if (invalid || bitmapIdxFile == null) {
return null;
}
- if (bitmapIdx == null) {
- final PackBitmapIndex idx;
- try {
- idx = PackBitmapIndex.open(bitmapIdxFile, idx(),
- getReverseIdx());
- } catch (FileNotFoundException e) {
- // Once upon a time the bitmap or index files existed. Now one
- // of them has been removed. Most likely an external gc has
- // removed index, packfile or the bitmap
- bitmapIdxFile = null;
- return null;
- } catch (IOException e) {
- if (!FileUtils.isStaleFileHandleInCausalChain(e)) {
- throw e;
- }
- // Ignore NFS stale handle exception the same way as
- // FileNotFoundException above.
- bitmapIdxFile = null;
- return null;
- }
-
+ Optional<PackBitmapIndex> optional = bitmapIdx.getOptional();
+ if (optional.isPresent()) {
+ return optional.get();
+ }
+ try {
+ PackBitmapIndex idx = PackBitmapIndex.open(bitmapIdxFile, idx(),
+ getReverseIdx());
// At this point, idx() will have set packChecksum.
if (Arrays.equals(packChecksum, idx.packChecksum)) {
- bitmapIdx = idx;
- } else {
- bitmapIdxFile = null;
+ bitmapIdx = optionally(idx);
+ return idx;
+ }
+ } catch (FileNotFoundException e) {
+ // Once upon a time the bitmap or index files existed. Now one
+ // of them has been removed. Most likely an external gc has
+ // removed index, packfile or the bitmap
+ bitmapIdxFile = null;
+ return null;
+ } catch (IOException e) {
+ if (!FileUtils.isStaleFileHandleInCausalChain(e)) {
+ throw e;
}
+ // Ignore NFS stale handle exception the same way as
+ // FileNotFoundException above.
+ bitmapIdxFile = null;
+ return null;
}
- return bitmapIdx;
+ bitmapIdxFile = null;
+ return null;
}
- this.bitmapIdx = null;
+ synchronized void refreshBitmapIndex(PackFile bitmapIndexFile) {
- this.bitmapIdx = null;
++ this.bitmapIdx = Optionally.empty();
+ this.invalid = false;
+ this.bitmapIdxFile = bitmapIndexFile;
+ try {
+ getBitmapIndex();
+ } catch (IOException e) {
+ LOG.warn(JGitText.get().bitmapFailedToGet, bitmapIdxFile, e);
++ this.bitmapIdx = Optionally.empty();
+ this.bitmapIdxFile = null;
+ }
+ }
+
private synchronized PackReverseIndex getReverseIdx() throws IOException {
- if (reverseIdx == null)
- reverseIdx = new PackReverseIndex(idx());
- return reverseIdx;
+ if (invalid) {
+ throw new PackInvalidException(packFile, invalidatingCause);
+ }
+ Optional<PackReverseIndex> optional = reverseIdx.getOptional();
+ if (optional.isPresent()) {
+ return optional.get();
+ }
+ PackFile reverseIndexFile = packFile.create(REVERSE_INDEX);
+ PackReverseIndex revIdx = PackReverseIndexFactory.openOrCompute(reverseIndexFile,
+ getObjectCount(), () -> getIndex());
+ revIdx.verifyPackChecksum(getPackFile().getPath());
+ reverseIdx = optionally(revIdx);
+ return revIdx;
}
private boolean isCorrupt(long offset) {