private CanonicalTreeParser ParserFor(AnyObjectId id) { var p = new CanonicalTreeParser(); p.reset(_db, id, _cursor); return(p); }
/// <summary>Push a candidate object onto the generator's traversal stack.</summary> /// <remarks> /// Push a candidate object onto the generator's traversal stack. /// <p> /// Candidates should be pushed in history order from oldest-to-newest. /// Applications should push the starting commit first, then the index /// revision (if the index is interesting), and finally the working tree copy /// (if the working tree is interesting). /// </remarks> /// <param name="description">description of the blob revision, such as "Working Tree". /// </param> /// <param name="id">may be a commit or a blob.</param> /// <returns> /// /// <code>this</code> /// </returns> /// <exception cref="System.IO.IOException">the repository cannot be read.</exception> public virtual NGit.Blame.BlameGenerator Push(string description, AnyObjectId id) { ObjectLoader ldr = reader.Open(id); if (ldr.GetType() == Constants.OBJ_BLOB) { if (description == null) { description = JGitText.Get().blameNotCommittedYet; } Candidate.BlobCandidate c = new Candidate.BlobCandidate(description, resultPath); c.sourceBlob = id.ToObjectId(); c.sourceText = new RawText(ldr.GetCachedBytes(int.MaxValue)); c.regionList = new Region(0, 0, c.sourceText.Size()); remaining = c.sourceText.Size(); Push(c); return(this); } RevCommit commit = revPool.ParseCommit(id); if (!Find(commit, resultPath)) { return(this); } Candidate c_1 = new Candidate(commit, resultPath); c_1.sourceBlob = idBuf.ToObjectId(); c_1.LoadText(reader); c_1.regionList = new Region(0, 0, c_1.sourceText.Size()); remaining = c_1.sourceText.Size(); Push(c_1); return(this); }
/** * Reset this walker to run over a single existing tree. * * @param id * the tree we need to parse. The walker will execute over this * single tree if the reset is successful. * @throws MissingObjectException * the given tree object does not exist in this repository. * @throws IncorrectObjectTypeException * the given object id does not denote a tree, but instead names * some other non-tree type of object. Note that commits are not * trees, even if they are sometimes called a "tree-ish". * @throws CorruptObjectException * the object claimed to be a tree, but its contents did not * appear to be a tree. The repository may have data corruption. * @throws IOException * a loose object or pack file could not be Read. */ public void reset(AnyObjectId id) { if (_trees.Length == 1) { AbstractTreeIterator iterator = _trees[0]; while (iterator.Parent != null) { iterator = iterator.Parent; } CanonicalTreeParser oParse = (iterator as CanonicalTreeParser); if (oParse != null) { iterator.Matches = null; iterator.MatchShift = 0; oParse.reset(_db, id, _cursor); _trees[0] = iterator; } else { _trees[0] = ParserFor(id); } } else { _trees = new AbstractTreeIterator[] { ParserFor(id) }; } _advance = false; _depth = 0; }
/// <exception cref="NGit.Errors.MissingObjectException"></exception> /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception> /// <exception cref="NGit.Api.Errors.JGitInternalException"></exception> private NGit.Api.LogCommand Add(bool include, AnyObjectId start) { CheckCallable(); try { if (include) { walk.MarkStart(walk.LookupCommit(start)); startSpecified = true; } else { walk.MarkUninteresting(walk.LookupCommit(start)); } return(this); } catch (MissingObjectException e) { throw; } catch (IncorrectObjectTypeException e) { throw; } catch (IOException e) { throw new JGitInternalException(MessageFormat.Format(JGitText.Get().exceptionOccurredDuringAddingOfOptionToALogCommand , start), e); } }
/// <summary>Determine the differences between two trees.</summary> /// <remarks> /// Determine the differences between two trees. /// No output is created, instead only the file paths that are different are /// returned. Callers may choose to format these paths themselves, or convert /// them into /// <see cref="NGit.Patch.FileHeader">NGit.Patch.FileHeader</see> /// instances with a complete edit list by /// calling /// <see cref="ToFileHeader(DiffEntry)">ToFileHeader(DiffEntry)</see> /// . /// </remarks> /// <param name="a">the old (or previous) side.</param> /// <param name="b">the new (or updated) side.</param> /// <returns>the paths that are different.</returns> /// <exception cref="System.IO.IOException">trees cannot be read or file contents cannot be read. /// </exception> public virtual IList <DiffEntry> Scan(AnyObjectId a, AnyObjectId b) { AssertHaveRepository(); RevWalk rw = new RevWalk(reader); return(Scan(rw.ParseTree(a), rw.ParseTree(b))); }
/// <summary>Configure the generator to compute reverse blame (history of deletes).</summary> /// <remarks> /// Configure the generator to compute reverse blame (history of deletes). /// <p> /// This method is expensive as it immediately runs a RevWalk over the /// history spanning the expression /// <code>start..end</code> /// (end being more recent /// than start) and then performs the equivalent operation as /// <see cref="Push(string, NGit.AnyObjectId)">Push(string, NGit.AnyObjectId)</see> /// to begin blame traversal from the /// commit named by /// <code>start</code> /// walking forwards through history until /// <code>end</code> /// blaming line deletions. /// <p> /// A reverse blame may produce multiple sources for the same result line, /// each of these is a descendant commit that removed the line, typically /// this occurs when the same deletion appears in multiple side branches such /// as due to a cherry-pick. Applications relying on reverse should use /// <see cref="BlameResult">BlameResult</see> /// as it filters these duplicate sources and only /// remembers the first (oldest) deletion. /// </remarks> /// <param name="start"> /// oldest commit to traverse from. The result file will be loaded /// from this commit's tree. /// </param> /// <param name="end"> /// most recent commits to stop traversal at. Usually an active /// branch tip, tag, or HEAD. /// </param> /// <returns> /// /// <code>this</code> /// </returns> /// <exception cref="System.IO.IOException">the repository cannot be read.</exception> public virtual NGit.Blame.BlameGenerator Reverse <_T0>(AnyObjectId start, ICollection <_T0> end) where _T0 : ObjectId { InitRevPool(true); ReverseWalk.ReverseCommit result = (ReverseWalk.ReverseCommit)revPool.ParseCommit (start); if (!Find(result, resultPath)) { return(this); } revPool.MarkUninteresting(result); foreach (ObjectId id in end) { revPool.MarkStart(revPool.ParseCommit(id)); } while (revPool.Next() != null) { } // just pump the queue Candidate.ReverseCandidate c = new Candidate.ReverseCandidate(result, resultPath); c.sourceBlob = idBuf.ToObjectId(); c.LoadText(reader); c.regionList = new Region(0, 0, c.sourceText.Size()); remaining = c.sourceText.Size(); Push(c); return(this); }
/// <summary> /// Create a generator and advance it to the submodule entry at the given /// path /// </summary> /// <param name="repository"></param> /// <param name="treeId"> /// the root of a tree containing both a submodule at the given path /// and .gitmodules at the root. /// </param> /// <param name="path"></param> /// <returns>generator at given path, null if no submodule at given path</returns> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public static NGit.Submodule.SubmoduleWalk ForPath(Repository repository, AnyObjectId treeId, string path) { NGit.Submodule.SubmoduleWalk generator = new NGit.Submodule.SubmoduleWalk(repository ); try { generator.SetTree(treeId); PathFilter filter = PathFilter.Create(path); generator.SetFilter(filter); generator.SetRootTree(treeId); while (generator.Next()) { if (filter.IsDone(generator.walk)) { return(generator); } } } catch (IOException e) { generator.Release(); throw; } generator.Release(); return(null); }
/// <summary>Reset this walker to run over a single existing tree.</summary> /// <remarks>Reset this walker to run over a single existing tree.</remarks> /// <param name="id"> /// the tree we need to parse. The walker will execute over this /// single tree if the reset is successful. /// </param> /// <exception cref="NGit.Errors.MissingObjectException">the given tree object does not exist in this repository. /// </exception> /// <exception cref="NGit.Errors.IncorrectObjectTypeException"> /// the given object id does not denote a tree, but instead names /// some other non-tree type of object. Note that commits are not /// trees, even if they are sometimes called a "tree-ish". /// </exception> /// <exception cref="NGit.Errors.CorruptObjectException"> /// the object claimed to be a tree, but its contents did not /// appear to be a tree. The repository may have data corruption. /// </exception> /// <exception cref="System.IO.IOException">a loose object or pack file could not be read. /// </exception> public virtual void Reset(AnyObjectId id) { if (trees.Length == 1) { AbstractTreeIterator o = trees[0]; while (o.parent != null) { o = o.parent; } if (o is CanonicalTreeParser) { o.matches = null; o.matchShift = 0; ((CanonicalTreeParser)o).Reset(reader, id); trees[0] = o; } else { trees[0] = ParserFor(id); } } else { trees = new AbstractTreeIterator[] { ParserFor(id) }; } advance = false; depth = 0; }
/// <exception cref="System.IO.IOException"></exception> internal override int EstimateSize(AnyObjectId noteOn, ObjectReader or) { // If most of this fan-out is full, estimate it should still be split. if (LeafBucket.MAX_SIZE * 3 / 4 <= cnt) { return(1 + LeafBucket.MAX_SIZE); } // Due to the uniform distribution of ObjectIds, having less nodes full // indicates a good chance the total number of children below here // is less than the MAX_SIZE split point. Get a more accurate count. MutableObjectId id = new MutableObjectId(); id.FromObjectId(noteOn); int sz = 0; for (int cell = 0; cell < 256; cell++) { NoteBucket b = table[cell]; if (b == null) { continue; } id.SetByte(prefixLen >> 1, cell); sz += b.EstimateSize(id, or); if (LeafBucket.MAX_SIZE < sz) { break; } } return(sz); }
/// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception> /// <exception cref="System.IO.IOException"></exception> private CanonicalTreeParser ParserFor(AnyObjectId id) { CanonicalTreeParser p = new CanonicalTreeParser(); p.Reset(reader, id); return(p); }
private ICollection <WalkRemoteObjectDatabase> ExpandOneAlternate(AnyObjectId id, ProgressMonitor pm) { while (!noAlternatesYet.IsEmpty()) { WalkRemoteObjectDatabase wrr = noAlternatesYet.RemoveFirst(); try { pm.BeginTask(JGitText.Get().listingAlternates, ProgressMonitor.UNKNOWN); ICollection <WalkRemoteObjectDatabase> altList = wrr.GetAlternates(); if (altList != null && !altList.IsEmpty()) { return(altList); } } catch (IOException e) { // Try another repository. // RecordError(id, e); } finally { pm.EndTask(); } } return(null); }
private bool MatchHave(AnyObjectId id) { RevObject o; try { o = _walk.parseAny(id); } catch (IOException) { return(false); } if (!o.has(PEER_HAS)) { o.add(PEER_HAS); RevCommit oComm = (o as RevCommit); if (oComm != null) { oComm.carry(PEER_HAS); } AddCommonBase(o); } return(true); }
private void VerifySafeObject(AnyObjectId id, int type, byte[] data) { if (_objCheck != null) { try { _objCheck.check(type, data); } catch (CorruptObjectException e) { throw new IOException("Invalid " + Constants.typeString(type) + " " + id + ": " + e.Message, e); } } ObjectLoader ldr = _repo.OpenObject(_windowCursor, id); if (ldr != null) { byte[] existingData = ldr.CachedBytes; if (ldr.Type != type || !data.ArrayEquals(existingData)) { throw new IOException("Collision on " + id); } } }
/// <summary> /// Recursively add an entire tree into this builder. /// <para /> /// If pathPrefix is "a/b" and the tree contains file "c" then the resulting /// DirCacheEntry will have the path "a/b/c". /// <para /> /// All entries are inserted at stage 0, therefore assuming that the /// application will not insert any other paths with the same pathPrefix. /// </summary> /// <param name="pathPrefix"> /// UTF-8 encoded prefix to mount the tree's entries at. If the /// path does not end with '/' one will be automatically inserted /// as necessary. /// </param> /// <param name="stage">Stage of the entries when adding them.</param> /// <param name="db"> /// Repository the tree(s) will be read from during recursive /// traversal. This must be the same repository that the resulting /// <see cref="DirCache"/> would be written out to (or used in) otherwise /// the caller is simply asking for deferred MissingObjectExceptions. /// </param> /// <param name="tree"> /// The tree to recursively add. This tree's contents will appear /// under <paramref name="pathPrefix"/>. The ObjectId must be that of a /// tree; the caller is responsible for dereferencing a tag or /// commit (if necessary). /// </param> /// <exception cref="IOException"> /// A tree cannot be read to iterate through its entries. /// </exception> public void addTree(byte[] pathPrefix, int stage, Repository db, AnyObjectId tree) { var tw = new TreeWalk.TreeWalk(db); tw.reset(); var curs = new WindowCursor(); try { tw.addTree(new CanonicalTreeParser(pathPrefix, db, tree.ToObjectId(), curs)); } finally { curs.Release(); } tw.Recursive = true; if (!tw.next()) { return; } DirCacheEntry newEntry = ToEntry(stage, tw); BeforeAdd(newEntry); FastAdd(newEntry); while (tw.next()) { FastAdd(ToEntry(stage, tw)); } }
/// <exception cref="System.IO.IOException"></exception> private void AdvertiseAnyOnce(AnyObjectId obj, string refName) { if (!sent.Contains(obj)) { AdvertiseAny(obj, refName); } }
private int Search(AnyObjectId objId) { int low = 0; int high = cnt; while (low < high) { int mid = (int)(((uint)(low + high)) >> 1); int cmp = objId.CompareTo(notes[mid]); if (cmp < 0) { high = mid; } else { if (cmp == 0) { return(mid); } else { low = mid + 1; } } } return(-(low + 1)); }
/// <summary>Configure the generator to compute reverse blame (history of deletes).</summary> /// <remarks>Configure the generator to compute reverse blame (history of deletes).</remarks> /// <param name="start"> /// oldest commit to traverse from. The result file will be loaded /// from this commit's tree. /// </param> /// <param name="end"> /// most recent commits to stop traversal at. Usually an active /// branch tip, tag, or HEAD. /// </param> /// <returns> /// /// <code>this</code> /// </returns> /// <exception cref="System.IO.IOException">the repository cannot be read.</exception> public virtual NGit.Api.BlameCommand Reverse(AnyObjectId start, ICollection <ObjectId > end) { startCommit = start.ToObjectId(); reverseEndCommits = new AList <ObjectId>(end); return(this); }
/// <summary> /// Create a new commit. /// </summary> /// <param name="id">the identity of this commit.</param> /// <param name="tags">the tags associated with this commit, null for no tags</param> public PlotCommit(AnyObjectId id, Ref[] tags) : base(id) { this.refs = tags; passingLanes = NO_LANES; children = NO_CHILDREN; }
/// <exception cref="System.IO.IOException"></exception> internal override long GetObjectSize1(WindowCursor curs, AnyObjectId objectId) { ObjectDirectory.PackList pList = packList.Get(); for (; ;) { foreach (PackFile p in pList.packs) { try { long sz = p.GetObjectSize(curs, objectId); if (0 <= sz) { return(sz); } } catch (PackMismatchException) { // Pack was modified; refresh the entire pack list. // pList = ScanPacks(pList); goto SEARCH_continue; } catch (IOException) { // Assume the pack is corrupted. // RemovePack(p); } } return(-1); SEARCH_continue :; } SEARCH_break :; }
internal override bool HasObject1(AnyObjectId objectId) { if (unpackedObjectCache.IsUnpacked(objectId)) { return(true); } foreach (PackFile p in packList.Get().packs) { try { if (p.HasObject(objectId)) { return(true); } } catch (IOException) { // The hasObject call should have only touched the index, // so any failure here indicates the index is unreadable // by this process, and the pack is likewise not readable. // RemovePack(p); continue; } } return(false); }
/// <summary>Set the identity of the object, if its not already set.</summary> /// <remarks>Set the identity of the object, if its not already set.</remarks> /// <param name="id">the id of the object that is too large to process.</param> public virtual void SetObjectId(AnyObjectId id) { if (objectId == null) { objectId = id.Copy(); } }
/// <summary>Back door to quickly create a subtree iterator for any subtree.</summary> /// <remarks> /// Back door to quickly create a subtree iterator for any subtree. /// <p> /// Don't use this unless you are ObjectWalk. The method is meant to be /// called only once the current entry has been identified as a tree and its /// identity has been converted into an ObjectId. /// </remarks> /// <param name="reader">reader to load the tree data from.</param> /// <param name="id">ObjectId of the tree to open.</param> /// <returns>a new parser that walks over the current subtree.</returns> /// <exception cref="System.IO.IOException">a loose object or pack file could not be read. /// </exception> public NGit.Treewalk.CanonicalTreeParser CreateSubtreeIterator0(ObjectReader reader , AnyObjectId id) { NGit.Treewalk.CanonicalTreeParser p = new NGit.Treewalk.CanonicalTreeParser(this); p.Reset(reader, id); return(p); }
public TrackingRefUpdate(Repository db, RefSpec spec, AnyObjectId nv, string msg) : this(db, spec.Destination, spec.Source, spec.Force, nv, msg) { if (spec == null) { throw new System.ArgumentNullException("spec"); } }
/// <exception cref="System.IO.IOException"></exception> internal override Sharpen.Iterator <Note> Iterator(AnyObjectId objId, ObjectReader reader) { MutableObjectId id = new MutableObjectId(); id.FromObjectId(objId); return(new _Iterator_138(this, id, reader)); }
/// <exception cref="System.IO.IOException"></exception> internal InMemoryNoteBucket Load(AnyObjectId prefix, ObjectReader or) { AbbreviatedObjectId p = prefix.Abbreviate(this._enclosing.prefixLen + 2); InMemoryNoteBucket self = NoteParser.Parse(p, this.treeId, or); this._enclosing.table[this._enclosing.Cell(prefix)] = self; return(self); }
public TrackingRefUpdate(Repository db, string localName, string remoteName, bool forceUpdate, AnyObjectId nv, string msg) { RemoteName = remoteName; update = db.UpdateRef(localName); update.IsForceUpdate = forceUpdate; update.NewObjectId = nv.Copy(); update.SetRefLogMessage(msg, true); }
public override bool Equals(AnyObjectId o) { if (o.GetType() != typeof(RevObject)) { return(false); } return(this == o); }
public void include(string name, AnyObjectId id) { if (!Repository.IsValidRefName(name)) throw new ArgumentException("Invalid ref name: " + name, "name"); if (includeObjects.ContainsKey(name)) throw new ApplicationException("Duplicate ref: " + name); includeObjects.Add(name, id.ToObjectId()); }
public static RevObject object_Get(this RevWalk revWalk, AnyObjectId objectId) { if (revWalk.notNull() && objectId.notNull()) { return(revWalk.LookupOrNull(objectId)); } return(null); }
private static bool SameContent(Note a, Note b) { if (a == null && b == null) { return(true); } return(a != null && b != null && AnyObjectId.Equals(a.GetData(), b.GetData())); }
/// <exception cref="System.IO.IOException"></exception> internal override long GetObjectSize1(WindowCursor curs, AnyObjectId objectId) { if (unpackedObjects.Contains(objectId)) { return(wrapped.GetObjectSize2(curs, objectId.Name, objectId)); } return(wrapped.GetObjectSize1(curs, objectId)); }
public ObjectId(AnyObjectId src) { this.W1 = src.W1; this.W2 = src.W2; this.W3 = src.W3; this.W4 = src.W4; this.W5 = src.W5; }
private static bool SameNote(Note a, Note b) { if (a == null && b == null) { return(true); } return(a != null && b != null && AnyObjectId.Equals(a, b)); }
internal LargeObject(int type, long size, FilePath path, AnyObjectId id, FileObjectDatabase db) { this.type = type; this.size = size; this.path = path; this.id = id.Copy(); this.source = db; }
/** * Set the common ancestor tree. * * @param id * common base treeish; null to automatically compute the common * base from the input commits during * {@link #merge(AnyObjectId, AnyObjectId)}. * @throws IncorrectObjectTypeException * the object is not a treeish. * @throws MissingObjectException * the object does not exist. * @throws IOException * the object could not be read. */ public void SetBase(AnyObjectId id) { if (id != null) { _baseTree = Walk.parseTree(id); } else { _baseTree = null; } }
private static byte[] Entry(FileMode mode, string name, AnyObjectId id) { var @out = new MemoryStream(); mode.CopyTo(@out); @out.WriteByte((byte) ' '); byte[] bytes = Constants.encode(name); @out.Write(bytes, 0, bytes.Length); @out.WriteByte(0); id.copyRawTo(@out); return @out.ToArray(); }
public TrackingRefUpdate(Repository db, string localName, string remoteName, bool forceUpdate, AnyObjectId nv, string msg) { if (db == null) throw new System.ArgumentNullException("db"); if (nv == null) throw new System.ArgumentNullException("nv"); RemoteName = remoteName; update = db.UpdateRef(localName); update.IsForceUpdate = forceUpdate; update.NewObjectId = nv.Copy(); update.setRefLogMessage(msg, true); }
/// <summary> /// Parse an encoded type string into a type constant. /// </summary> /// <param name="id"> /// <see cref="ObjectId" /> this type string came from; may be null if /// that is not known at the time the parse is occurring. /// </param> /// <param name="typeString">string version of the type code.</param> /// <param name="endMark"> /// Character immediately following the type string. Usually ' ' /// (space) or '\n' (line feed). /// </param> /// <param name="offset"> /// Position within <paramref name="typeString"/> where the parse /// should start. Updated with the new position (just past /// <paramref name="endMark"/> when the parse is successful). /// </param> /// <returns> /// A type code constant (one of <see cref="OBJ_BLOB"/>, /// <see cref="OBJ_COMMIT"/>, <see cref="OBJ_TAG"/>, <see cref="OBJ_TREE"/> /// </returns> /// <exception cref="CorruptObjectException"></exception> public static int decodeTypeString(AnyObjectId id, byte[] typeString, byte endMark, MutableInteger offset) { try { int position = offset.value; switch (typeString[position]) { case (byte)'b': if (typeString[position + 1] != (byte)'l' || typeString[position + 2] != (byte)'o' || typeString[position + 3] != (byte)'b' || typeString[position + 4] != endMark) { throw new CorruptObjectException(id, "invalid type"); } offset.value = position + 5; return OBJ_BLOB; case (byte)'c': if (typeString[position + 1] != (byte)'o' || typeString[position + 2] != (byte)'m' || typeString[position + 3] != (byte)'m' || typeString[position + 4] != (byte)'i' || typeString[position + 5] != (byte)'t' || typeString[position + 6] != endMark) { throw new CorruptObjectException(id, "invalid type"); } offset.value = position + 7; return OBJ_COMMIT; case (byte)'t': switch (typeString[position + 1]) { case (byte)'a': if (typeString[position + 2] != (byte)'g' || typeString[position + 3] != endMark) throw new CorruptObjectException(id, "invalid type"); offset.value = position + 4; return OBJ_TAG; case (byte)'r': if (typeString[position + 2] != (byte)'e' || typeString[position + 3] != (byte)'e' || typeString[position + 4] != endMark) throw new CorruptObjectException(id, "invalid type"); offset.value = position + 5; return OBJ_TREE; default: throw new CorruptObjectException(id, "invalid type"); } default: throw new CorruptObjectException(id, "invalid type"); } } catch (IndexOutOfRangeException) { throw new CorruptObjectException(id, "invalid type"); } }
private int BinarySearchLevelTwo(AnyObjectId objId, int levelOne) { int[] data = _names[levelOne]; var high = (int)((uint)(_offset32[levelOne].Length) >> 2); if (high == 0) { return -1; } int low = 0; do { var mid = (int)((uint)(low + high) >> 1); int mid4 = mid << 2; int cmp = objId.CompareTo(data, mid4 + mid); if (cmp < 0) { high = mid; } else if (cmp == 0) { return mid; } else { low = mid + 1; } } while (low < high); return -1; }
public override long FindOffset(AnyObjectId objId) { int levelOne = objId.GetFirstByte(); int levelTwo = BinarySearchLevelTwo(objId, levelOne); if (levelTwo == -1) { return -1; } long p = NB.DecodeUInt32(_offset32[levelOne], levelTwo << 2); if ((p & IS_O64) != 0) { return NB.DecodeUInt64(_offset64, (8 * (int)(p & ~IS_O64))); } return p; }
/** * @param curs * temporary working space associated with the calling thread. * @param id * SHA-1 of an object. * * @return a {@link ObjectLoader} for accessing the data of the named * object, or null if the object does not exist. * @ */ public ObjectLoader openObject(WindowCursor curs, AnyObjectId id) { return objectDatabase.openObject(curs, id); }
/** * Create a new parser for a tree appearing in a subset of a repository. * * @param prefix * position of this iterator in the repository tree. The value * may be null or the empty array to indicate the prefix is the * root of the repository. A trailing slash ('/') is * automatically appended if the prefix does not end in '/'. * @param repo * repository to load the tree data from. * @param treeId * identity of the tree being parsed; used only in exception * messages if data corruption is found. * @param curs * a window cursor to use during data access from the repository. * @throws MissingObjectException * the object supplied is not available from the repository. * @throws IncorrectObjectTypeException * the object supplied as an argument is not actually a tree and * cannot be parsed as though it were a tree. * @throws IOException * a loose object or pack file could not be read. */ public CanonicalTreeParser(byte[] prefix, Repository repo, AnyObjectId treeId, WindowCursor curs) : base(prefix) { reset(repo, treeId, curs); }
/** * Reset this parser to walk through the given tree. * * @param repo * repository to load the tree data from. * @param id * identity of the tree being parsed; used only in exception * messages if data corruption is found. * @param curs * window cursor to use during repository access. * @throws MissingObjectException * the object supplied is not available from the repository. * @throws IncorrectObjectTypeException * the object supplied as an argument is not actually a tree and * cannot be parsed as though it were a tree. * @throws IOException * a loose object or pack file could not be read. */ public void reset(Repository repo, AnyObjectId id, WindowCursor curs) { ObjectLoader ldr = repo.openObject(curs, id); if (ldr == null) { ObjectId me = id.ToObjectId(); throw new MissingObjectException(me, Constants.TYPE_TREE); } byte[] subtreeData = ldr.getCachedBytes(); if (ldr.getType() != Constants.OBJ_TREE) { ObjectId me = id.ToObjectId(); throw new IncorrectObjectTypeException(me, Constants.TYPE_TREE); } reset(subtreeData); }
public CorruptObjectException(AnyObjectId id, string message, Exception inner) : base(string.Format("object {0} is corrupt: {1}", id, message), inner) { }
public override void openObjectInAllPacks1(List<PackedObjectLoader> @out, WindowCursor curs, AnyObjectId objectId) { PackFile[] pList = packs(); for (; ; ) { SEARCH: foreach (PackFile p in pList) { try { PackedObjectLoader ldr = p.Get(curs, objectId); if (ldr != null) { @out.Add(ldr); } } catch (PackMismatchException) { // Pack was modified; refresh the entire pack list. // pList = scanPacks(pList); goto SEARCH; } catch (IOException) { // Assume the pack is corrupted. // removePack(p); } } break; } }
public override ObjectLoader openObject2(WindowCursor curs, string objectName, AnyObjectId objectId) { try { return new UnpackedObjectLoader(fileFor(objectName), objectId); } catch (FileNotFoundException) { return null; } catch (DirectoryNotFoundException) { return null; } }
public override ObjectLoader openObject1(WindowCursor curs, AnyObjectId objectId) { PackFile[] pList = packs(); for (; ; ) { SEARCH: foreach (PackFile p in pList) { try { PackedObjectLoader ldr = p.Get(curs, objectId); if (ldr != null) { ldr.materialize(curs); return ldr; } } catch (PackMismatchException) { // Pack was modified; refresh the entire pack list. // pList = scanPacks(pList); goto SEARCH; } catch (IOException) { // Assume the pack is corrupted. // removePack(p); } } return null; } }
public override bool hasObject1(AnyObjectId objectId) { foreach (PackFile p in packs()) { try { if (p.HasObject(objectId)) { return true; } } catch (IOException) { // The hasObject call should have only touched the index, // so any failure here indicates the index is unreadable // by this process, and the pack is likewise not readable. // removePack(p); continue; } } return false; }
/** * Compute the location of a loose object file. * * @param objectId * identity of the loose object to map to the directory. * @return location of the object, if it were to exist as a loose object. */ public FileInfo fileFor(AnyObjectId objectId) { return fileFor(objectId.ToString()); }
///** // * Open object in all packs containing specified object. // * // * @param objectId // * id of object to search for // * @param resultLoaders // * result collection of loaders for this object, filled with // * loaders from all packs containing specified object // * @param curs // * temporary working space associated with the calling thread. // * @ // */ public void openObjectInAllPacks(AnyObjectId objectId, List<PackedObjectLoader> resultLoaders, WindowCursor curs) { objectDatabase.openObjectInAllPacks(resultLoaders, curs, objectId); }
///** // * Open object in all packs containing specified object. // * // * @param objectId // * id of object to search for // * @param curs // * temporary working space associated with the calling thread. // * @return collection of loaders for this object, from all packs containing // * this object // * @ // */ //public ICollection<PackedObjectLoader> OpenObjectInAllPacks(AnyObjectId objectId, WindowCursor cursor) //{ // ICollection<PackedObjectLoader> result = new LinkedList<PackedObjectLoader>(); // OpenObjectInAllPacks(objectId, result, cursor); // return result; //} public List<PackedObjectLoader> openObjectInAllPacks(AnyObjectId objectId, WindowCursor curs) { List<PackedObjectLoader> result = new List<PackedObjectLoader>(); openObjectInAllPacks(objectId, result, curs); return result; }
public TrackingRefUpdate(Repository db, RefSpec spec, AnyObjectId nv, string msg) : this(db, spec.Destination, spec.Source, spec.Force, nv, msg) { if (spec == null) throw new System.ArgumentNullException("spec"); }
public ObjectLoader OpenObject(WindowCursor curs, AnyObjectId id) { return openObject(curs, id); }
private void writeLooseRef(string name, AnyObjectId id) { writeLooseRef(name, id.Name + "\n"); }
// [henon] createSubtreeIterator0 <--- not a typo! /** * Back door to quickly create a subtree iterator for any subtree. * <p> * Don't use this unless you are ObjectWalk. The method is meant to be * called only once the current entry has been identified as a tree and its * identity has been converted into an ObjectId. * * @param repo * repository to load the tree data from. * @param id * ObjectId of the tree to open. * @param curs * window cursor to use during repository access. * @return a new parser that walks over the current subtree. * @throws IOException * a loose object or pack file could not be read. */ public CanonicalTreeParser createSubtreeIterator0(Repository repo, AnyObjectId id, WindowCursor curs) { CanonicalTreeParser p = new CanonicalTreeParser(this); p.reset(repo, id, curs); return p; }
private void writePackedRef(string name, AnyObjectId id) { writePackedRefs(id.Name + " " + name + "\n"); }
/** * Reset this parser to walk through the given tree. * * @param repo * repository to load the tree data from. * @param id * identity of the tree being parsed; used only in exception * messages if data corruption is found. * @param curs * window cursor to use during repository access. * @return the root level parser. * @throws MissingObjectException * the object supplied is not available from the repository. * @throws IncorrectObjectTypeException * the object supplied as an argument is not actually a tree and * cannot be parsed as though it were a tree. * @throws IOException * a loose object or pack file could not be read. */ public CanonicalTreeParser resetRoot(Repository repo, AnyObjectId id, WindowCursor curs) { CanonicalTreeParser p = this; while (p.parent != null) p = (CanonicalTreeParser)p.parent; p.reset(repo, id, curs); return p; }
public override long FindCRC32(AnyObjectId objId) { int levelOne = objId.GetFirstByte(); int levelTwo = BinarySearchLevelTwo(objId, levelOne); if (levelTwo == -1) { throw new MissingObjectException(objId.Copy(), ObjectType.Unknown); } return NB.DecodeUInt32(_crc32[levelOne], levelTwo << 2); }
/** * Compares this abbreviation to a full object id. * * @param other * the other object id. * @return <0 if this abbreviation names an object that is less than * <code>other</code>; 0 if this abbreviation exactly matches the * first {@link #Length} digits of <code>other.name()</code>; * >0 if this abbreviation names an object that is after * <code>other</code>. */ public int prefixCompare(AnyObjectId other) { int cmp; cmp = NB.CompareUInt32(w1, mask(1, other.W1)); if (cmp != 0) return cmp; cmp = NB.CompareUInt32(w2, mask(2, other.W2)); if (cmp != 0) return cmp; cmp = NB.CompareUInt32(w3, mask(3, other.W3)); if (cmp != 0) return cmp; cmp = NB.CompareUInt32(w4, mask(4, other.W4)); if (cmp != 0) return cmp; return NB.CompareUInt32(w5, mask(5, other.W5)); }
/** * @param id * SHA-1 of an object. * * @return a {@link ObjectLoader} for accessing the data of the named * object, or null if the object does not exist. * @ */ public ObjectLoader OpenObject(AnyObjectId id) { WindowCursor wc = new WindowCursor(); try { return openObject(wc, id); } finally { wc.release(); } }