]> source.dussan.org Git - jgit.git/commitdiff
Merge branch 'stable-6.6' into stable-6.7
authorMatthias Sohn <matthias.sohn@sap.com>
Wed, 21 Feb 2024 16:41:44 +0000 (17:41 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Wed, 21 Feb 2024 16:47:28 +0000 (17:47 +0100)
* stable-6.6:
  Delete org.eclipse.jgit.ssh.apache.agent/bin/.project
  Allow to discover bitmap on disk created after the packfile

Change-Id: I2bbc8c9a4ed45d37fa7ba63b2afd5511b6cf47a2

1  2 
org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackDirectory.java

index 4f1d3488446a2f500abc59132d0cf03e676e26d4,7d39b1fbcc8f437888b7bf10041feb5cc9dc45e9..333967c5e56a8c08353cce805b8194f24690bc83
@@@ -1146,51 -1129,54 +1146,64 @@@ public class Pack implements Iterable<P
                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) {