aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorAnna Papitto <annapapitto@google.com>2022-11-10 14:48:22 -0800
committerAnna Papitto <annapapitto@google.com>2022-12-15 11:54:11 -0800
commit5c6c374ff660437571369782bfbacea62d2b81a0 (patch)
treeab7a99140afd96908771b5832a31781b3e07a783 /org.eclipse.jgit.test
parent3a136d2000cc0741c8a0c5ea0f64ec1c0796f3f8 (diff)
downloadjgit-5c6c374ff660437571369782bfbacea62d2b81a0.tar.gz
jgit-5c6c374ff660437571369782bfbacea62d2b81a0.zip
Gc#deleteOrphans: avoid dependence on PackExt alphabetical ordering
Deleting orphan files depends on .pack and .keep being reverse-sorted to before the corresponding index files that could be orphans. The new reverse index file extension (.rev) will break that frail dependency. Rewrite Gc#deleteOrphans to avoid that dependence by tracking which pack names have a .pack or .keep file and then deleting any index files that without a corresponding one. This approach takes linear time instead of the O(n logn) time needed for sorting. Change-Id: If83c378ea070b8871d4b01ae008e7bf8270de763 Signed-off-by: Anna Papitto <annapapitto@google.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcOrphanFilesTest.java35
1 files changed, 33 insertions, 2 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcOrphanFilesTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcOrphanFilesTest.java
index 620aedf20f..342e559643 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcOrphanFilesTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcOrphanFilesTest.java
@@ -10,6 +10,7 @@
package org.eclipse.jgit.internal.storage.file;
+import static org.eclipse.jgit.internal.storage.pack.PackExt.REVERSE_INDEX;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -36,6 +37,14 @@ public class GcOrphanFilesTest extends GcTestCase {
private static final String PACK_File_3 = PACK + "-3.pack";
+ private static final String REVERSE_File_2 = PACK + "-2."
+ + REVERSE_INDEX.getExtension();
+
+ private static final String REVERSE_File_4 = PACK + "-4."
+ + REVERSE_INDEX.getExtension();
+
+ private static final String NONEXISTENT_EXT = PACK + "-4.xxxxx";
+
private File packDir;
@Override
@@ -46,14 +55,27 @@ public class GcOrphanFilesTest extends GcTestCase {
}
@Test
- public void bitmapAndIdxDeletedButPackNot() throws Exception {
+ public void indexesDeletedButPackNot() throws Exception {
createFileInPackFolder(BITMAP_File_1);
createFileInPackFolder(IDX_File_2);
createFileInPackFolder(PACK_File_3);
+ createFileInPackFolder(REVERSE_File_4);
gc.gc().get();
assertFalse(new File(packDir, BITMAP_File_1).exists());
assertFalse(new File(packDir, IDX_File_2).exists());
assertTrue(new File(packDir, PACK_File_3).exists());
+ assertFalse(new File(packDir, REVERSE_File_4).exists());
+ }
+
+ @Test
+ public void noPacks_allIndexesDeleted() throws Exception {
+ createFileInPackFolder(BITMAP_File_1);
+ createFileInPackFolder(IDX_File_2);
+ createFileInPackFolder(REVERSE_File_4);
+ gc.gc().get();
+ assertFalse(new File(packDir, BITMAP_File_1).exists());
+ assertFalse(new File(packDir, IDX_File_2).exists());
+ assertFalse(new File(packDir, REVERSE_File_4).exists());
}
@Test
@@ -77,18 +99,27 @@ public class GcOrphanFilesTest extends GcTestCase {
}
@Test
+ public void nonexistantExtensionNotDeleted() throws Exception {
+ createFileInPackFolder(NONEXISTENT_EXT);
+ gc.gc().get();
+ assertTrue(new File(packDir, NONEXISTENT_EXT).exists());
+ }
+
+ @Test
public void keepPreventsDeletionOfIndexFilesForMissingPackFile()
throws Exception {
createFileInPackFolder(BITMAP_File_1);
- createFileInPackFolder(IDX_File_2);
createFileInPackFolder(BITMAP_File_2);
+ createFileInPackFolder(IDX_File_2);
createFileInPackFolder(KEEP_File_2);
+ createFileInPackFolder(REVERSE_File_2);
createFileInPackFolder(PACK_File_3);
gc.gc().get();
assertFalse(new File(packDir, BITMAP_File_1).exists());
assertTrue(new File(packDir, BITMAP_File_2).exists());
assertTrue(new File(packDir, IDX_File_2).exists());
assertTrue(new File(packDir, KEEP_File_2).exists());
+ assertTrue(new File(packDir, REVERSE_File_2).exists());
assertTrue(new File(packDir, PACK_File_3).exists());
}