diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2012-05-19 16:49:03 +0200 |
---|---|---|
committer | Stefan Lay <stefan.lay@sap.com> | 2012-05-30 10:26:21 +0200 |
commit | 59d2ef94709ba29395c58fec454bf846f920e99a (patch) | |
tree | c5775d0f6d697f3cd6fd73489d61e0b6c44bfef2 /org.eclipse.jgit | |
parent | 24a0f47e32ab7cdf20c2201d7100599ea057f8a3 (diff) | |
download | jgit-59d2ef94709ba29395c58fec454bf846f920e99a.tar.gz jgit-59d2ef94709ba29395c58fec454bf846f920e99a.zip |
Enable loading history until a given commit
This is needed to allow jumping to a selected commit when loading
history incrementally.
Change-Id: Id3b97d88d3b4b2d67561b11f8810cb88fe040823
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to '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)}. |