diff options
author | Luca Milanesio <luca.milanesio@gmail.com> | 2024-01-10 19:38:46 +0000 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2024-02-20 22:54:54 +0100 |
commit | 3e624306dea4de6f7a78a7bcf34a57882f731a2d (patch) | |
tree | 73cb3406d8d5eb70c1c75be65f47dae2ce2ef0d0 /org.eclipse.jgit/src | |
parent | acf21c0bc6a63a3d20fca92757b992a1f2d55f41 (diff) | |
download | jgit-3e624306dea4de6f7a78a7bcf34a57882f731a2d.tar.gz jgit-3e624306dea4de6f7a78a7bcf34a57882f731a2d.zip |
Allow to discover bitmap on disk created after the packfile
When the bitmap file was created *after* a packfile had been
loaded into the memory, JGit was unable to discover them.
That happed because of two problems:
1. The PackDirectory.getPacks() does not implement the usual
while loop that is scanning through the packs directory
as in the other parts of JGit.
2. The scan packs does not look for newly created bitmap files
if the packfile is already loaded in memory.
Implement the normal packfiles scanning whenever the PackDirectory
needs to return a list of packs, and make sure that any reused
Pack object would have its associated bitmap properly refreshed
from disk.
Adapt the assertions in GcConcurrentTest with the rescanned list
of Pack from the objects/packs directory.
Bug: jgit-15
Change-Id: I2ed576cefd78a0e128b175228a59c9af51523d7b
Diffstat (limited to 'org.eclipse.jgit/src')
3 files changed, 29 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java index c7cad43d96..1d5a2e1f6b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java @@ -93,6 +93,8 @@ public class JGitText extends TranslationBundle { /***/ public String binaryHunkInvalidLength; /***/ public String binaryHunkLineTooShort; /***/ public String binaryHunkMissingNewline; + /***/ public String bitmapAccessErrorForPackfile; + /***/ public String bitmapFailedToGet; /***/ public String bitmapMissingObject; /***/ public String bitmapsMustBePrepared; /***/ public String blameNotCommittedYet; 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 d6c25b2587..7d39b1fbcc 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 @@ -1160,6 +1160,19 @@ public class Pack implements Iterable<PackIndex.MutableEntry> { return bitmapIdx; } + synchronized void refreshBitmapIndex(PackFile bitmapIndexFile) { + this.bitmapIdx = null; + this.invalid = false; + this.bitmapIdxFile = bitmapIndexFile; + try { + getBitmapIndex(); + } catch (IOException e) { + LOG.warn(JGitText.get().bitmapFailedToGet, bitmapIdxFile, e); + this.bitmapIdx = null; + this.bitmapIdxFile = null; + } + } + private synchronized PackReverseIndex getReverseIdx() throws IOException { if (reverseIdx == null) reverseIdx = new PackReverseIndex(idx()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackDirectory.java index 6a99cb3d83..1676d8bc18 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackDirectory.java @@ -115,10 +115,13 @@ class PackDirectory { } Collection<Pack> getPacks() { - PackList list = packList.get(); - if (list == NO_PACKS) { - list = scanPacks(list); - } + PackList list; + do { + list = packList.get(); + if (list == NO_PACKS) { + list = scanPacks(list); + } + } while (searchPacksAgain(list)); Pack[] packs = list.packs; return Collections.unmodifiableCollection(Arrays.asList(packs)); } @@ -455,6 +458,13 @@ class PackDirectory { && !oldPack.getFileSnapshot().isModified(packFile)) { forReuse.remove(packFile.getName()); list.add(oldPack); + try { + if(oldPack.getBitmapIndex() == null) { + oldPack.refreshBitmapIndex(packFilesByExt.get(BITMAP_INDEX)); + } + } catch (IOException e) { + LOG.warn(JGitText.get().bitmapAccessErrorForPackfile, oldPack.getPackName(), e); + } continue; } |