]> source.dussan.org Git - jgit.git/commitdiff
Remove objects before optimization from DfsGarbageCollector 79/11179/2
authorShawn Pearce <spearce@spearce.org>
Thu, 14 Mar 2013 23:14:04 +0000 (16:14 -0700)
committerShawn Pearce <spearce@spearce.org>
Thu, 14 Mar 2013 23:36:36 +0000 (16:36 -0700)
Just counting objects is not sufficient. There are some race
conditions with receive packs and delta base completion that
may confuse such a simple algorithm.

Instead always do the larger set computations, and rely on the
PackWriter having no objects pending as the way to avoid creating
an empty pack file.

Change-Id: Ic81fefb158ed6ef8d6522062f2be0338a49f6bc4

org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsGarbageCollector.java

index 40555dde1624ffe64cfbd308cf35234fb2ebfd4e..8f175a8227878297d79a179fc028893778b679ea 100644 (file)
@@ -100,12 +100,6 @@ public class DfsGarbageCollector {
 
        private Set<ObjectId> nonHeads;
 
-       /** Sum of object counts in {@link #packsBefore}. */
-       private long objectsBefore;
-
-       /** Sum of object counts iN {@link #newPackDesc}. */
-       private long objectsPacked;
-
        private Set<ObjectId> tagTargets;
 
        /**
@@ -288,7 +282,7 @@ public class DfsGarbageCollector {
        }
 
        private void packRest(ProgressMonitor pm) throws IOException {
-               if (nonHeads.isEmpty() || objectsPacked == getObjectsBefore())
+               if (nonHeads.isEmpty())
                        return;
 
                PackWriter pw = newPackWriter();
@@ -304,14 +298,11 @@ public class DfsGarbageCollector {
        }
 
        private void packGarbage(ProgressMonitor pm) throws IOException {
-               if (objectsPacked == getObjectsBefore())
-                       return;
-
                // TODO(sop) This is ugly. The garbage pack needs to be deleted.
                PackWriter pw = newPackWriter();
                try {
                        RevWalk pool = new RevWalk(ctx);
-                       pm.beginTask("Finding garbage", (int) getObjectsBefore());
+                       pm.beginTask("Finding garbage", objectsBefore());
                        for (DfsPackFile oldPack : packsBefore) {
                                PackIndex oldIdx = oldPack.getPackIndex(ctx);
                                for (PackIndex.MutableEntry ent : oldIdx) {
@@ -343,12 +334,11 @@ public class DfsGarbageCollector {
                return ref.getName().startsWith(Constants.R_HEADS);
        }
 
-       private long getObjectsBefore() {
-               if (objectsBefore == 0) {
-                       for (DfsPackFile p : packsBefore)
-                               objectsBefore += p.getPackDescription().getObjectCount();
-               }
-               return objectsBefore;
+       private int objectsBefore() {
+               int cnt = 0;
+               for (DfsPackFile p : packsBefore)
+                       cnt += p.getPackDescription().getObjectCount();
+               return cnt;
        }
 
        private PackWriter newPackWriter() {
@@ -403,7 +393,6 @@ public class DfsGarbageCollector {
 
                PackWriter.Statistics stats = pw.getStatistics();
                pack.setPackStats(stats);
-               objectsPacked += stats.getTotalObjects();
                newPackStats.add(stats);
 
                DfsBlockCache.getInstance().getOrCreate(pack, null);