diff options
6 files changed, 113 insertions, 15 deletions
diff --git a/org.eclipse.jgit.packaging/pom.xml b/org.eclipse.jgit.packaging/pom.xml index 6a37f0adf7..068712868a 100644 --- a/org.eclipse.jgit.packaging/pom.xml +++ b/org.eclipse.jgit.packaging/pom.xml @@ -189,6 +189,19 @@ </rules> </configuration> </execution> + <execution> + <id>enforce-java</id> + <goals> + <goal>enforce</goal> + </goals> + <configuration> + <rules> + <requireJavaVersion> + <version>17</version> + </requireJavaVersion> + </rules> + </configuration> + </execution> </executions> </plugin> <plugin> diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileReftableDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileReftableDatabase.java index 559d5a4339..64f8c9b0e3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileReftableDatabase.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileReftableDatabase.java @@ -264,8 +264,14 @@ public class FileReftableDatabase extends RefDatabase { public void refresh() { try { if (!reftableStack.isUpToDate()) { - reftableDatabase.clearCache(); - reftableStack.reload(); + ReentrantLock lock = getLock(); + lock.lock(); + try { + reftableDatabase.clearCache(); + reftableStack.reload(); + } finally { + lock.unlock(); + } } } catch (IOException e) { throw new UncheckedIOException(e); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LocalObjectRepresentation.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LocalObjectRepresentation.java index 3f3d78c734..af571622b4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LocalObjectRepresentation.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LocalObjectRepresentation.java @@ -22,6 +22,11 @@ class LocalObjectRepresentation extends StoredObjectRepresentation { public int getFormat() { return PACK_WHOLE; } + + @Override + public boolean wasDeltaAttempted() { + return true; + } }; r.pack = pack; r.offset = offset; @@ -81,5 +86,10 @@ class LocalObjectRepresentation extends StoredObjectRepresentation { public int getFormat() { return PACK_DELTA; } + + @Override + public boolean wasDeltaAttempted() { + return true; + } } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java index 3a6de4e8e2..dc25bfde40 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java @@ -70,6 +70,11 @@ import org.eclipse.jgit.util.FileUtils; * considered. */ public class ObjectDirectory extends FileObjectDatabase { + @FunctionalInterface + private interface TriFunctionThrowsException<A, A2, A3, R, E extends Exception> { + R apply(A a, A2 a2, A3 a3) throws E; + } + /** Maximum number of candidates offered as resolutions of abbreviation. */ private static final int RESOLVE_ABBREV_LIMIT = 256; @@ -348,9 +353,13 @@ public class ObjectDirectory extends FileObjectDatabase { @Override ObjectLoader openObject(WindowCursor curs, AnyObjectId objectId) throws IOException { - ObjectLoader ldr = openObjectWithoutRestoring(curs, objectId); - if (ldr == null && restoreFromSelfOrAlternate(objectId, null)) { + ObjectLoader ldr = getFromLocalObjectToPack(curs, objectId, + (p, c, l) -> p.load(c, l.offset)); + if (ldr == null) { ldr = openObjectWithoutRestoring(curs, objectId); + if (ldr == null && restoreFromSelfOrAlternate(objectId, null)) { + ldr = openObjectWithoutRestoring(curs, objectId); + } } return ldr; } @@ -419,11 +428,16 @@ public class ObjectDirectory extends FileObjectDatabase { return loose.open(curs, id); } + @SuppressWarnings("boxing") @Override long getObjectSize(WindowCursor curs, AnyObjectId id) throws IOException { - long sz = getObjectSizeWithoutRestoring(curs, id); - if (0 > sz && restoreFromSelfOrAlternate(id, null)) { + Long sz = getFromLocalObjectToPack(curs, id, + (p, c, l) -> p.getObjectSize(c, l)); + if (sz == null) { sz = getObjectSizeWithoutRestoring(curs, id); + if (sz < 0 && restoreFromSelfOrAlternate(id, null)) { + sz = getObjectSizeWithoutRestoring(curs, id); + } } return sz; } @@ -480,6 +494,24 @@ public class ObjectDirectory extends FileObjectDatabase { return -1; } + private <R> R getFromLocalObjectToPack(WindowCursor curs, + AnyObjectId objectId, + TriFunctionThrowsException<Pack, WindowCursor, LocalObjectToPack, R, IOException> func) { + if (objectId instanceof LocalObjectToPack) { + LocalObjectToPack lotp = (LocalObjectToPack) objectId; + Pack pack = lotp.pack; + if (pack != null) { + try { + return func.apply(pack, curs, lotp); + } catch (IOException e) { + // lotp potentially repacked, continue as if lotp not + // provided + } + } + } + return null; + } + @Override void selectObjectRepresentation(PackWriter packer, ObjectToPack otp, WindowCursor curs) throws IOException { 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 5813d39e9a..bf574ec4c2 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 @@ -122,11 +122,11 @@ public class Pack implements Iterable<PackIndex.MutableEntry> { private byte[] packChecksum; - private Optionally<PackIndex> loadedIdx = Optionally.empty(); + private volatile Optionally<PackIndex> loadedIdx = Optionally.empty(); - private Optionally<PackReverseIndex> reverseIdx = Optionally.empty(); + private volatile Optionally<PackReverseIndex> reverseIdx = Optionally.empty(); - private Optionally<PackBitmapIndex> bitmapIdx = Optionally.empty(); + private volatile Optionally<PackBitmapIndex> bitmapIdx = Optionally.empty(); /** * Objects we have tried to read, and discovered to be corrupt. @@ -162,7 +162,15 @@ public class Pack implements Iterable<PackIndex.MutableEntry> { length = Long.MAX_VALUE; } - private synchronized PackIndex idx() throws IOException { + private PackIndex idx() throws IOException { + Optional<PackIndex> optional = loadedIdx.getOptional(); + if (optional.isPresent()) { + return optional.get(); + } + return memoizeIdxIfNeeded(); + } + + private synchronized PackIndex memoizeIdxIfNeeded() throws IOException { Optional<PackIndex> optional = loadedIdx.getOptional(); if (optional.isPresent()) { return optional.get(); @@ -312,9 +320,9 @@ public class Pack implements Iterable<PackIndex.MutableEntry> { } private synchronized void closeIndices() { - loadedIdx.clear(); - reverseIdx.clear(); - bitmapIdx.clear(); + loadedIdx = Optionally.empty(); + reverseIdx = Optionally.empty(); + bitmapIdx = Optionally.empty(); } /** @@ -1182,7 +1190,15 @@ public class Pack implements Iterable<PackIndex.MutableEntry> { return getReverseIdx().findNextOffset(startOffset, maxOffset); } - synchronized PackBitmapIndex getBitmapIndex() throws IOException { + PackBitmapIndex getBitmapIndex() throws IOException { + Optional<PackBitmapIndex> optional = bitmapIdx.getOptional(); + if (optional.isPresent()) { + return optional.get(); + } + return memoizeBitmapIndexIfNeeded(); + } + + private synchronized PackBitmapIndex memoizeBitmapIndexIfNeeded() throws IOException { if (invalid || bitmapIdxFile == null) { return null; } @@ -1217,7 +1233,15 @@ public class Pack implements Iterable<PackIndex.MutableEntry> { this.bitmapIdxFile = bitmapIndexFile; } - private synchronized PackReverseIndex getReverseIdx() throws IOException { + private PackReverseIndex getReverseIdx() throws IOException { + Optional<PackReverseIndex> optional = reverseIdx.getOptional(); + if (optional.isPresent()) { + return optional.get(); + } + return memoizeReverseIdxIfNeeded(); + } + + private synchronized PackReverseIndex memoizeReverseIdxIfNeeded() throws IOException { if (invalid) { throw new PackInvalidException(packFile, invalidatingCause); } @@ -404,6 +404,19 @@ </rules> </configuration> </execution> + <execution> + <id>enforce-java</id> + <goals> + <goal>enforce</goal> + </goals> + <configuration> + <rules> + <requireJavaVersion> + <version>17</version> + </requireJavaVersion> + </rules> + </configuration> + </execution> </executions> </plugin> |