Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn2019-03-21 10:35:18 -0400
committerMatthias Sohn2019-03-21 10:35:26 -0400
commit1a289e342083d18fe4013bdb75004c079122df67 (patch)
treeed1c2faf564b7e574d3f2b362a3a69bdbf7ef944
parent6a30ffd0338239a49b1d0c34ad827d317d5b15ec (diff)
parentf06de6b575f3f40ccd944ed2eb5c43d06666687f (diff)
downloadjgit-1a289e342083d18fe4013bdb75004c079122df67.tar.gz
jgit-1a289e342083d18fe4013bdb75004c079122df67.tar.xz
jgit-1a289e342083d18fe4013bdb75004c079122df67.zip
Merge branch 'stable-4.10' into stable-4.11
* stable-4.10: Fix GC to delete empty fanout directories after repacking Change-Id: I7118b9c668dcbb0f5435cc613e964c557bfebf01 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPruneNonReferencedTest.java17
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java7
2 files changed, 22 insertions, 2 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPruneNonReferencedTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPruneNonReferencedTest.java
index 5b1a4178a6..345207089f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPruneNonReferencedTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPruneNonReferencedTest.java
@@ -47,6 +47,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.io.File;
import java.util.Collections;
import java.util.Date;
@@ -113,8 +114,24 @@ public class GcPruneNonReferencedTest extends GcTestCase {
fsTick();
gc.gc();
stats = gc.getStatistics();
+ assertNoEmptyFanoutDirectories();
assertEquals(0, stats.numberOfLooseObjects);
assertEquals(8, stats.numberOfPackedObjects);
assertEquals(2, stats.numberOfPackFiles);
}
+
+ private void assertNoEmptyFanoutDirectories() {
+ File[] fanout = repo.getObjectsDirectory().listFiles();
+ for (File f : fanout) {
+ if (f.isDirectory()) {
+ String[] entries = f.list();
+ if (entries == null || entries.length == 0) {
+ assertFalse(
+ "Found empty fanout directory "
+ + f.getAbsolutePath() + " after pruning",
+ f.getName().length() == 2);
+ }
+ }
+ }
+ }
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
index 0598ddddf1..8a47dfc18c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
@@ -548,9 +548,12 @@ public class GC {
pm.update(1);
if (d.length() != 2)
continue;
- File[] entries = new File(objects, d).listFiles();
- if (entries == null)
+ File dir = new File(objects, d);
+ File[] entries = dir.listFiles();
+ if (entries == null || entries.length == 0) {
+ FileUtils.delete(dir, FileUtils.IGNORE_ERRORS);
continue;
+ }
for (File f : entries) {
checkCancelled();
String fName = f.getName();

Back to the top