pw.release();
}
- odb.openPack(pack, idx);
+ odb.openPack(pack);
updateServerInfo();
prunePacked(odb);
}
copyFile(JGitTestUtil.getTestResourceFile(
"pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idxV2"),
crc32Idx);
- db.openPack(crc32Pack, crc32Idx);
+ db.openPack(crc32Pack);
writeVerifyPack2(true);
}
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 {
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());
}
@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
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();
*
* @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
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())
*
* @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;
}
}
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;
}
}
try {
- newPack = db.openPack(finalPack, finalIdx);
+ newPack = db.openPack(finalPack);
} catch (IOException err) {
keep.unlock();
if (finalPack.exists())
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;
}
};
- private final File idxFile;
-
private final File packFile;
private File keepFile;
/**
* 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);
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;
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);
+ }
}