]> source.dussan.org Git - jgit.git/commitdiff
GC: delete empty directories after purging loose objects 24/89824/3
authorMatthias Sohn <matthias.sohn@sap.com>
Mon, 30 Jan 2017 00:24:45 +0000 (01:24 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Wed, 1 Feb 2017 22:44:07 +0000 (23:44 +0100)
In order to limit the number of directories we check for emptiness only
consider fanout directories which contained unreferenced loose objects
we deleted in the same gc run.

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

index d1cdbeb46b971868413701e33e23114257cdb5d1..b60841686801dd52336b7e0639e7e0f99f5ef566 100644 (file)
@@ -475,12 +475,19 @@ public class GC {
                // loose objects. Make a last check, though, to avoid deleting objects
                // that could have been referenced while the candidates list was being
                // built (by an incoming push, for example).
+               Set<File> touchedFanout = new HashSet<>();
                for (File f : deletionCandidates.values()) {
                        if (f.lastModified() < expireDate) {
                                f.delete();
+                               touchedFanout.add(f.getParentFile());
                        }
                }
 
+               for (File f : touchedFanout) {
+                       FileUtils.delete(f,
+                                       FileUtils.EMPTY_DIRECTORIES_ONLY | FileUtils.IGNORE_ERRORS);
+               }
+
                repo.getObjectDatabase().close();
        }