Browse Source

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>
stable-0.12
Shawn O. Pearce 14 years ago
parent
commit
3e64b928d5
  1. 19
      org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java

19
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 {

Loading…
Cancel
Save