ObjectDirectory: Add pack directory getter
So far, in order to get the pack directory it was necessary to resolve it from the object directory. This resolution is already done when creating the object directory, so simplify the call by just adding a getter to the pack directory. Change-Id: I69e783141dc6739024e8b3d5acc30843edd651a7 Signed-off-by: Hector Caballero <hector.caballero@ericsson.com>
This commit is contained in:
parent
178c5d2f0e
commit
4334b27d3c
|
@ -912,7 +912,7 @@ private static void prunePacked(ObjectDirectory odb) throws IOException {
|
|||
}
|
||||
|
||||
private static File nameFor(ObjectDirectory odb, ObjectId name, String t) {
|
||||
File packdir = new File(odb.getDirectory(), "pack");
|
||||
File packdir = odb.getPackDirectory();
|
||||
return new File(packdir, "pack-" + name.name() + t);
|
||||
}
|
||||
|
||||
|
|
|
@ -178,7 +178,7 @@ public void testAbbreviateIsActuallyUnique() throws Exception {
|
|||
}
|
||||
|
||||
String packName = "pack-" + id.name();
|
||||
File packDir = new File(db.getObjectDatabase().getDirectory(), "pack");
|
||||
File packDir = db.getObjectDatabase().getPackDirectory();
|
||||
File idxFile = new File(packDir, packName + ".idx");
|
||||
File packFile = new File(packDir, packName + ".pack");
|
||||
FileUtils.mkdir(packDir, true);
|
||||
|
|
|
@ -272,7 +272,7 @@ private static void touch(final long begin, final File dir) {
|
|||
}
|
||||
|
||||
private File fullPackFileName(final ObjectId name, final String suffix) {
|
||||
final File packdir = new File(db.getObjectDatabase().getDirectory(), "pack");
|
||||
final File packdir = db.getObjectDatabase().getPackDirectory();
|
||||
return new File(packdir, "pack-" + name.name() + suffix);
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ public class GcOrphanFilesTest extends GcTestCase {
|
|||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
packDir = new File(repo.getObjectsDirectory(), PACK);
|
||||
packDir = repo.getObjectDatabase().getPackDirectory();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -129,8 +129,8 @@ public void testScanningForPackfiles() throws Exception {
|
|||
assertTrue(receivingDB.getObjectDatabase().hasPackedObject(id));
|
||||
|
||||
// preparations
|
||||
File packsFolder = new File(receivingDB.getObjectsDirectory(),
|
||||
"pack");
|
||||
File packsFolder = receivingDB.getObjectDatabase()
|
||||
.getPackDirectory();
|
||||
// prepare creation of a temporary file in the pack folder. This
|
||||
// simulates that a native git gc is happening starting to write
|
||||
// temporary files but has not yet finished
|
||||
|
|
|
@ -337,7 +337,7 @@ public void testWritePack2DeltasReuseOffsets() throws IOException {
|
|||
*/
|
||||
@Test
|
||||
public void testWritePack2DeltasCRC32Copy() throws IOException {
|
||||
final File packDir = new File(db.getObjectDatabase().getDirectory(), "pack");
|
||||
final File packDir = db.getObjectDatabase().getPackDirectory();
|
||||
final File crc32Pack = new File(packDir,
|
||||
"pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack");
|
||||
final File crc32Idx = new File(packDir,
|
||||
|
@ -713,7 +713,7 @@ private static PackIndex writePack(FileRepository repo, RevWalk walk,
|
|||
|
||||
pw.preparePack(NullProgressMonitor.INSTANCE, ow, want, have, NONE);
|
||||
String id = pw.computeName().getName();
|
||||
File packdir = new File(repo.getObjectsDirectory(), "pack");
|
||||
File packdir = repo.getObjectDatabase().getPackDirectory();
|
||||
File packFile = new File(packdir, "pack-" + id + ".pack");
|
||||
FileOutputStream packOS = new FileOutputStream(packFile);
|
||||
pw.writePack(NullProgressMonitor.INSTANCE,
|
||||
|
|
|
@ -79,8 +79,7 @@ public static void copyCGitTestPacks(FileRepository repo) throws IOException {
|
|||
"pack-e6d07037cbcf13376308a0a995d1fa48f8f76aaa",
|
||||
"pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12"
|
||||
};
|
||||
final File packDir = new File(repo.getObjectDatabase().getDirectory(),
|
||||
"pack");
|
||||
final File packDir = repo.getObjectDatabase().getPackDirectory();
|
||||
for (String n : packs) {
|
||||
JGitTestUtil.copyTestResource(n + ".pack", new File(packDir, n + ".pack"));
|
||||
JGitTestUtil.copyTestResource(n + ".idx", new File(packDir, n + ".idx"));
|
||||
|
|
|
@ -57,7 +57,6 @@
|
|||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.text.MessageFormat;
|
||||
import java.text.ParseException;
|
||||
|
@ -925,8 +924,7 @@ private static boolean isTag(Ref ref) {
|
|||
* </p>
|
||||
*/
|
||||
private void deleteOrphans() {
|
||||
Path packDir = Paths.get(repo.getObjectsDirectory().getAbsolutePath(),
|
||||
"pack"); //$NON-NLS-1$
|
||||
Path packDir = repo.getObjectDatabase().getPackDirectory().toPath();
|
||||
List<String> fileNames = null;
|
||||
try (Stream<Path> files = Files.list(packDir)) {
|
||||
fileNames = files.map(path -> path.getFileName().toString())
|
||||
|
@ -1114,7 +1112,7 @@ public int compare(PackExt o1, PackExt o2) {
|
|||
|
||||
// create temporary files
|
||||
String id = pw.computeName().getName();
|
||||
File packdir = new File(repo.getObjectsDirectory(), "pack"); //$NON-NLS-1$
|
||||
File packdir = repo.getObjectDatabase().getPackDirectory();
|
||||
tmpPack = File.createTempFile("gc_", ".pack_tmp", packdir); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
final String tmpBase = tmpPack.getName()
|
||||
.substring(0, tmpPack.getName().lastIndexOf('.'));
|
||||
|
@ -1214,7 +1212,7 @@ public int compare(PackExt o1, PackExt o2) {
|
|||
}
|
||||
|
||||
private File nameFor(String name, String ext) {
|
||||
File packdir = new File(repo.getObjectsDirectory(), "pack"); //$NON-NLS-1$
|
||||
File packdir = repo.getObjectDatabase().getPackDirectory();
|
||||
return new File(packdir, "pack-" + name + ext); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ private PackFile getPackFile(String packName) throws FileNotFoundException {
|
|||
}
|
||||
|
||||
private String getPackFilePath(String packName) {
|
||||
final File packDir = new File(odb.getDirectory(), "pack"); //$NON-NLS-1$
|
||||
final File packDir = odb.getPackDirectory();
|
||||
return new File(packDir, "pack-" + packName + ".pack").getPath(); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
|
|
|
@ -196,6 +196,14 @@ public final File getDirectory() {
|
|||
return objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the location of the <code>pack</code> directory.
|
||||
* @since 4.10
|
||||
*/
|
||||
public final File getPackDirectory() {
|
||||
return packDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the location of the <code>preserved</code> directory.
|
||||
*/
|
||||
|
|
|
@ -262,8 +262,7 @@ public void flush() throws IOException {
|
|||
File tmpIdx = idxFor(tmpPack);
|
||||
writePackIndex(tmpIdx, packHash, objectList);
|
||||
|
||||
File realPack = new File(
|
||||
new File(db.getDirectory(), "pack"), //$NON-NLS-1$
|
||||
File realPack = new File(db.getPackDirectory(),
|
||||
"pack-" + computeName(objectList).name() + ".pack"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
db.closeAllPackHandles(realPack);
|
||||
tmpPack.setReadOnly();
|
||||
|
|
Loading…
Reference in New Issue