diff options
author | Stefan Lay <stefan.lay@sap.com> | 2012-05-25 03:51:21 -0400 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org <gerrit@eclipse.org> | 2012-05-25 03:51:21 -0400 |
commit | e3bb6ae3fd559234fd7644b828e7b87e55e8522f (patch) | |
tree | 4e5d3a247b4728617a548184610af057199c7680 /org.eclipse.jgit/src/org/eclipse/jgit | |
parent | 23e0a3e734beaed5af14d8fb64c5a8285631adc1 (diff) | |
parent | b14aa4df99e9d87ddcb958deca16c4022107f647 (diff) | |
download | jgit-e3bb6ae3fd559234fd7644b828e7b87e55e8522f.tar.gz jgit-e3bb6ae3fd559234fd7644b828e7b87e55e8522f.zip |
Merge "Enable loading history until a given commit"
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommitList.java | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommitList.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommitList.java index 753cbad5ff..3498059f63 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommitList.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommitList.java @@ -340,6 +340,72 @@ public class RevCommitList<E extends RevCommit> extends RevObjectList<E> { } /** + * Ensures all commits until the given commit are loaded. The revision + * walker specified by {@link #source(RevWalk)} is pumped until the + * specified commit is loaded. Callers can test the final size of the list + * by {@link #size()} to determine if the high water mark specified was met. + * <p/> + * @param commitToLoad + * commit the caller wants this list to contain when the fill + * operation is complete. + * @param highMark + * maximum number of commits the caller wants this list to + * contain when the fill operation is complete. If highMark is 0 + * the walk is pumped until the specified commit or the end of + * the walk is reached. + * @throws IOException + * see {@link RevWalk#next()} + * @throws IncorrectObjectTypeException + * see {@link RevWalk#next()} + * @throws MissingObjectException + * see {@link RevWalk#next()} + */ + public void fillTo(final RevCommit commitToLoad, int highMark) + throws MissingObjectException, IncorrectObjectTypeException, + IOException { + if (walker == null || commitToLoad == null + || (highMark > 0 && size > highMark)) + return; + + RevCommit c = walker.next(); + if (c == null) { + walker = null; + return; + } + enter(size, (E) c); + add((E) c); + + while ((highMark == 0 || size <= highMark) && !c.equals(commitToLoad)) { + int index = size; + Block s = contents; + while (index >> s.shift >= BLOCK_SIZE) { + s = new Block(s.shift + BLOCK_SHIFT); + s.contents[0] = contents; + contents = s; + } + while (s.shift > 0) { + final int i = index >> s.shift; + index -= i << s.shift; + if (s.contents[i] == null) + s.contents[i] = new Block(s.shift - BLOCK_SHIFT); + s = (Block) s.contents[i]; + } + + final Object[] dst = s.contents; + while ((highMark == 0 || size <= highMark) && index < BLOCK_SIZE + && !c.equals(commitToLoad)) { + c = walker.next(); + if (c == null) { + walker = null; + return; + } + enter(size++, (E) c); + dst[index++] = c; + } + } + } + + /** * Optional callback invoked when commits enter the list by fillTo. * <p> * This method is only called during {@link #fillTo(int)}. |