]> source.dussan.org Git - jgit.git/commitdiff
Pack: open reverse index from file if present 95/203195/3
authorAnna Papitto <annapapitto@google.com>
Fri, 14 Jul 2023 19:19:27 +0000 (12:19 -0700)
committerAnna Papitto <annapapitto@google.com>
Tue, 18 Jul 2023 22:19:26 +0000 (15:19 -0700)
The reverse index for a pack is still always computed if needed, which
is slower than parsing it from a file.

Supply the file path where the reverse index file might be so that it
parsed instead of computed if the file is present.

Change-Id: I8c60d970fd587341dfb2763fb87f1c586279f2a5
Signed-off-by: Anna Papitto <annapapitto@google.com>
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java

index 8d9fe23ae567116c39d3bff157df09a503f38a83..2b5586a2ceb35f944cc22cb00e37fd46e33402c3 100644 (file)
@@ -14,6 +14,7 @@ package org.eclipse.jgit.internal.storage.file;
 
 import static org.eclipse.jgit.internal.storage.pack.PackExt.INDEX;
 import static org.eclipse.jgit.internal.storage.pack.PackExt.KEEP;
+import static org.eclipse.jgit.internal.storage.pack.PackExt.REVERSE_INDEX;
 
 import java.io.EOFException;
 import java.io.File;
@@ -1150,8 +1151,15 @@ public class Pack implements Iterable<PackIndex.MutableEntry> {
        }
 
        private synchronized PackReverseIndex getReverseIdx() throws IOException {
-               if (reverseIdx == null)
-                       reverseIdx = PackReverseIndexFactory.computeFromIndex(idx());
+               if (invalid) {
+                       throw new PackInvalidException(packFile, invalidatingCause);
+               }
+               if (reverseIdx == null) {
+                       PackFile reverseIndexFile = packFile.create(REVERSE_INDEX);
+                       reverseIdx = PackReverseIndexFactory.openOrCompute(reverseIndexFile,
+                                       getObjectCount(), () -> getIndex());
+                       reverseIdx.verifyPackChecksum(getPackFile().getPath());
+               }
                return reverseIdx;
        }