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 9c7570ef6..2f5bcda49 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 { 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 b6932db59..4752a3fb2 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 bdc9edbe3..798968e8b 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/dfs/DfsGarbageCollector.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsGarbageCollector.java index 7d8ff3e1a..5da958a0b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsGarbageCollector.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsGarbageCollector.java @@ -65,6 +65,7 @@ import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.storage.dfs.DfsObjDatabase.PackSource; import org.eclipse.jgit.storage.file.PackIndex; import org.eclipse.jgit.storage.pack.PackConfig; +import org.eclipse.jgit.storage.pack.PackConstants; import org.eclipse.jgit.storage.pack.PackWriter; import org.eclipse.jgit.util.io.CountingOutputStream; @@ -318,14 +319,14 @@ public class DfsGarbageCollector { DfsPackDescription pack = repo.getObjectDatabase().newPack(source); newPackDesc.add(pack); - out = objdb.writePackFile(pack); + out = objdb.writeFile(pack, PackConstants.PACK_EXT); try { pw.writePack(pm, pm, out); } finally { out.close(); } - out = objdb.writePackIndex(pack); + out = objdb.writeFile(pack, PackConstants.PACK_INDEX_EXT); try { CountingOutputStream cnt = new CountingOutputStream(out); pw.writeIndex(cnt); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsInserter.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsInserter.java index 0e02e00bc..a86326e39 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsInserter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsInserter.java @@ -43,6 +43,9 @@ package org.eclipse.jgit.storage.dfs; +import static org.eclipse.jgit.storage.pack.PackConstants.PACK_EXT; +import static org.eclipse.jgit.storage.pack.PackConstants.PACK_INDEX_EXT; + import java.io.EOFException; import java.io.IOException; import java.io.InputStream; @@ -220,7 +223,7 @@ public class DfsInserter extends ObjectInserter { rollback = true; packDsc = db.newPack(DfsObjDatabase.PackSource.INSERT); - packOut = new PackStream(db.writePackFile(packDsc)); + packOut = new PackStream(db.writeFile(packDsc, PACK_EXT)); packKey = new DfsPackKey(); // Write the header as though it were a single object pack. @@ -250,7 +253,7 @@ public class DfsInserter extends ObjectInserter { packIndex = PackIndex.read(buf.openInputStream()); } - DfsOutputStream os = db.writePackIndex(pack); + DfsOutputStream os = db.writeFile(pack, PACK_INDEX_EXT); try { CountingOutputStream cnt = new CountingOutputStream(os); if (buf != null) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsObjDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsObjDatabase.java index 32244c1b0..f24189412 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsObjDatabase.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsObjDatabase.java @@ -264,62 +264,40 @@ public abstract class DfsObjDatabase extends ObjectDatabase { protected abstract List listPacks() throws IOException; /** - * Open a pack file for reading. + * Open a pack, pack index, or other related file for reading. * * @param desc - * description of pack to read. This is an instance previously - * obtained from {@link #listPacks()}, but not necessarily from - * the same DfsObjDatabase instance. - * @return channel to read the pack file. + * description of pack related to the data that will be read. + * This is an instance previously obtained from + * {@link #listPacks()}, but not necessarily from the same + * DfsObjDatabase instance. + * @param ext + * file extension that will be read i.e "pack" or "idx". + * @return channel to read the file. * @throws FileNotFoundException * the file does not exist. * @throws IOException * the file cannot be opened. */ - protected abstract ReadableChannel openPackFile(DfsPackDescription desc) + protected abstract ReadableChannel openFile( + DfsPackDescription desc, String ext) throws FileNotFoundException, IOException; /** - * Open a pack index for reading. + * Open a pack, pack index, or other related file for writing. * * @param desc - * description of index to read. This is an instance previously - * obtained from {@link #listPacks()}, but not necessarily from - * the same DfsObjDatabase instance. - * @return channel to read the pack file. - * @throws FileNotFoundException - * the file does not exist. - * @throws IOException - * the file cannot be opened. - */ - protected abstract ReadableChannel openPackIndex(DfsPackDescription desc) - throws FileNotFoundException, IOException; - - /** - * Open a pack file for writing. - * - * @param desc - * description of pack to write. This is an instance previously - * obtained from {@link #newPack(PackSource)}. - * @return channel to write the pack file. + * description of pack related to the data that will be written. + * This is an instance previously obtained from + * {@link #newPack(PackSource)}. + * @param ext + * file extension that will be written i.e "pack" or "idx". + * @return channel to write the file. * @throws IOException * the file cannot be opened. */ - protected abstract DfsOutputStream writePackFile(DfsPackDescription desc) - throws IOException; - - /** - * Open a pack index for writing. - * - * @param desc - * description of index to write. This is an instance previously - * obtained from {@link #newPack(PackSource)}. - * @return channel to write the index file. - * @throws IOException - * the file cannot be opened. - */ - protected abstract DfsOutputStream writePackIndex(DfsPackDescription desc) - throws IOException; + protected abstract DfsOutputStream writeFile( + DfsPackDescription desc, String ext) throws IOException; void addPack(DfsPackFile newPack) throws IOException { PackList o, n; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsOutputStream.java index 434676040..9a2aff4fa 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsOutputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsOutputStream.java @@ -50,8 +50,7 @@ import java.nio.ByteBuffer; /** * Output stream to create a file on the DFS. * - * @see DfsObjDatabase#writePackFile(DfsPackDescription) - * @see DfsObjDatabase#writePackIndex(DfsPackDescription) + * @see DfsObjDatabase#writeFile(DfsPackDescription, String) */ public abstract class DfsOutputStream extends OutputStream { /** diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackCompactor.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackCompactor.java index 773366722..8515acd7a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackCompactor.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackCompactor.java @@ -44,6 +44,8 @@ package org.eclipse.jgit.storage.dfs; import static org.eclipse.jgit.storage.dfs.DfsObjDatabase.PackSource.COMPACT; +import static org.eclipse.jgit.storage.pack.PackConstants.PACK_EXT; +import static org.eclipse.jgit.storage.pack.PackConstants.PACK_INDEX_EXT; import java.io.IOException; import java.util.ArrayList; @@ -283,7 +285,7 @@ public class DfsPackCompactor { private void writePack(DfsObjDatabase objdb, DfsPackDescription pack, PackWriter pw, ProgressMonitor pm) throws IOException { - DfsOutputStream out = objdb.writePackFile(pack); + DfsOutputStream out = objdb.writeFile(pack, PACK_EXT); try { CountingOutputStream cnt = new CountingOutputStream(out); pw.writePack(pm, pm, cnt); @@ -296,7 +298,7 @@ public class DfsPackCompactor { private void writeIndex(DfsObjDatabase objdb, DfsPackDescription pack, PackWriter pw) throws IOException { - DfsOutputStream out = objdb.writePackIndex(pack); + DfsOutputStream out = objdb.writeFile(pack, PACK_INDEX_EXT); try { CountingOutputStream cnt = new CountingOutputStream(out); pw.writeIndex(cnt); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackDescription.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackDescription.java index 79cd04f30..e23f14c8f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackDescription.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackDescription.java @@ -47,6 +47,7 @@ import java.util.Set; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.storage.dfs.DfsObjDatabase.PackSource; +import org.eclipse.jgit.storage.pack.PackConstants; import org.eclipse.jgit.storage.pack.PackWriter; /** @@ -81,9 +82,9 @@ public class DfsPackDescription implements Comparable { /** * Initialize a description by pack name and repository. *

- * The corresponding index file is assumed to exist and end with ".idx" - * instead of ".pack". If this is not true implementors must extend the - * class and override {@link #getIndexName()}. + * The corresponding index file is assumed to exist. If this is not true + * implementors must extend the class and override + * {@link #getFileName(String)}. *

* Callers should also try to fill in other fields if they are reasonably * free to access at the time this instance is being initialized. @@ -95,7 +96,8 @@ public class DfsPackDescription implements Comparable { */ public DfsPackDescription(DfsRepositoryDescription repoDesc, String name) { this.repoDesc = repoDesc; - this.packName = name; + int dot = name.lastIndexOf('.'); + this.packName = (dot < 0) ? name : name.substring(0, dot); } /** @return description of the repository. */ @@ -103,18 +105,13 @@ public class DfsPackDescription implements Comparable { return repoDesc; } - /** @return name of the pack file. */ - public String getPackName() { - return packName; - } - - /** @return name of the index file. */ - public String getIndexName() { - String name = getPackName(); - int dot = name.lastIndexOf('.'); - if (dot < 0) - dot = name.length(); - return name.substring(0, dot) + ".idx"; //$NON-NLS-1$ + /** + * @param ext + * the file extension + * @return name of the file. + * */ + public String getFileName(String ext) { + return packName + '.' + ext; } /** @return the source of the pack. */ @@ -261,14 +258,14 @@ public class DfsPackDescription implements Comparable { @Override public int hashCode() { - return getPackName().hashCode(); + return packName.hashCode(); } @Override public boolean equals(Object b) { if (b instanceof DfsPackDescription) { DfsPackDescription desc = (DfsPackDescription) b; - return getPackName().equals(desc.getPackName()) && + return packName.equals(desc.packName) && getRepositoryDescription().equals(desc.getRepositoryDescription()); } return false; @@ -299,6 +296,6 @@ public class DfsPackDescription implements Comparable { @Override public String toString() { - return getPackName(); + return getFileName(PackConstants.PACK_EXT); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackFile.java index ea8aa73cf..221211624 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackFile.java @@ -45,6 +45,9 @@ package org.eclipse.jgit.storage.dfs; +import static org.eclipse.jgit.storage.pack.PackConstants.PACK_EXT; +import static org.eclipse.jgit.storage.pack.PackConstants.PACK_INDEX_EXT; + import java.io.BufferedInputStream; import java.io.EOFException; import java.io.IOException; @@ -187,7 +190,7 @@ public final class DfsPackFile { } private String getPackName() { - return packDesc.getPackName(); + return packDesc.getFileName(PACK_EXT); } void setBlockSize(int newSize) { @@ -229,7 +232,7 @@ public final class DfsPackFile { PackIndex idx; try { - ReadableChannel rc = ctx.db.openPackIndex(packDesc); + ReadableChannel rc = ctx.db.openFile(packDesc, PACK_INDEX_EXT); try { InputStream in = Channels.newInputStream(rc); int wantSize = 8192; @@ -246,13 +249,15 @@ public final class DfsPackFile { } catch (EOFException e) { invalid = true; IOException e2 = new IOException(MessageFormat.format( - DfsText.get().shortReadOfIndex, packDesc.getIndexName())); + DfsText.get().shortReadOfIndex, + packDesc.getFileName(PACK_INDEX_EXT))); e2.initCause(e); throw e2; } catch (IOException e) { invalid = true; IOException e2 = new IOException(MessageFormat.format( - DfsText.get().cannotReadIndex, packDesc.getIndexName())); + DfsText.get().cannotReadIndex, + packDesc.getFileName(PACK_INDEX_EXT))); e2.initCause(e); throw e2; } @@ -616,7 +621,7 @@ public final class DfsPackFile { throw new PackInvalidException(getPackName()); boolean close = true; - ReadableChannel rc = ctx.db.openPackFile(packDesc); + ReadableChannel rc = ctx.db.openFile(packDesc, PACK_EXT); try { // If the block alignment is not yet known, discover it. Prefer the // larger size from either the cache or the file itself. diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackParser.java index 6ec01fc47..13943d1a6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackParser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackParser.java @@ -58,6 +58,7 @@ import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.storage.file.PackIndex; import org.eclipse.jgit.storage.file.PackLock; +import org.eclipse.jgit.storage.pack.PackConstants; import org.eclipse.jgit.transport.PackParser; import org.eclipse.jgit.transport.PackedObjectInfo; @@ -205,7 +206,7 @@ public class DfsPackParser extends PackParser { packDsc = objdb.newPack(DfsObjDatabase.PackSource.RECEIVE); packKey = new DfsPackKey(); - out = objdb.writePackFile(packDsc); + out = objdb.writeFile(packDsc, PackConstants.PACK_EXT); int size = out.blockSize(); if (size <= 0) size = blockCache.getBlockSize(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsReader.java index b5244d043..d83137d85 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsReader.java @@ -47,6 +47,7 @@ package org.eclipse.jgit.storage.dfs; import static org.eclipse.jgit.lib.Constants.OBJECT_ID_LENGTH; import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; import static org.eclipse.jgit.lib.Constants.OBJ_TREE; +import static org.eclipse.jgit.storage.pack.PackConstants.PACK_EXT; import java.io.IOException; import java.io.InterruptedIOException; @@ -661,7 +662,7 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs { pack.setInvalid(); throw new IOException(MessageFormat.format( JGitText.get().packfileCorruptionDetected, - pack.getPackDescription().getPackName())); + pack.getPackDescription().getFileName(PACK_EXT))); } } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/InMemoryRepository.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/InMemoryRepository.java index 1783a6032..4086539dd 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/InMemoryRepository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/InMemoryRepository.java @@ -6,7 +6,9 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicInteger; @@ -101,50 +103,31 @@ public class InMemoryRepository extends DfsRepository { } @Override - protected ReadableChannel openPackFile(DfsPackDescription desc) - throws FileNotFoundException { + protected ReadableChannel openFile(DfsPackDescription desc, String ext) + throws FileNotFoundException, IOException { MemPack memPack = (MemPack) desc; - if (memPack.packFile == null) - throw new FileNotFoundException(desc.getPackName()); - return new ByteArrayReadableChannel(memPack.packFile); + byte[] file = memPack.fileMap.get(ext); + if (file == null) + throw new FileNotFoundException(desc.getFileName(ext)); + return new ByteArrayReadableChannel(file); } @Override - protected ReadableChannel openPackIndex(DfsPackDescription desc) - throws FileNotFoundException { - MemPack memPack = (MemPack) desc; - if (memPack.packIndex == null) - throw new FileNotFoundException(desc.getIndexName()); - return new ByteArrayReadableChannel(memPack.packIndex); - } - - @Override - protected DfsOutputStream writePackFile(DfsPackDescription desc) { - final MemPack memPack = (MemPack) desc; - return new Out() { - @Override - public void flush() { - memPack.packFile = getData(); - } - }; - } - - @Override - protected DfsOutputStream writePackIndex(DfsPackDescription desc) { + protected DfsOutputStream writeFile( + DfsPackDescription desc, final String ext) throws IOException { final MemPack memPack = (MemPack) desc; return new Out() { @Override public void flush() { - memPack.packIndex = getData(); + memPack.fileMap.put(ext, getData()); } }; } } private static class MemPack extends DfsPackDescription { - private byte[] packFile; - - private byte[] packIndex; + private final Map + fileMap = new HashMap(); MemPack(String name, DfsRepositoryDescription repoDesc) { super(repoDesc, name); 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 37ab0e086..0bbb3ffe9 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 ffbd2edfb..6c8c1f6af 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 6ab1b3fd3..4c27c08ae 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 72b150961..cf4ec5893 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 a20f10af4..4d196fbf4 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 518bccf71..b61b75c5c 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 a32acfc45..8ad01e1c5 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 { } }; - private final File idxFile; - private final File packFile; private File keepFile; @@ -135,13 +135,10 @@ public class PackFile implements Iterable { /** * Construct a reader for an existing, pre-indexed packfile. * - * @param idxFile - * path of the .idx file listing the contents. * @param packFile * path of the .pack 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 { 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 { 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); + } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackConstants.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackConstants.java new file mode 100644 index 000000000..84acf720f --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackConstants.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2013, Google Inc. + * and other copyright owners as documented in the project's IP log. + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Distribution License v1.0 which + * accompanies this distribution, is reproduced below, and is + * available at http://www.eclipse.org/org/documents/edl-v10.php + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Eclipse Foundation, Inc. nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.eclipse.jgit.storage.pack; + +/** Misc. constants used with pack files. */ +public class PackConstants { + + /** A pack file extension. */ + public static final String PACK_EXT = "pack"; //$NON-NLS-1$ + + /** A pack index file extension. */ + public static final String PACK_INDEX_EXT = "idx"; //$NON-NLS-1$ + + private PackConstants() { + } +}