]> source.dussan.org Git - jgit.git/commitdiff
Remove packIndex field from FileObjDatabase openPack method. 02/9602/2
authorColby Ranger <cranger@google.com>
Thu, 10 Jan 2013 21:01:17 +0000 (13:01 -0800)
committerColby Ranger <cranger@google.com>
Thu, 10 Jan 2013 22:02:28 +0000 (14:02 -0800)
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

org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0004_PackReaderTest.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/CachedObjectDirectory.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileObjectDatabase.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/GC.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryPackParser.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java

index 9c7570ef619a4373231189e81e4edf6e2224993a..2f5bcda49df27d35228b60b7dab98524394253d7 100644 (file)
@@ -667,7 +667,7 @@ public class TestRepository<R extends Repository> {
                                pw.release();
                        }
 
-                       odb.openPack(pack, idx);
+                       odb.openPack(pack);
                        updateServerInfo();
                        prunePacked(odb);
                }
index b6932db596452509aae376b25693d1088117a76a..4752a3fb2026ec1af762b544c7a71995f56aec43 100644 (file)
@@ -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);
        }
index bdc9edbe350961f7c5bf03645c65f0ec969c2cf4..798968e8b126b8a1d95bbbbc37d32e9d7e105d5f 100644 (file)
@@ -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());
index 37ab0e0860f32cd7a50de57b71e39ed3a1226dba..0bbb3ffe96bcab7ea9bab64f296b962de9158346 100644 (file)
@@ -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
index ffbd2edfbde1ff8934f42724cf93b0241fdf309e..6c8c1f6afebeaf1dfc0e65ee58cbbe3a482fb674 100644 (file)
@@ -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();
 
index 6ab1b3fd37bcf4962cec3afa6dba40110e708dd2..4c27c08aeff7b464a8dc20582bbe405ca043c100 100644 (file)
@@ -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
index 72b150961c6f8a08406196f013e1e298f9509158..cf4ec589366c24f7557c0110c07a1ef0b28f7431 100644 (file)
@@ -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())
index a20f10af4783ad2a48162479755d156f06cd17f2..4d196fbf41386e2299f330c4ea7aeef0633026f4 100644 (file)
@@ -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;
                }
 
index 518bccf71b908938b946ec623ab762e90a2c307c..b61b75c5c0302c3bef1dac515e0df75208602064 100644 (file)
@@ -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())
index a32acfc451c934497a111fdd26defc6f11b7d9f0..8ad01e1c5c74faacf140893887ec7d99049487c2 100644 (file)
@@ -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);
+       }
 }