]> source.dussan.org Git - jgit.git/commitdiff
GC should not pack objects only referenced by ORIG_HEAD,... 69/72569/2
authorChristian Halstrick <christian.halstrick@sap.com>
Wed, 11 May 2016 20:36:10 +0000 (22:36 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Wed, 18 May 2016 20:49:22 +0000 (22:49 +0200)
There are references which are returned by
RefDatabase.getAdditionalRefs() which are allowed to point to
non-existing objects. These refs should not save objects from being
garbage collected. Examples for these references are ORIG_HEAD,
MERGE_HEAD, FETCH_HEAD and CHERRY_PICK_HEAD. Native git will not take
these references into account when doing a gc and therefore these
references may point to non-existing objects after a gc. Teach JGit's
GC to behave the same: ignore additional refs if they don't start with
"refs/". Examples for refs returned by getAdditionalRefs() which do
start with "refs/" are the bootstrap refs when using reftree's (see
commit 115f1ad3974d1162b33d1c8eff466019d1f249f3). See also
http://article.gmane.org/gmane.comp.version-control.git/294126.

Bug: 479697
Change-Id: I10e40589f13e72aacdd9f86f3b44696fd1cd068a
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
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 33be3b15a87f9bdbf7a19d4bdb1f134f24af2c8f..dc91a70866620c6e7666a3d6cb1a3e536fe1691d 100644 (file)
@@ -241,7 +241,12 @@ public class DfsGarbageCollector {
                if (!addl.isEmpty()) {
                        List<Ref> all = new ArrayList<>(refs.size() + addl.size());
                        all.addAll(refs);
-                       all.addAll(addl);
+                       // add additional refs which start with refs/
+                       for (Ref r : addl) {
+                               if (r.getName().startsWith(Constants.R_REFS)) {
+                                       all.add(r);
+                               }
+                       }
                        return all;
                }
                return refs;
index 9cdb753221be3fe3bfca02937c05e3de3995115d..c998ebe960905517929ec4cb264090f4d1438a8d 100644 (file)
@@ -655,8 +655,12 @@ public class GC {
        }
 
        /**
-        * Returns a collection of all refs and additional refs (e.g. FETCH_HEAD,
-        * MERGE_HEAD, ...)
+        * Returns a collection of all refs and additional refs.
+        *
+        * Additional refs which don't start with "refs/" are not returned because
+        * they should not save objects from being garbage collected. Examples for
+        * such references are ORIG_HEAD, MERGE_HEAD, FETCH_HEAD and
+        * CHERRY_PICK_HEAD.
         *
         * @return a collection of refs pointing to live objects.
         * @throws IOException
@@ -668,7 +672,12 @@ public class GC {
                if (!addl.isEmpty()) {
                        List<Ref> all = new ArrayList<>(refs.size() + addl.size());
                        all.addAll(refs);
-                       all.addAll(addl);
+                       // add additional refs which start with refs/
+                       for (Ref r : addl) {
+                               if (r.getName().startsWith(Constants.R_REFS)) {
+                                       all.add(r);
+                               }
+                       }
                        return all;
                }
                return refs;