PackExt: add a #getTmpExtension method
During garbage collection, extensions for temporary files for indices are formatted manually. Add a method to PackExt to generate the temporary file extensions for each type of index file programmatically. Change-Id: I210bc2702e750bf0aea643b1a9a8536adebef179 Signed-off-by: Anna Papitto <annapapitto@google.com>
This commit is contained in:
parent
e6f216119f
commit
2c89a3ec74
|
@ -11,6 +11,7 @@
|
||||||
package org.eclipse.jgit.internal.storage.file;
|
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.BITMAP_INDEX;
|
||||||
|
import static org.eclipse.jgit.internal.storage.pack.PackExt.COMMIT_GRAPH;
|
||||||
import static org.eclipse.jgit.internal.storage.pack.PackExt.INDEX;
|
import static org.eclipse.jgit.internal.storage.pack.PackExt.INDEX;
|
||||||
import static org.eclipse.jgit.internal.storage.pack.PackExt.KEEP;
|
import static org.eclipse.jgit.internal.storage.pack.PackExt.KEEP;
|
||||||
import static org.eclipse.jgit.internal.storage.pack.PackExt.PACK;
|
import static org.eclipse.jgit.internal.storage.pack.PackExt.PACK;
|
||||||
|
@ -943,7 +944,8 @@ void writeCommitGraph(@NonNull Set<? extends ObjectId> wants)
|
||||||
try (RevWalk walk = new RevWalk(repo)) {
|
try (RevWalk walk = new RevWalk(repo)) {
|
||||||
CommitGraphWriter writer = new CommitGraphWriter(
|
CommitGraphWriter writer = new CommitGraphWriter(
|
||||||
GraphCommits.fromWalk(pm, wants, walk));
|
GraphCommits.fromWalk(pm, wants, walk));
|
||||||
tmpFile = File.createTempFile("commit_", ".graph_tmp", //$NON-NLS-1$//$NON-NLS-2$
|
tmpFile = File.createTempFile("commit_", //$NON-NLS-1$
|
||||||
|
COMMIT_GRAPH.getTmpExtension(),
|
||||||
repo.getObjectDatabase().getInfoDirectory());
|
repo.getObjectDatabase().getInfoDirectory());
|
||||||
// write the commit-graph file
|
// write the commit-graph file
|
||||||
try (FileOutputStream fos = new FileOutputStream(tmpFile);
|
try (FileOutputStream fos = new FileOutputStream(tmpFile);
|
||||||
|
@ -1292,10 +1294,11 @@ private Pack writePack(@NonNull Set<? extends ObjectId> want,
|
||||||
ObjectId id = pw.computeName();
|
ObjectId id = pw.computeName();
|
||||||
File packdir = repo.getObjectDatabase().getPackDirectory();
|
File packdir = repo.getObjectDatabase().getPackDirectory();
|
||||||
packdir.mkdirs();
|
packdir.mkdirs();
|
||||||
tmpPack = File.createTempFile("gc_", ".pack_tmp", packdir); //$NON-NLS-1$ //$NON-NLS-2$
|
tmpPack = File.createTempFile("gc_", //$NON-NLS-1$
|
||||||
final String tmpBase = tmpPack.getName()
|
PACK.getTmpExtension(), packdir);
|
||||||
|
String tmpBase = tmpPack.getName()
|
||||||
.substring(0, tmpPack.getName().lastIndexOf('.'));
|
.substring(0, tmpPack.getName().lastIndexOf('.'));
|
||||||
File tmpIdx = new File(packdir, tmpBase + ".idx_tmp"); //$NON-NLS-1$
|
File tmpIdx = new File(packdir, tmpBase + INDEX.getTmpExtension());
|
||||||
tmpExts.put(INDEX, tmpIdx);
|
tmpExts.put(INDEX, tmpIdx);
|
||||||
|
|
||||||
if (!tmpIdx.createNewFile())
|
if (!tmpIdx.createNewFile())
|
||||||
|
@ -1321,7 +1324,8 @@ private Pack writePack(@NonNull Set<? extends ObjectId> want,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pw.prepareBitmapIndex(pm)) {
|
if (pw.prepareBitmapIndex(pm)) {
|
||||||
File tmpBitmapIdx = new File(packdir, tmpBase + ".bitmap_tmp"); //$NON-NLS-1$
|
File tmpBitmapIdx = new File(packdir,
|
||||||
|
tmpBase + BITMAP_INDEX.getTmpExtension());
|
||||||
tmpExts.put(BITMAP_INDEX, tmpBitmapIdx);
|
tmpExts.put(BITMAP_INDEX, tmpBitmapIdx);
|
||||||
|
|
||||||
if (!tmpBitmapIdx.createNewFile())
|
if (!tmpBitmapIdx.createNewFile())
|
||||||
|
|
|
@ -71,6 +71,15 @@ public int getBit() {
|
||||||
return 1 << getPosition();
|
return 1 << getPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format a temporary file extension for this PackExt.
|
||||||
|
*
|
||||||
|
* @return a temporary file extension
|
||||||
|
*/
|
||||||
|
public String getTmpExtension() {
|
||||||
|
return String.format(".%s_tmp", ext); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
Loading…
Reference in New Issue