]> source.dussan.org Git - jgit.git/commitdiff
Pack refs/tags/ with refs/heads/ 72/87972/2
authorShawn Pearce <spearce@spearce.org>
Tue, 3 Jan 2017 22:23:57 +0000 (14:23 -0800)
committerShawn Pearce <spearce@spearce.org>
Tue, 3 Jan 2017 22:46:41 +0000 (14:46 -0800)
This fixes a nasty performance issue for repositories that have many
objects referenced through refs/tags/, but not in refs/heads/.
Situations like this can arise when a project has made releases like
refs/tags/v1.0, and then decides to orphan history and start over for
version 2. The v1.0 objects are not reachable from master anymore,
but are still live due to the v1.0 tag.

When tags are packed in the GC_OTHER pack, bitmaps are not able to
cover the repository's contents. This may cause very slow counting
times during git clone, as the server must enumerate the ancient
history under refs/tags/ to respond to the client.

Clients by default always ask for all tags when asking for all heads
during clone. This has been true since git-core commit 8434c2f1afedb
(Apr 27 2008), when clone was converted to a builtin. Including tags
in the main GC pack should still allow servers to benefit from the
fast full pack reuse path when serving a clone to a client.

Change-Id: I22e29517b5bc6fa3d6b19a19f13bef0c68afdca3

org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcBasicPackingTest.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java

index 41a1a5d3f5a32104ecb20167f56ed6fa7bd87152..762feed3c2a858ca541d3e14e0a79a398571cfe9 100644 (file)
@@ -47,9 +47,10 @@ import static org.junit.Assert.assertEquals;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
-import java.util.Iterator;
+import java.util.List;
 
 import org.eclipse.jgit.junit.TestRepository.BranchBuilder;
 import org.eclipse.jgit.revwalk.RevCommit;
@@ -175,14 +176,9 @@ public class GcBasicPackingTest extends GcTestCase {
                stats = gc.getStatistics();
                assertEquals(0, stats.numberOfLooseObjects);
 
-               Iterator<PackFile> pIt = repo.getObjectDatabase().getPacks().iterator();
-               long c = pIt.next().getObjectCount();
-               if (c == 9)
-                       assertEquals(2, pIt.next().getObjectCount());
-               else {
-                       assertEquals(2, c);
-                       assertEquals(9, pIt.next().getObjectCount());
-               }
+               List<PackFile> packs = new ArrayList<>(
+                               repo.getObjectDatabase().getPacks());
+               assertEquals(11, packs.get(0).getObjectCount());
        }
 
        @Test
index 6f760caea1bed75ec0a7a9581631d36f0061b48b..f7d078fa3cbe199d701014a21986c6c9ab50efa2 100644 (file)
@@ -253,7 +253,7 @@ public class DfsGarbageCollector {
                        for (Ref ref : refsBefore) {
                                if (ref.isSymbolic() || ref.getObjectId() == null)
                                        continue;
-                               if (isHead(ref))
+                               if (isHead(ref) || isTag(ref))
                                        allHeads.add(ref.getObjectId());
                                else if (RefTreeNames.isRefTree(refdb, ref.getName()))
                                        txnHeads.add(ref.getObjectId());
@@ -461,6 +461,10 @@ public class DfsGarbageCollector {
                return ref.getName().startsWith(Constants.R_HEADS);
        }
 
+       private static boolean isTag(Ref ref) {
+               return ref.getName().startsWith(Constants.R_TAGS);
+       }
+
        private int objectsBefore() {
                int cnt = 0;
                for (DfsPackFile p : packsBefore)
index 560db924013cf677c9a9ddc6c9dffb26fce2dfc6..d67b9fa299fc5eea6131bebde66b69f3328d8c59 100644 (file)
@@ -607,7 +607,7 @@ public class GC {
                        nonHeads.addAll(listRefLogObjects(ref, 0));
                        if (ref.isSymbolic() || ref.getObjectId() == null)
                                continue;
-                       if (ref.getName().startsWith(Constants.R_HEADS))
+                       if (isHead(ref) || isTag(ref))
                                allHeads.add(ref.getObjectId());
                        else if (RefTreeNames.isRefTree(refdb, ref.getName()))
                                txnHeads.add(ref.getObjectId());
@@ -660,6 +660,14 @@ public class GC {
                return ret;
        }
 
+       private static boolean isHead(Ref ref) {
+               return ref.getName().startsWith(Constants.R_HEADS);
+       }
+
+       private static boolean isTag(Ref ref) {
+               return ref.getName().startsWith(Constants.R_TAGS);
+       }
+
        /**
         * @param ref
         *            the ref which log should be inspected