From f196c7a0e838becff12d9a3ea922398cf8c9d3be Mon Sep 17 00:00:00 2001 From: Anna Papitto Date: Fri, 14 Jul 2023 12:19:27 -0700 Subject: [PATCH] Pack: open reverse index from file if present 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 --- .../org/eclipse/jgit/internal/storage/file/Pack.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java index 8d9fe23ae..2b5586a2c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java @@ -14,6 +14,7 @@ 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 @@ synchronized PackBitmapIndex getBitmapIndex() throws IOException { } 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; }