Browse Source

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>
tags/v4.10.0.201712302008-r
Hector Caballero 6 years ago
parent
commit
4334b27d3c

+ 1
- 1
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java View File

@@ -912,7 +912,7 @@ public class TestRepository<R extends Repository> {
}

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


+ 1
- 1
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/AbbreviationTest.java View File

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

+ 1
- 1
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ConcurrentRepackTest.java View File

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


+ 1
- 1
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcOrphanFilesTest.java View File

@@ -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

+ 2
- 2
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java View File

@@ -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

+ 2
- 2
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java View File

@@ -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,

+ 1
- 2
org.eclipse.jgit.test/tst/org/eclipse/jgit/test/resources/SampleDataRepositoryTestCase.java View File

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

+ 3
- 5
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java View File

@@ -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 {
* </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 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$
}


+ 1
- 1
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LocalCachedPack.java View File

@@ -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$
}
}

+ 8
- 0
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java View File

@@ -196,6 +196,14 @@ public class ObjectDirectory extends FileObjectDatabase {
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.
*/

+ 1
- 2
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackInserter.java View File

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

Loading…
Cancel
Save