diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2011-02-18 17:06:36 -0800 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2011-02-18 17:36:45 -0800 |
commit | 3e64b928d51b3a28e89cfe2a3f0eeae35ef07839 (patch) | |
tree | 133006fbbdb5b88c232d4eb38be987fedce6c5c2 /org.eclipse.jgit | |
parent | 388ba7e005fdc5b61a7a494fa44ba24489d0c6d0 (diff) | |
download | jgit-3e64b928d51b3a28e89cfe2a3f0eeae35ef07839.tar.gz jgit-3e64b928d51b3a28e89cfe2a3f0eeae35ef07839.zip |
PackWriter: Short-circuit counting on full cached pack reuse
If one or more cached packs fully covers the request, don't bother
with looking up the objects and trying to walk the graph. Just use
the cached packs and return immediately.
This helps clones of quiet repositories that have not been modified
since their last repack, its likely the cached packs are accurate
and no graph walking is required.
Change-Id: I9062a5ac2f71b525322590209664a84051fd5f8a
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java | 19 |
1 files changed, 19 insertions, 0 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 285cd7e21a..5a103bec2b 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 @@ -59,6 +59,7 @@ import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -1130,12 +1131,30 @@ public class PackWriter { if (have.isEmpty()) { walker.sort(RevSort.COMMIT_TIME_DESC); if (useCachedPacks && reuseSupport != null) { + Set<ObjectId> need = new HashSet<ObjectId>(want); + List<CachedPack> shortCircuit = new LinkedList<CachedPack>(); + for (CachedPack pack : reuseSupport.getCachedPacks()) { + if (need.containsAll(pack.getTips())) { + need.removeAll(pack.getTips()); + shortCircuit.add(pack); + } + for (ObjectId id : pack.getTips()) { tipToPack.put(id, pack); all.add(id); } } + + if (need.isEmpty() && !shortCircuit.isEmpty()) { + cachedPacks.addAll(shortCircuit); + for (CachedPack pack : shortCircuit) + countingMonitor.update((int) pack.getObjectCount()); + countingMonitor.endTask(); + stats.timeCounting = System.currentTimeMillis() - countingStart; + return; + } + haveEst += tipToPack.size(); } } else { |