Browse Source

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>
tags/v5.11.0.202103091610-r
Nasser Grainawi 3 years ago
parent
commit
093020864f
1 changed files with 16 additions and 13 deletions
  1. 16
    13
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java

+ 16
- 13
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java View File

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

Loading…
Cancel
Save