/// <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; }
/// <summary> * The constructor from object identifier /// </summary> /// <param name="base">the base configuration file </param> /// <param name="repo">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 repo, ObjectId objectid) : base(@base) { if (repo == null) { throw new System.ArgumentNullException("repo"); } ObjectLoader loader = repo.OpenBlob(objectid); if (loader == null) { throw new IOException("Blob not found: " + objectid); } fromText(RawParseUtils.decode(loader.Bytes)); }
public Entry(byte[] raw, int pos) { oldId = ObjectId.FromString(raw, pos); pos += Constants.OBJECT_ID_STRING_LENGTH; if (raw[pos++] != ' ') throw new ArgumentException("Raw log message does not parse as log entry"); newId = ObjectId.FromString(raw, pos); pos += Constants.OBJECT_ID_STRING_LENGTH; 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); }
private Tag MakeTag(ObjectId id, string refName, byte[] raw) { return new Tag(this, id, refName, raw); }
public Tree(Repository repo, ObjectId id) : base(repo, id) { }
private object MakeCommit(ObjectId id, byte[] raw) { return new Commit(this, id, raw); }
internal Commit(Repository repo, ObjectId id) : base(repo, id) { }
public SymlinkTreeEntry(Tree parent, ObjectId id, byte[] nameUTF8) : base(parent, id, nameUTF8) { }
/// <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"); } }
/// <summary> /// Create a new ref pairing. /// </summary> /// <param name="st">method used to store this ref.</param> /// <param name="name">name of this ref.</param> /// <param name="id"> /// current value of the ref. May be null to indicate a ref that /// does not exist yet. /// </param> public Unpeeled(Storage st, string name, ObjectId id) : base(st, name, id) { }
/// <summary> /// Access a Tree by SHA'1 id. /// </summary> /// <param name="id"></param> /// <returns>Tree or null</returns> public Tree MapTree(ObjectId id) { ObjectLoader or = OpenObject(id); if (or == null) { return null; } byte[] raw = or.Bytes; switch (((ObjectType)or.Type)) { case ObjectType.Tree: return new Tree(this, id, raw); case ObjectType.Commit: return MapTree(ObjectId.FromString(raw, 5)); } throw new IncorrectObjectTypeException(id, ObjectType.Tree); }
public Commit OpenCommit(ObjectId id) { return MapCommit(id); }
/// <summary> /// Create a commit object with the specified id and data from an existing /// commit object in a repository. /// </summary> /// <param name="db"> /// The repository to which this commit object belongs. /// </param> /// <param name="id">Commit id.</param> /// <param name="raw">Raw commit object data.</param> 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; if (np == 0) { ParentIds[np++] = ObjectId.FromString(raw, rawPtr + 7); } else if (np == 1) { ParentIds = new[] { ParentIds[0], ObjectId.FromString(raw, rawPtr + 7) }; np++; } else { 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); } 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 = EmptyObjectidList; } } _raw = raw; Decode(); }
/// <summary> /// Create a commit associated with these parents and associate it with a /// repository. /// </summary> /// <param name="db"> /// The repository to which this commit object belongs. /// </param> /// <param name="parentIds"> /// Id's of the parent(s). /// </param> public Commit(Repository db, ObjectId[] parentIds) { Repository = db; ParentIds = parentIds; }
private void WriteVerifyPack4(bool thin) { var interestings = new LinkedList<ObjectId>(); interestings.AddLast(ObjectId.FromString("82c6b885ff600be425b4ea96dee75dca255b69e7")); var uninterestings = new LinkedList<ObjectId>(); uninterestings.AddLast(ObjectId.FromString("c59759f143fb1fe21c197981df75a7ee00290799")); CreateVerifyOpenPack(interestings, uninterestings, thin, false); var writtenObjects = new[] { ObjectId.FromString("82c6b885ff600be425b4ea96dee75dca255b69e7"), ObjectId.FromString("aabf2ffaec9b497f0950352b3e582d73035c2035"), ObjectId.FromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259") }; Assert.AreEqual(writtenObjects.Length, _writer.getObjectsNumber()); ObjectId[] expectedObjects; if (thin) { expectedObjects = new ObjectId[4]; Array.Copy(writtenObjects, 0, expectedObjects, 0, writtenObjects.Length); expectedObjects[3] = ObjectId.FromString("6ff87c4664981e4397625791c8ea3bbb5f2279a3"); } else { expectedObjects = writtenObjects; } VerifyObjectsOrder(expectedObjects); Assert.AreEqual("cded4b74176b4456afa456768b2b5aafb41c44fc", _writer.computeName().Name); }
private void VerifyObjectsOrder(ObjectId[] objectsOrder) { var entries = new SortedList<long, PackIndex.MutableEntry>(); foreach (PackIndex.MutableEntry me in _pack) { entries.Add(me.Offset, me.CloneEntry()); } int i = 0; foreach (PackIndex.MutableEntry me in entries.Values) { Assert.AreEqual(objectsOrder[i++].ToObjectId(), me.ToObjectId()); } }
/// <summary> /// Create a new ref pairing. /// </summary> /// <param name="st">method used to store this ref.</param> /// <param name="name">name of this ref.</param> /// <param name="id"> /// current value of the ref. /// </param> /// <param name="p">the first non-tag object that tag {@code id} points to.</param> public PeeledTag(Storage st, string name, ObjectId id, ObjectId p) : base(st, name, id) { _peeledObjectId = p; }
private Tree MakeTree(ObjectId id, byte[] raw) { return new Tree(this, id, raw); }
/// <summary> /// Construct a Tree object with known content and hash value /// </summary> /// <param name="repo"></param> /// <param name="id"></param> /// <param name="raw"></param> /// <exception cref="IOException"></exception> public Tree(Repository repo, ObjectId id, byte[] raw) : base(null, id, null) { _db = repo; ReadTree(raw); }
/// <summary> /// Access a Commit by SHA'1 id. /// </summary> /// <param name="id"></param> /// <returns>Commit or null</returns> public Commit MapCommit(ObjectId id) { ObjectLoader or = OpenObject(id); if (or == null) { return null; } byte[] raw = or.Bytes; if (Constants.OBJ_COMMIT == or.Type) { return new Commit(this, id, raw); } throw new IncorrectObjectTypeException(id, ObjectType.Commit); }
public void Write(ObjectId id) { RequireLock(); try { var b = new BinaryWriter(_os); id.CopyTo(b); b.Write('\n'); b.Flush(); _fLck.Release(); b.Close(); _os = null; } catch (Exception) { Unlock(); throw; } }
/// <summary> /// Access a Tag by SHA'1 id /// </summary> /// <param name="refName"></param> /// <param name="id"></param> /// <returns>Commit or null</returns> public Tag MapTag(string refName, ObjectId id) { ObjectLoader or = OpenObject(id); if (or == null) return null; byte[] raw = or.Bytes; if (ObjectType.Tag == (ObjectType)or.Type) { return new Tag(this, id, refName, raw); } return new Tag(this, id, refName, null); }
internal Tree(Repository repo, ObjectId id) : base(repo, id) { }
/// <summary> /// /// </summary> /// <param name="id">SHA'1 of a blob</param> /// <returns> /// An <see cref="ObjectLoader"/> for accessing the data of a named blob /// </returns> public ObjectLoader OpenBlob(ObjectId id) { return OpenObject(id); }
protected override RefUpdate.RefUpdateResult doRename() { if (source.getRef().isSymbolic()) return RefUpdate.RefUpdateResult.IO_FAILURE; // not supported var rw = new RevWalk.RevWalk(_refdb.getRepository()); _objId = source.getOldObjectId(); _updateHead = needToUpdateHEAD(); _tmp = _refdb.newTemporaryUpdate(); try { // First backup the source so its never unreachable. _tmp.setNewObjectId(_objId); _tmp.setForceUpdate(true); _tmp.disableRefLog(); switch (_tmp.update(rw)) { case RefUpdate.RefUpdateResult.NEW: case RefUpdate.RefUpdateResult.FORCED: case RefUpdate.RefUpdateResult.NO_CHANGE: break; default: return _tmp.getResult(); } // Save the source's log under the temporary name, we must do // this before we delete the source, otherwise we lose the log. if (!renameLog(source, _tmp)) return RefUpdate.RefUpdateResult.IO_FAILURE; // If HEAD has to be updated, link it now to destination. // We have to link before we delete, otherwise the delete // fails because its the current branch. RefUpdate dst = destination; if (_updateHead) { if (!linkHEAD(destination)) { renameLog(_tmp, source); return RefUpdate.RefUpdateResult.LOCK_FAILURE; } // Replace the update operation so HEAD will log the rename. dst = _refdb.newUpdate(Constants.HEAD, false); dst.setRefLogIdent(destination.getRefLogIdent()); dst.setRefLogMessage(destination.getRefLogMessage(), false); } // Delete the source name so its path is free for replacement. source.setExpectedOldObjectId(_objId); source.setForceUpdate(true); source.disableRefLog(); if (source.delete(rw) != RefUpdate.RefUpdateResult.FORCED) { renameLog(_tmp, source); if (_updateHead) linkHEAD(source); return source.getResult(); } // Move the log to the destination. if (!renameLog(_tmp, destination)) { renameLog(_tmp, source); source.setExpectedOldObjectId(ObjectId.ZeroId); source.setNewObjectId(_objId); source.update(rw); if (_updateHead) linkHEAD(source); return RefUpdate.RefUpdateResult.IO_FAILURE; } // Create the destination, logging the rename during the creation. dst.setExpectedOldObjectId(ObjectId.ZeroId); dst.setNewObjectId(_objId); if (dst.update(rw) != RefUpdate.RefUpdateResult.NEW) { // If we didn't create the destination we have to undo // our work. Put the log back and restore source. if (renameLog(destination, _tmp)) renameLog(_tmp, source); source.setExpectedOldObjectId(ObjectId.ZeroId); source.setNewObjectId(_objId); source.update(rw); if (_updateHead) linkHEAD(source); return dst.getResult(); } return RefUpdate.RefUpdateResult.RENAMED; } finally { // Always try to free the temporary name. try { _refdb.delete(_tmp); } catch (IOException) { _refdb.fileFor(_tmp.getName()).Delete(); } } }
/// <summary> /// /// </summary> /// <param name="id">SHA'1 of a tree</param> /// <returns> /// An <see cref="ObjectLoader"/> for accessing the data of a named tree /// </returns> public ObjectLoader OpenTree(ObjectId id) { return OpenObject(id); }
private ObjectId Commit(ObjectWriter ow, DirCache treeB, ObjectId[] parentIds) { var c = new Commit(db) { TreeId = treeB.writeTree(ow), Author = new PersonIdent("A U Thor", "a.u.thor", 1L, 0) }; c.Committer = c.Author; c.ParentIds = parentIds; c.Message = "Tree " + c.TreeId.Name; return ow.WriteCommit(c); }
/// <summary> /// Construct a Tree with a known SHA-1 under another tree. Data is not yet /// specified and will have to be loaded on demand. /// </summary> /// <param name="parent"></param> /// <param name="id"></param> /// <param name="nameUTF8"></param> public Tree(Tree parent, ObjectId id, byte[] nameUTF8) : base(parent, id, nameUTF8) { _db = parent.Repository; }
private static global::GitSharp.Core.Ref newRef(String name, ObjectId id) { return new Unpeeled(Storage.Loose, name, id); }