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
This commit is contained in:
parent
5d3c2b3def
commit
82ecfb3e31
|
@ -667,7 +667,7 @@ public void packAndPrune() throws Exception {
|
|||
pw.release();
|
||||
}
|
||||
|
||||
odb.openPack(pack, idx);
|
||||
odb.openPack(pack);
|
||||
updateServerInfo();
|
||||
prunePacked(odb);
|
||||
}
|
||||
|
|
|
@ -298,7 +298,7 @@ public void testWritePack2DeltasCRC32Copy() throws IOException {
|
|||
copyFile(JGitTestUtil.getTestResourceFile(
|
||||
"pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idxV2"),
|
||||
crc32Idx);
|
||||
db.openPack(crc32Pack, crc32Idx);
|
||||
db.openPack(crc32Pack);
|
||||
|
||||
writeVerifyPack2(true);
|
||||
}
|
||||
|
|
|
@ -62,7 +62,6 @@
|
|||
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 void test003_lookupCompressedObject() throws IOException {
|
|||
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());
|
||||
|
|
|
@ -252,8 +252,8 @@ InsertLooseObjectResult insertUnpackedObject(File tmp, ObjectId objectId,
|
|||
}
|
||||
|
||||
@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
|
||||
|
|
|
@ -288,7 +288,7 @@ abstract long getObjectSize2(WindowCursor curs, String objectName,
|
|||
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();
|
||||
|
||||
|
|
|
@ -369,14 +369,12 @@ public Set<ObjectId> getAdditionalHaves() {
|
|||
*
|
||||
* @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
|
||||
|
|
|
@ -710,7 +710,7 @@ private PackFile writePack(Set<? extends ObjectId> want,
|
|||
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())
|
||||
|
|
|
@ -327,28 +327,18 @@ private CachedPackList scanCachedPacks(CachedPackList old)
|
|||
*
|
||||
* @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 @@ private PackList scanPacksImpl(final PackList old) {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -479,7 +479,7 @@ private PackLock renameAndOpenPack(final String lockMessage)
|
|||
}
|
||||
|
||||
try {
|
||||
newPack = db.openPack(finalPack, finalIdx);
|
||||
newPack = db.openPack(finalPack);
|
||||
} catch (IOException err) {
|
||||
keep.unlock();
|
||||
if (finalPack.exists())
|
||||
|
|
|
@ -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 int compare(final PackFile a, final PackFile b) {
|
|||
}
|
||||
};
|
||||
|
||||
private final File idxFile;
|
||||
|
||||
private final File packFile;
|
||||
|
||||
private File keepFile;
|
||||
|
@ -135,13 +135,10 @@ public int compare(final PackFile a, final PackFile b) {
|
|||
/**
|
||||
* 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 @@ private synchronized PackIndex idx() throws IOException {
|
|||
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 @@ private void setCorrupt(long offset) {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue