Skip to content

Commit f026c19

Browse files
committedNov 23, 2024
PackDirectory: Filter out tmp GC pack files
git repack passes a ".tmp-XXXX-" prefix to git pack-objects when repacking. git pack-objects then adds a "pack-XXXXX.pack" to this to create the name of new packfiles it writes to. PackDirectory was previously very lenient and would allow these files to be added to its list of known packfiles. Fix PackDirectory to filter these out since they are not meant to be consumed yet, and doing so can cause user facing errors. Change-Id: I072e57d9522e02049db17d3f4977df7eda14bba7 Signed-off-by: Martin Fick <mfick@nvidia.com>
1 parent 079dbe8 commit f026c19

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed
 

‎org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackDirectory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ private Map<String, Map<PackExt, PackFile>> getPackFilesByExtById() {
545545
for (String name : nameList) {
546546
try {
547547
PackFile pack = new PackFile(directory, name);
548-
if (pack.getPackExt() != null) {
548+
if (pack.getPackExt() != null && !pack.isTmpGCFile()) {
549549
Map<PackExt, PackFile> packByExt = packFilesByExtById
550550
.get(pack.getId());
551551
if (packByExt == null) {

‎org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java

+8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class PackFile extends File {
2727
private static final long serialVersionUID = 1L;
2828

2929
private static final String PREFIX = "pack-"; //$NON-NLS-1$
30+
private static final String TMP_GC_PREFIX = ".tmp-"; //$NON-NLS-1$
3031

3132
private final String base; // PREFIX + id i.e.
3233
// pack-0123456789012345678901234567890123456789
@@ -125,6 +126,13 @@ public PackExt getPackExt() {
125126
return packExt;
126127
}
127128

129+
/**
130+
* @return whether the file is a temporary GC file
131+
*/
132+
public boolean isTmpGCFile() {
133+
return id.startsWith(TMP_GC_PREFIX);
134+
}
135+
128136
/**
129137
* Create a new similar PackFile with the given extension instead.
130138
*

0 commit comments

Comments
 (0)
Please sign in to comment.