/// <summary> * The constructor from object identifier /// </summary> /// <param name="base">the base configuration file </param> /// <param name="r">the repository</param> /// <param name="objectid">the object identifier</param> /// <exception cref="IOException"> /// the blob cannot be read from the repository. </exception> /// <exception cref="ConfigInvalidException"> /// the blob is not a valid configuration format. /// </exception> public BlobBasedConfig(Config @base, Repository r, ObjectId objectid) : base(@base) { ObjectLoader loader = r.OpenBlob(objectid); if (loader == null) { throw new IOException("Blob not found: " + objectid); } fromText(RawParseUtils.decode(loader.Bytes)); }
public static ObjectType DecodeTypeString(ObjectId id, byte[] typeString, byte endMark, ref int offset) { try { switch (typeString[offset]) { case (byte)'b': if (typeString[offset + 1] != (byte)'l' || typeString[offset + 2] != (byte)'o' || typeString[offset + 3] != (byte)'b' || typeString[offset + 4] != endMark) break; offset += 5; return ObjectType.Blob; case (byte)'c': if (typeString[offset + 1] != (byte)'o' || typeString[offset + 2] != (byte)'m' || typeString[offset + 3] != (byte)'m' || typeString[offset + 4] != (byte)'i' || typeString[offset + 5] != (byte)'t' || typeString[offset + 6] != endMark) break; offset += 7; return ObjectType.Commit; case (byte)'t': switch (typeString[offset + 1]) { case (byte)'a': if (typeString[offset + 2] != (byte)'g' || typeString[offset + 2] != endMark) { throw new CorruptObjectException(id, "invalid type"); } offset += 4; return ObjectType.Tag; case (byte)'r': if (typeString[offset + 2] != (byte)'e' || typeString[offset + 3] != (byte)'e' || typeString[offset + 4] != endMark) { throw new CorruptObjectException(id, "invalid type"); } offset += 5; return ObjectType.Tree; } break; } } catch (IndexOutOfRangeException) { } throw new CorruptObjectException(id, "invalid type"); }
/** * Construct a Tag representing an existing with a known name referencing an known object. * This could be either a simple or annotated tag. * * @param db {@link Repository} * @param id target id. * @param refName tag name or null * @param raw data of an annotated tag. */ public Tag(Repository db, ObjectId id, string refName, byte[] raw) { Repository = db; if (raw != null) { TagId = id; Id = ObjectId.FromString(raw, 7); } else Id = id; if (refName != null && refName.StartsWith("refs/tags/")) refName = refName.Substring(10); TagName = refName; this.raw = raw; }
private static void appendOneRecord(ObjectId oldId, ObjectId newId, PersonIdent ident, String msg, Repository db, String refName) { if (ident == null) ident = new PersonIdent(db); else ident = new PersonIdent(ident); StringBuilder r = new StringBuilder(); r.Append(ObjectId.ToString(oldId)); r.Append(' '); r.Append(ObjectId.ToString(newId)); r.Append(' '); r.Append(ident.ToExternalString()); r.Append('\t'); r.Append(msg); r.Append('\n'); byte[] rec = Constants.encode(r.ToString()); var logdir = new DirectoryInfo(db.Directory + "/" + Constants.LOGS); var reflog = new DirectoryInfo(logdir + "/" + refName); var refdir = reflog.Parent; refdir.Create(); if (!refdir.Exists) throw new IOException("Cannot create directory " + refdir); using (var @out = new FileStream(reflog.FullName, System.IO.FileMode.OpenOrCreate, FileAccess.Write)) { try { @out.Write(rec, 0, rec.Length); } finally { @out.Close(); } } }
/** * Writes reflog entry for ref specified by refName * * @param repo * repository to use * @param oldCommit * previous commit * @param commit * new commit * @param message * reflog message * @param refName * full ref name */ public static void WriteReflog(Repository repo, ObjectId oldCommit, ObjectId commit, string message, string refName) { string entry = BuildReflogString(repo, oldCommit, commit, message); DirectoryInfo directory = repo.Directory; FileInfo reflogfile = PathUtil.CombineFilePath(directory, "logs/" + refName); DirectoryInfo reflogdir = reflogfile.Directory; if (!reflogdir.Exists) { try { reflogdir.Create(); } catch (Exception) { throw new IOException("Cannot create directory " + reflogdir); } } StreamWriter writer = new StreamWriter(reflogfile.OpenWrite()); writer.WriteLine(entry); writer.Close(); }
/** * @param id * SHA'1 of a tree * @return an {@link ObjectLoader} for accessing the data of a named tree * @ */ public ObjectLoader OpenTree(ObjectId id) { return OpenObject(id); }
/** * Access a Commit by SHA'1 id. * @param id * @return Commit or null * @ for I/O error or unexpected object type. */ public Commit MapCommit(ObjectId id) { ObjectLoader or = OpenObject(id); if (or == null) return null; byte[] raw = or.getBytes(); if (Constants.OBJ_COMMIT == or.getType()) return new Commit(this, id, raw); throw new IncorrectObjectTypeException(id, ObjectType.Commit); }
public Commit OpenCommit(ObjectId id) { return MapCommit(id); }
//private void OpenObjectInAllPacks(AnyObjectId objectId, ICollection<PackedObjectLoader> resultLoaders, WindowCursor cursor) //{ // foreach (PackFile pack in _packs) // { // PackedObjectLoader loader = pack.Get(cursor, objectId); // if (loader != null) // resultLoaders.Add(loader); // } //} /** * @param id * SHA'1 of a blob * @return an {@link ObjectLoader} for accessing the data of a named blob * @ */ public ObjectLoader OpenBlob(ObjectId id) { return OpenObject(id); }
private Tree MakeTree(ObjectId id, byte[] raw) { return new Tree(this, id, raw); }
public DeltaRefPackedObjectLoader(PackFile pr, long dataOffset, long objectOffset, int deltaSz, ObjectId @base) : base(pr, dataOffset, objectOffset, deltaSz) { deltaBase = @base; }
private static string BuildReflogString(Repository repo, ObjectId oldCommit, ObjectId commit, string message) { PersonIdent me = new PersonIdent(repo); string initial = ""; if (oldCommit == null) { oldCommit = ObjectId.ZeroId; initial = " (initial)"; } string s = oldCommit.ToString() + " " + commit.ToString() + " " + me.ToExternalString() + "\t" + message + initial; return s; }
/** * Access a Tree by SHA'1 id. * @param id * @return Tree or null * @ for I/O error or unexpected object type. */ public Tree MapTree(ObjectId id) { ObjectLoader or = OpenObject(id); if (or == null) return null; byte[] raw = or.getBytes(); switch (((ObjectType)or.getType())) { case ObjectType.Tree: return new Tree(this, id, raw); case ObjectType.Commit: return MapTree(ObjectId.FromString(raw, 5)); } throw new IncorrectObjectTypeException(id, ObjectType.Tree); }
internal void Stored(string origName, string name, ObjectId id, DateTime time) { lock (this) { _looseRefs[name] = new Ref(Ref.Storage.Loose, origName, name, id); _looseRefsMTime[name] = time; SetModified(); } Repository.fireRefsMaybeChanged(); }
public CachedRef(Storage st, string refName, ObjectId id, DateTime mtime) : base(st, refName, id) { LastModified = mtime; }
/// <summary> /// Access any type of Git object by id and /// </summary> /// <param name="id">SHA-1 of object to read</param> /// <param name="refName">optional, only relevant for simple tags</param> /// <returns>The Git object if found or null</returns> public object MapObject(ObjectId id, string refName) { ObjectLoader or = OpenObject(id); if (or == null) { return null; } byte[] raw = or.Bytes; switch ((ObjectType)(or.Type)) { case ObjectType.Tree: return MakeTree(id, raw); case ObjectType.Commit: return MakeCommit(id, raw); case ObjectType.Tag: return MakeTag(id, refName, raw); case ObjectType.Blob: return raw; default: throw new IncorrectObjectTypeException(id, "COMMIT nor TREE nor BLOB nor TAG"); } }
/** * Create a commit object with the specified id and data from and existing * commit object in a repository. * * @param db * The repository to which this commit object belongs * @param id * Commit id * @param raw * Raw commit object data */ public Commit(Repository db, ObjectId id, byte[] raw) { Repository = db; CommitId = id; treeId = ObjectId.FromString(raw, 5); ParentIds = new ObjectId[1]; int np = 0; int rawPtr = 46; while (true) { if (raw[rawPtr] != 'p') break; switch (np) { case 0: ParentIds[np++] = ObjectId.FromString(raw, rawPtr + 7); break; case 1: ParentIds = new[] { ParentIds[0], ObjectId.FromString(raw, rawPtr + 7) }; np++; break; default: if (ParentIds.Length <= np) { ObjectId[] old = ParentIds; ParentIds = new ObjectId[ParentIds.Length + 32]; for (int i = 0; i < np; ++i) ParentIds[i] = old[i]; } ParentIds[np++] = ObjectId.FromString(raw, rawPtr + 7); break; } rawPtr += 48; } if (np != ParentIds.Length) { ObjectId[] old = ParentIds; ParentIds = new ObjectId[np]; for (int i = 0; i < np; ++i) ParentIds[i] = old[i]; } else if (np == 0) ParentIds = new ObjectId[0]; this.raw = raw; }
/** * Create a commit associated with these parents and associate it with a * repository. * * @param db * The repository to which this commit object belongs * @param parentIds * Id's of the parent(s) */ public Commit(Repository db, ObjectId[] parentIds) { Repository = db; ParentIds = parentIds; }
/** * Access any type of Git object by id and * * @param id * SHA-1 of object to read * @param refName optional, only relevant for simple tags * @return The Git object if found or null * @ */ public object MapObject(ObjectId id, string refName) { ObjectLoader or = OpenObject(id); byte[] raw = or.getBytes(); switch ((ObjectType)(or.getType())) { case ObjectType.Tree: return MakeTree(id, raw); case ObjectType.Commit: return MakeCommit(id, raw); case ObjectType.Tag: return MakeTag(id, refName, raw); case ObjectType.Blob: return raw; } return null; }
public IncorrectObjectTypeException(ObjectId id, string type) : base(string.Format("object {0} is not a {1}.", id, type)) { }
private object MakeCommit(ObjectId id, byte[] raw) { return new Commit(this, id, raw); }
public void Write(ObjectId id) { RequireLock(); try { var b = new BinaryWriter(os); id.CopyTo(os); b.Write('\n'); b.Flush(); fLck.Release(); b.Close(); os = null; } catch (Exception) { Unlock(); throw; } }
private Tag MakeTag(ObjectId id, string refName, byte[] raw) { return new Tag(this, id, refName, raw); }
public Tree(Repository repo, ObjectId id, byte[] raw) : base(null, id, null) { _db = repo; ReadTree(raw); }
/** * Access a Tag by SHA'1 id * @param refName * @param id * @return Commit or null * @ for I/O error or unexpected object type. */ public Tag MapTag(string refName, ObjectId id) { ObjectLoader or = OpenObject(id); if (or == null) return null; byte[] raw = or.getBytes(); if (ObjectType.Tag == (ObjectType)or.getType()) return new Tag(this, id, refName, raw); return new Tag(this, id, refName, null); }
public Tree(Tree parent, ObjectId id, byte[] nameUTF8) : base(parent, id, nameUTF8) { _db = parent.Repository; }
public IncorrectObjectTypeException(ObjectId id, int type, Exception inner) : base(string.Format("object {0} is not a {1}.", id, (ObjectType)type), inner) { }
public FileTreeEntry(Tree parent, ObjectId id, byte[] nameUTF8, bool execute) : base(parent,id, nameUTF8) { this.SetExecutable(execute); }
public TreeEntry(Tree myParent, ObjectId id, byte[] nameUTF8) { this.NameUTF8 = nameUTF8; this.Parent = myParent; this._id = id; }
public Entry(byte[] raw, int pos) { oldId = ObjectId.FromString(raw, pos); pos += Constants.OBJECT_ID_LENGTH*2; if (raw[pos++] != ' ') throw new ArgumentException("Raw log message does not parse as log entry"); newId = ObjectId.FromString(raw, pos); pos += Constants.OBJECT_ID_LENGTH * 2; if (raw[pos++] != ' ') throw new ArgumentException("Raw log message does not parse as log entry"); who = RawParseUtils.parsePersonIdentOnly(raw, pos); int p0 = RawParseUtils.next(raw, pos, (byte)'\t'); if (p0 == -1) throw new ArgumentException("Raw log message does not parse as log entry"); int p1 = RawParseUtils.nextLF(raw, p0); if (p1 == -1) throw new ArgumentException("Raw log message does not parse as log entry"); comment = RawParseUtils.decode(raw, p0, p1 - 1); }