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 <annapapitto@google.com>
This commit is contained in:
Anna Papitto 2023-07-14 12:19:27 -07:00
parent 2eba4e5b41
commit f196c7a0e8
1 changed files with 10 additions and 2 deletions

View File

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