From 3e64b928d51b3a28e89cfe2a3f0eeae35ef07839 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 18 Feb 2011 17:06:36 -0800 Subject: [PATCH] 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 --- .../eclipse/jgit/storage/pack/PackWriter.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 need = new HashSet(want); + List shortCircuit = new LinkedList(); + 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 { -- 2.39.5