summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorNasser Grainawi <quic_nasserg@quicinc.com>2021-03-03 17:05:21 -0700
committerNasser Grainawi <quic_nasserg@quicinc.com>2021-03-04 16:37:08 -0700
commit093020864f06b75708f8ec225e5df9e0ad54f9c1 (patch)
tree528a2ba1c0c90a6090cda9fb88ac3d8ed10447c2 /org.eclipse.jgit
parentc57b2935cd8bf160cb81ef86205ea0c5ea36da98 (diff)
downloadjgit-093020864f06b75708f8ec225e5df9e0ad54f9c1.tar.gz
jgit-093020864f06b75708f8ec225e5df9e0ad54f9c1.zip
GC: deleteOrphans: Use PackFile
It's easier to follow the logic here when we can use our own objects instead of Strings. Change-Id: I6a166edcc67903fc1ca3544f458634c4cef8fde7 Signed-off-by: Nasser Grainawi <quic_nasserg@quicinc.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java29
1 files changed, 16 insertions, 13 deletions
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 e328870daa..9366404ba4 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
@@ -12,6 +12,8 @@ package org.eclipse.jgit.internal.storage.file;
import static org.eclipse.jgit.internal.storage.pack.PackExt.BITMAP_INDEX;
import static org.eclipse.jgit.internal.storage.pack.PackExt.INDEX;
+import static org.eclipse.jgit.internal.storage.pack.PackExt.PACK;
+import static org.eclipse.jgit.internal.storage.pack.PackExt.KEEP;
import java.io.File;
import java.io.FileOutputStream;
@@ -965,20 +967,21 @@ public class GC {
return;
}
- String base = null;
+ String latestId = null;
for (String n : fileNames) {
- if (n.endsWith(PACK_EXT) || n.endsWith(KEEP_EXT)) {
- base = n.substring(0, n.lastIndexOf('.'));
- } else {
- if (base == null || !n.startsWith(base)) {
- try {
- Path delete = packDir.resolve(n);
- FileUtils.delete(delete.toFile(),
- FileUtils.RETRY | FileUtils.SKIP_MISSING);
- LOG.warn(JGitText.get().deletedOrphanInPackDir, delete);
- } catch (IOException e) {
- LOG.error(e.getMessage(), e);
- }
+ PackFile pf = new PackFile(packDir.toFile(), n);
+ PackExt ext = pf.getPackExt();
+ if (ext.equals(PACK) || ext.equals(KEEP)) {
+ latestId = pf.getId();
+ }
+ if (latestId == null || !pf.getId().equals(latestId)) {
+ // no pack or keep for this id
+ try {
+ FileUtils.delete(pf,
+ FileUtils.RETRY | FileUtils.SKIP_MISSING);
+ LOG.warn(JGitText.get().deletedOrphanInPackDir, pf);
+ } catch (IOException e) {
+ LOG.error(e.getMessage(), e);
}
}
}