diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2011-01-30 15:10:51 -0800 |
---|---|---|
committer | Chris Aniszczyk <caniszczyk@gmail.com> | 2011-02-01 09:03:24 -0600 |
commit | 2fbcba41e365752681f635c706d577e605d3336a (patch) | |
tree | cc8e9b9acedcc7cf95f2e38e54ddbeed50a31cd3 /org.eclipse.jgit | |
parent | 8f63dface2e08b228cdeb3bef3f93458eab9ce14 (diff) | |
download | jgit-2fbcba41e365752681f635c706d577e605d3336a.tar.gz jgit-2fbcba41e365752681f635c706d577e605d3336a.zip |
PackWriter: Cleanup findObjectToPack method
Some of this code predates making ObjectId.equals() final
and fixing RevObject.equals() to match ObjectId.equals().
It was therefore more complex than it needs to be, because
it tried to work around RevObject's broken equals() rules
by converting to ObjectId in a different collection.
Also combine setUpWalker() and findObjectsToPack() methods,
these can be one method and the code is actually cleaner.
Change-Id: I0f4cf9997cd66d8b6e7f80873979ef1439e507fe
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java | 52 |
1 files changed, 20 insertions, 32 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java index fb15a5c59d..af1fe7d57e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java @@ -55,10 +55,8 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; -import java.util.HashSet; import java.util.Iterator; import java.util.List; -import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; @@ -376,9 +374,8 @@ public class PackWriter { throws IOException { if (countingMonitor == null) countingMonitor = NullProgressMonitor.INSTANCE; - ObjectWalk walker = setUpWalker(interestingObjects, + findObjectsToPack(countingMonitor, interestingObjects, uninterestingObjects); - findObjectsToPack(countingMonitor, walker); } /** @@ -976,32 +973,30 @@ public class PackWriter { out.write(packcsum); } - private ObjectWalk setUpWalker( - final Collection<? extends ObjectId> interestingObjects, - final Collection<? extends ObjectId> uninterestingObjects) + private void findObjectsToPack(final ProgressMonitor countingMonitor, + final Collection<? extends ObjectId> want, + Collection<? extends ObjectId> have) throws MissingObjectException, IOException, IncorrectObjectTypeException { - List<ObjectId> all = new ArrayList<ObjectId>(interestingObjects.size()); - for (ObjectId id : interestingObjects) - all.add(id.copy()); - - final Set<ObjectId> not; - if (uninterestingObjects != null && !uninterestingObjects.isEmpty()) { - not = new HashSet<ObjectId>(); - for (ObjectId id : uninterestingObjects) - not.add(id.copy()); - all.addAll(not); - } else - not = Collections.emptySet(); + countingMonitor.beginTask(JGitText.get().countingObjects, + ProgressMonitor.UNKNOWN); + + if (have == null) + have = Collections.emptySet(); + + List<ObjectId> all = new ArrayList<ObjectId>(want.size() + have.size()); + all.addAll(want); + all.addAll(have); final ObjectWalk walker = new ObjectWalk(reader); walker.setRetainBody(false); - if (not.isEmpty()) + if (have.isEmpty()) walker.sort(RevSort.COMMIT_TIME_DESC); - else + else { walker.sort(RevSort.TOPO); - if (thin && !not.isEmpty()) - walker.sort(RevSort.BOUNDARY, true); + if (thin) + walker.sort(RevSort.BOUNDARY, true); + } AsyncRevObjectQueue q = walker.parseAny(all, true); try { @@ -1010,13 +1005,13 @@ public class PackWriter { RevObject o = q.next(); if (o == null) break; - if (not.contains(o.copy())) + if (have.contains(o)) walker.markUninteresting(o); else walker.markStart(o); } catch (MissingObjectException e) { if (ignoreMissingUninteresting - && not.contains(e.getObjectId())) + && have.contains(e.getObjectId())) continue; throw e; } @@ -1024,14 +1019,7 @@ public class PackWriter { } finally { q.release(); } - return walker; - } - private void findObjectsToPack(final ProgressMonitor countingMonitor, - final ObjectWalk walker) throws MissingObjectException, - IncorrectObjectTypeException, IOException { - countingMonitor.beginTask(JGitText.get().countingObjects, - ProgressMonitor.UNKNOWN); RevObject o; while ((o = walker.next()) != null) { |