From 4334b27d3cf4610b5c99bb29897cdfa785b06474 Mon Sep 17 00:00:00 2001
From: Hector Caballero
Date: Sat, 4 Nov 2017 07:37:39 -0400
Subject: 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
---
.../src/org/eclipse/jgit/junit/TestRepository.java | 2 +-
.../org/eclipse/jgit/internal/storage/file/AbbreviationTest.java | 2 +-
.../eclipse/jgit/internal/storage/file/ConcurrentRepackTest.java | 2 +-
.../org/eclipse/jgit/internal/storage/file/GcOrphanFilesTest.java | 2 +-
.../eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java | 4 ++--
.../org/eclipse/jgit/internal/storage/file/PackWriterTest.java | 4 ++--
.../eclipse/jgit/test/resources/SampleDataRepositoryTestCase.java | 3 +--
.../src/org/eclipse/jgit/internal/storage/file/GC.java | 8 +++-----
.../org/eclipse/jgit/internal/storage/file/LocalCachedPack.java | 2 +-
.../org/eclipse/jgit/internal/storage/file/ObjectDirectory.java | 8 ++++++++
.../src/org/eclipse/jgit/internal/storage/file/PackInserter.java | 3 +--
11 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
index d1358ee2a5..5d21e3d85c 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
@@ -912,7 +912,7 @@ public class TestRepository {
}
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);
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/AbbreviationTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/AbbreviationTest.java
index 343120ef5f..a9edf73b85 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/AbbreviationTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/AbbreviationTest.java
@@ -178,7 +178,7 @@ public class AbbreviationTest extends LocalDiskRepositoryTestCase {
}
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);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ConcurrentRepackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ConcurrentRepackTest.java
index 09438e9649..4813d28017 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ConcurrentRepackTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ConcurrentRepackTest.java
@@ -272,7 +272,7 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
}
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);
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcOrphanFilesTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcOrphanFilesTest.java
index 5393987781..79d72c56d0 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcOrphanFilesTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcOrphanFilesTest.java
@@ -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
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java
index f1cbb99d5a..cbb73bb08e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java
@@ -129,8 +129,8 @@ public class ObjectDirectoryTest extends RepositoryTestCase {
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
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
index 9b97eb4ff4..379432ddbb 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
@@ -337,7 +337,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
*/
@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 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
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,
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/test/resources/SampleDataRepositoryTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/test/resources/SampleDataRepositoryTestCase.java
index a57ef40b62..85a8aa7b8b 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/test/resources/SampleDataRepositoryTestCase.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/test/resources/SampleDataRepositoryTestCase.java
@@ -79,8 +79,7 @@ public abstract class SampleDataRepositoryTestCase extends RepositoryTestCase {
"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"));
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 3ac643d6b2..13d97528c6 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
@@ -57,7 +57,6 @@ import java.nio.channels.FileChannel;
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 @@ public class GC {
*
*/
private void deleteOrphans() {
- Path packDir = Paths.get(repo.getObjectsDirectory().getAbsolutePath(),
- "pack"); //$NON-NLS-1$
+ Path packDir = repo.getObjectDatabase().getPackDirectory().toPath();
List fileNames = null;
try (Stream files = Files.list(packDir)) {
fileNames = files.map(path -> path.getFileName().toString())
@@ -1114,7 +1112,7 @@ public class GC {
// 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 class GC {
}
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$
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LocalCachedPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LocalCachedPack.java
index fd9dcdafad..74453ee4b4 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LocalCachedPack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LocalCachedPack.java
@@ -118,7 +118,7 @@ class LocalCachedPack extends CachedPack {
}
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$
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java
index 1f1d92eb35..068db61150 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java
@@ -196,6 +196,14 @@ public class ObjectDirectory extends FileObjectDatabase {
return objects;
}
+ /**
+ * @return the location of the pack
directory.
+ * @since 4.10
+ */
+ public final File getPackDirectory() {
+ return packDirectory;
+ }
+
/**
* @return the location of the preserved
directory.
*/
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackInserter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackInserter.java
index dd83e251f8..8c3bb08749 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackInserter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackInserter.java
@@ -262,8 +262,7 @@ class PackInserter extends ObjectInserter {
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();
--
cgit v1.2.3