diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2019-03-21 16:14:03 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2019-03-21 16:14:12 +0100 |
commit | 88fffedd99e64175260e2db7c55887395aba48ab (patch) | |
tree | de683049ea98c7c899d70bf32f9ce49fbcbb4478 | |
parent | 6a7a265b4d2da67dcebeb978d54416446e726eb7 (diff) | |
parent | 08a5d2771d641b2f69e588ce11028d26323283aa (diff) | |
download | jgit-88fffedd99e64175260e2db7c55887395aba48ab.tar.gz jgit-88fffedd99e64175260e2db7c55887395aba48ab.zip |
Merge branch 'stable-5.1' into stable-5.2
* stable-5.1:
Fix GC to delete empty fanout directories after repacking
Change-Id: I0cf4d26bdee5ecee43e723c4176efbce777acabc
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPruneNonReferencedTest.java | 17 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java | 7 |
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 015d44e87f..e1ba130041 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 @@ -549,9 +549,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(); |