diff options
author | Colby Ranger <cranger@google.com> | 2013-01-10 13:01:17 -0800 |
---|---|---|
committer | Colby Ranger <cranger@google.com> | 2013-01-10 14:02:28 -0800 |
commit | 82ecfb3e317d71d7cbc69a4d205846c2c575415f (patch) | |
tree | c3155107deb135c44583e6bfe98996420a1f1bf3 | |
parent | 5d3c2b3def82298ff046d71726ad1e228500f97e (diff) | |
download | jgit-82ecfb3e317d71d7cbc69a4d205846c2c575415f.tar.gz jgit-82ecfb3e317d71d7cbc69a4d205846c2c575415f.zip |
Remove packIndex field from FileObjDatabase openPack method.
Previously, the FileObjDatabase required both the pack file path and
index file path to be passed to openPack(). A future change to add
a bitmap index will add a .bitmap file parallel to the pack file
(similar to the .idx file). Update the PackFile to support
automatically loading pack index extensions based on the pack file
path.
Change-Id: Ifc8fc3e57f4afa177ba5a88df87334dbfa799f01
10 files changed, 24 insertions, 34 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 9c7570ef61..2f5bcda49d 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 @@ -667,7 +667,7 @@ public class TestRepository<R extends Repository> { pw.release(); } - odb.openPack(pack, idx); + odb.openPack(pack); updateServerInfo(); prunePacked(odb); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java index b6932db596..4752a3fb20 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java @@ -298,7 +298,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { copyFile(JGitTestUtil.getTestResourceFile( "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idxV2"), crc32Idx); - db.openPack(crc32Pack, crc32Idx); + db.openPack(crc32Pack); writeVerifyPack2(true); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0004_PackReaderTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0004_PackReaderTest.java index bdc9edbe35..798968e8b1 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0004_PackReaderTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0004_PackReaderTest.java @@ -62,7 +62,6 @@ import org.junit.Test; public class T0004_PackReaderTest extends SampleDataRepositoryTestCase { private static final String PACK_NAME = "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f"; private static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + ".pack"); - private static final File TEST_IDX = JGitTestUtil.getTestResourceFile(PACK_NAME + ".idx"); @Test public void test003_lookupCompressedObject() throws IOException { @@ -71,7 +70,7 @@ public class T0004_PackReaderTest extends SampleDataRepositoryTestCase { final ObjectLoader or; id = ObjectId.fromString("902d5476fa249b7abc9d84c611577a81381f0327"); - pr = new PackFile(TEST_IDX, TEST_PACK); + pr = new PackFile(TEST_PACK); or = pr.get(new WindowCursor(null), id); assertNotNull(or); assertEquals(Constants.OBJ_TREE, or.getType()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/CachedObjectDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/CachedObjectDirectory.java index 37ab0e0860..0bbb3ffe96 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/CachedObjectDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/CachedObjectDirectory.java @@ -252,8 +252,8 @@ class CachedObjectDirectory extends FileObjectDatabase { } @Override - PackFile openPack(File pack, File idx) throws IOException { - return wrapped.openPack(pack, idx); + PackFile openPack(File pack) throws IOException { + return wrapped.openPack(pack); } @Override diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileObjectDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileObjectDatabase.java index ffbd2edfbd..6c8c1f6afe 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileObjectDatabase.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileObjectDatabase.java @@ -288,7 +288,7 @@ abstract class FileObjectDatabase extends ObjectDatabase { abstract InsertLooseObjectResult insertUnpackedObject(File tmp, ObjectId id, boolean createDuplicate) throws IOException; - abstract PackFile openPack(File pack, File idx) throws IOException; + abstract PackFile openPack(File pack) throws IOException; abstract FileObjectDatabase newCachedFileObjectDatabase(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java index 6ab1b3fd37..4c27c08aef 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java @@ -369,14 +369,12 @@ public class FileRepository extends Repository { * * @param pack * path of the pack file to open. - * @param idx - * path of the corresponding index file. * @throws IOException * index file could not be opened, read, or is not recognized as * a Git pack file index. */ - public void openPack(final File pack, final File idx) throws IOException { - objectDatabase.openPack(pack, idx); + public void openPack(final File pack) throws IOException { + objectDatabase.openPack(pack); } @Override diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/GC.java index 72b150961c..cf4ec58936 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/GC.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/GC.java @@ -710,7 +710,7 @@ public class GC { if (delete && tmpIdx.exists()) tmpIdx.delete(); } - return repo.getObjectDatabase().openPack(realPack, realIdx); + return repo.getObjectDatabase().openPack(realPack); } finally { pw.release(); if (tmpPack != null && tmpPack.exists()) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java index a20f10af47..4d196fbf41 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java @@ -327,28 +327,18 @@ public class ObjectDirectory extends FileObjectDatabase { * * @param pack * path of the pack file to open. - * @param idx - * path of the corresponding index file. * @return the pack that was opened and added to the database. * @throws IOException * index file could not be opened, read, or is not recognized as * a Git pack file index. */ - public PackFile openPack(final File pack, final File idx) + public PackFile openPack(final File pack) throws IOException { final String p = pack.getName(); - final String i = idx.getName(); - if (p.length() != 50 || !p.startsWith("pack-") || !p.endsWith(".pack")) //$NON-NLS-1$ throw new IOException(MessageFormat.format(JGitText.get().notAValidPack, pack)); - if (i.length() != 49 || !i.startsWith("pack-") || !i.endsWith(".idx")) //$NON-NLS-1$ - throw new IOException(MessageFormat.format(JGitText.get().notAValidPack, idx)); - - if (!p.substring(0, 45).equals(i.substring(0, 45))) - throw new IOException(MessageFormat.format(JGitText.get().packDoesNotMatchIndex, pack)); - - PackFile res = new PackFile(idx, pack); + PackFile res = new PackFile(pack); insertPack(res); return res; } @@ -747,8 +737,7 @@ public class ObjectDirectory extends FileObjectDatabase { } final File packFile = new File(packDirectory, packName); - final File idxFile = new File(packDirectory, indexName); - list.add(new PackFile(idxFile, packFile)); + list.add(new PackFile(packFile)); foundNew = true; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryPackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryPackParser.java index 518bccf71b..b61b75c5c0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryPackParser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryPackParser.java @@ -479,7 +479,7 @@ public class ObjectDirectoryPackParser extends PackParser { } try { - newPack = db.openPack(finalPack, finalIdx); + newPack = db.openPack(finalPack); } catch (IOException err) { keep.unlock(); if (finalPack.exists()) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java index a32acfc451..8ad01e1c5c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java @@ -45,6 +45,8 @@ package org.eclipse.jgit.storage.file; +import static org.eclipse.jgit.storage.pack.PackConstants.PACK_INDEX_EXT; + import java.io.EOFException; import java.io.File; import java.io.IOException; @@ -92,8 +94,6 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> { } }; - private final File idxFile; - private final File packFile; private File keepFile; @@ -135,13 +135,10 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> { /** * Construct a reader for an existing, pre-indexed packfile. * - * @param idxFile - * path of the <code>.idx</code> file listing the contents. * @param packFile * path of the <code>.pack</code> file holding the data. */ - public PackFile(final File idxFile, final File packFile) { - this.idxFile = idxFile; + public PackFile(final File packFile) { this.packFile = packFile; this.packLastModified = (int) (packFile.lastModified() >> 10); @@ -158,7 +155,7 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> { throw new PackInvalidException(packFile); try { - final PackIndex idx = PackIndex.open(idxFile); + final PackIndex idx = PackIndex.open(extFile(PACK_INDEX_EXT)); if (packChecksum == null) packChecksum = idx.packChecksum; @@ -1080,4 +1077,11 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> { list.add(offset); } } + + private File extFile(String ext) { + String p = packFile.getName(); + int dot = p.lastIndexOf('.'); + String b = (dot < 0) ? p : p.substring(0, dot); + return new File(packFile.getParentFile(), b + '.' + ext); + } } |