Browse Source

Merge branch 'stable-4.11' into stable-5.0

* stable-4.11:
  Fix GC to delete empty fanout directories after repacking

Change-Id: Idce894a24e126e0fbe7bc9b6a3c64318f1a8eb75
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-5.0
Matthias Sohn 6 years ago
parent
commit
b29bb5cbb0
  1. 17
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPruneNonReferencedTest.java
  2. 7
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java

17
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);
}
}
}
}
}

7
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();

Loading…
Cancel
Save