]> source.dussan.org Git - jgit.git/commitdiff
Merge branch 'stable-4.6' 22/90222/1
authorMatthias Sohn <matthias.sohn@sap.com>
Thu, 2 Feb 2017 22:36:28 +0000 (23:36 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Thu, 2 Feb 2017 22:36:28 +0000 (23:36 +0100)
* stable-4.6:
  GC: delete empty directories after purging loose objects
  GC.prune(Set<ObjectId>): return early if objects directory is empty

Change-Id: I3d6cacf80d3b4c69ba108e970855963bd9f6ee78
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
1  2 
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java

index 5017638e8cf8409a670acf4918316108e94078f2,b60841686801dd52336b7e0639e7e0f99f5ef566..708802a56fb68c8302b666d03835077dd43b1151
@@@ -455,50 -364,49 +455,53 @@@ public class GC 
                Set<ObjectId> indexObjects = null;
                File objects = repo.getObjectsDirectory();
                String[] fanout = objects.list();
-               if (fanout != null && fanout.length > 0) {
-                       pm.beginTask(JGitText.get().pruneLooseUnreferencedObjects,
-                                       fanout.length);
-                       try {
-                               for (String d : fanout) {
+               if (fanout == null || fanout.length == 0) {
+                       return;
+               }
+               pm.beginTask(JGitText.get().pruneLooseUnreferencedObjects,
+                               fanout.length);
+               try {
+                       for (String d : fanout) {
++                              checkCancelled();
+                               pm.update(1);
+                               if (d.length() != 2)
+                                       continue;
+                               File[] entries = new File(objects, d).listFiles();
+                               if (entries == null)
+                                       continue;
+                               for (File f : entries) {
 +                                      checkCancelled();
-                                       pm.update(1);
-                                       if (d.length() != 2)
+                                       String fName = f.getName();
+                                       if (fName.length() != Constants.OBJECT_ID_STRING_LENGTH - 2)
                                                continue;
-                                       File[] entries = new File(objects, d).listFiles();
-                                       if (entries == null)
+                                       if (repo.getFS().lastModified(f) >= expireDate)
                                                continue;
-                                       for (File f : entries) {
-                                               checkCancelled();
-                                               String fName = f.getName();
-                                               if (fName.length() != Constants.OBJECT_ID_STRING_LENGTH - 2)
+                                       try {
+                                               ObjectId id = ObjectId.fromString(d + fName);
+                                               if (objectsToKeep.contains(id))
                                                        continue;
-                                               if (repo.getFS().lastModified(f) >= expireDate)
+                                               if (indexObjects == null)
+                                                       indexObjects = listNonHEADIndexObjects();
+                                               if (indexObjects.contains(id))
                                                        continue;
-                                               try {
-                                                       ObjectId id = ObjectId.fromString(d + fName);
-                                                       if (objectsToKeep.contains(id))
-                                                               continue;
-                                                       if (indexObjects == null)
-                                                               indexObjects = listNonHEADIndexObjects();
-                                                       if (indexObjects.contains(id))
-                                                               continue;
-                                                       deletionCandidates.put(id, f);
-                                               } catch (IllegalArgumentException notAnObject) {
-                                                       // ignoring the file that does not represent loose
-                                                       // object
-                                                       continue;
-                                               }
+                                               deletionCandidates.put(id, f);
+                                       } catch (IllegalArgumentException notAnObject) {
+                                               // ignoring the file that does not represent loose
+                                               // object
+                                               continue;
                                        }
                                }
-                       } finally {
-                               pm.endTask();
                        }
+               } finally {
+                       pm.endTask();
                }
-               if (deletionCandidates.isEmpty())
+               if (deletionCandidates.isEmpty()) {
                        return;
+               }
  
 +              checkCancelled();
 +
                // From the set of current refs remove all those which have been handled
                // during last repack(). Only those refs will survive which have been
                // added or modified since the last repack. Only these can save existing