aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.jgit/META-INF/SOURCE-MANIFEST.MF1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LocalObjectRepresentation.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java40
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java43
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java60
6 files changed, 141 insertions, 16 deletions
diff --git a/org.eclipse.jgit/META-INF/MANIFEST.MF b/org.eclipse.jgit/META-INF/MANIFEST.MF
index 6b25c7e6f0..79e0cc7715 100644
--- a/org.eclipse.jgit/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit/META-INF/MANIFEST.MF
@@ -7,6 +7,8 @@ Bundle-Version: 7.4.0.qualifier
Bundle-Localization: OSGI-INF/l10n/plugin
Bundle-Vendor: %Bundle-Vendor
Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: JavaSE-17
+Bundle-SCM: url=https://github.com/eclipse-jgit/jgit, connection=scm:git:https://eclipse.gerrithub.io/eclipse-jgit/jgit.git, developerConnection=scm:git:https://eclipse.gerrithub.io/a/eclipse-jgit/jgit.git
Service-Component: OSGI-INF/org.eclipse.jgit.internal.util.CleanupService.xml
Eclipse-ExtensibleAPI: true
Export-Package: org.eclipse.jgit.annotations;version="7.4.0",
@@ -244,7 +246,6 @@ Export-Package: org.eclipse.jgit.annotations;version="7.4.0",
org.eclipse.jgit.treewalk",
org.eclipse.jgit.util.sha1;version="7.4.0",
org.eclipse.jgit.util.time;version="7.4.0"
-Bundle-RequiredExecutionEnvironment: JavaSE-17
Import-Package: com.googlecode.javaewah;version="[1.1.6,2.0.0)",
javax.crypto,
javax.management,
diff --git a/org.eclipse.jgit/META-INF/SOURCE-MANIFEST.MF b/org.eclipse.jgit/META-INF/SOURCE-MANIFEST.MF
index b52bd7d908..780059761d 100644
--- a/org.eclipse.jgit/META-INF/SOURCE-MANIFEST.MF
+++ b/org.eclipse.jgit/META-INF/SOURCE-MANIFEST.MF
@@ -4,4 +4,5 @@ Bundle-Name: org.eclipse.jgit - Sources
Bundle-SymbolicName: org.eclipse.jgit.source
Bundle-Vendor: Eclipse.org - JGit
Bundle-Version: 7.4.0.qualifier
+Bundle-SCM: url=https://github.com/eclipse-jgit/jgit, connection=scm:git:https://eclipse.gerrithub.io/eclipse-jgit/jgit.git, developerConnection=scm:git:https://eclipse.gerrithub.io/a/eclipse-jgit/jgit.git
Eclipse-SourceBundle: org.eclipse.jgit;version="7.4.0.qualifier";roots="."
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 f2f54947af..8988b41b55 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
@@ -124,15 +124,16 @@ 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 volatile PackObjectSizeIndex loadedObjSizeIdx;
private volatile boolean attemptLoadObjSizeIdx;
- private Optionally<PackBitmapIndex> bitmapIdx = Optionally.empty();
+ private volatile Optionally<PackBitmapIndex> bitmapIdx = Optionally.empty();
+
/**
* Objects we have tried to read, and discovered to be corrupt.
@@ -168,7 +169,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();
@@ -420,9 +429,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();
}
/**
@@ -1290,7 +1299,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;
}
@@ -1325,7 +1342,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);
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java
index 11c45471e4..6612cfc838 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java
@@ -55,6 +55,8 @@ final class WindowCursor extends ObjectReader implements ObjectReuseAsIs {
private DeltaBaseCache baseCache;
+ private Pack lastPack;
+
@Nullable
private final ObjectInserter createdFromInserter;
@@ -147,8 +149,7 @@ final class WindowCursor extends ObjectReader implements ObjectReuseAsIs {
return db.getShallowCommits();
}
- @Override
- public long getObjectSize(AnyObjectId objectId, int typeHint)
+ private long getObjectSizeStorage(AnyObjectId objectId, int typeHint)
throws MissingObjectException, IncorrectObjectTypeException,
IOException {
long sz = db.getObjectSize(this, objectId);
@@ -162,6 +163,61 @@ final class WindowCursor extends ObjectReader implements ObjectReuseAsIs {
}
@Override
+ public long getObjectSize(AnyObjectId objectId, int typeHint)
+ throws MissingObjectException, IncorrectObjectTypeException,
+ IOException {
+ // Async queue uses hint OBJ_ANY
+ if (typeHint != Constants.OBJ_BLOB) {
+ return getObjectSizeStorage(objectId, typeHint);
+ }
+
+ Pack pack = findPack(objectId);
+ if (pack == null) {
+ // Non-packed object (e.g. loose or in alternates)
+ return getObjectSizeStorage(objectId, typeHint);
+ }
+
+ long sz = pack.getIndexedObjectSize(objectId);
+ if (sz >= 0) {
+ return sz;
+ }
+ return getObjectSizeStorage(objectId, typeHint);
+ }
+
+ @Override
+ public boolean isNotLargerThan(AnyObjectId objectId, int typeHint,
+ long size)
+ throws MissingObjectException, IncorrectObjectTypeException,
+ IOException {
+ if (typeHint != Constants.OBJ_BLOB) {
+ return getObjectSizeStorage(objectId, typeHint) <= size;
+ }
+
+ Pack pack = findPack(objectId);
+ if (pack == null || !pack.hasObjectSizeIndex()) {
+ // Non-packed object (e.g. loose or in alternates)
+ return getObjectSizeStorage(objectId, typeHint) <= size;
+ }
+
+ return pack.getIndexedObjectSize(objectId) <= size;
+ }
+
+ private Pack findPack(AnyObjectId objectId) throws IOException {
+ if (lastPack != null && lastPack.hasObject(objectId)) {
+ return lastPack;
+ }
+
+ for (Pack p : db.getPacks()) {
+ if (p.hasObject(objectId)) {
+ lastPack = p;
+ return p;
+ }
+ }
+
+ return null;
+ }
+
+ @Override
public LocalObjectToPack newObjectToPack(AnyObjectId objectId, int type) {
return new LocalObjectToPack(objectId, type);
}