Browse Source

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
stable-2.3
Colby Ranger 12 years ago
parent
commit
82ecfb3e31
  1. 2
      org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
  2. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java
  3. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0004_PackReaderTest.java
  4. 4
      org.eclipse.jgit/src/org/eclipse/jgit/storage/file/CachedObjectDirectory.java
  5. 2
      org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileObjectDatabase.java
  6. 6
      org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java
  7. 2
      org.eclipse.jgit/src/org/eclipse/jgit/storage/file/GC.java
  8. 17
      org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java
  9. 2
      org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryPackParser.java
  10. 18
      org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java

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

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

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

4
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

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

6
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

2
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())

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

2
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())

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

Loading…
Cancel
Save