diff options
author | Martin Fick <mfick@nvidia.com> | 2025-07-23 16:51:43 -0700 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2025-07-30 11:22:20 +0200 |
commit | 0efc9c36711f25434308ef428cb7c8954dbf4ec6 (patch) | |
tree | b33fa67ccc5b5964ab2d4d7381c11785e9eb32d9 | |
parent | d9aba160b47607f12341f9f5021dc5f24c12ea56 (diff) | |
download | jgit-0efc9c36711f25434308ef428cb7c8954dbf4ec6.tar.gz jgit-0efc9c36711f25434308ef428cb7c8954dbf4ec6.zip |
Use LocalObjectToPack representation more
Use LOTP to also get size in ObjectDirectory. This path is use when
searching for deltas, however I cannot find an obvious testable
improvement for this. I suspect that this would do best on a fetch with
very few reuseable deltas.
Change-Id: Ifae154332e3599f77fd9c9bdcf7e1ad3f5055398
Signed-off-by: Martin Fick <mfick@nvidia.com>
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java | 51 |
1 files changed, 36 insertions, 15 deletions
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 b91e4d34d0..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,20 +353,13 @@ public class ObjectDirectory extends FileObjectDatabase { @Override ObjectLoader openObject(WindowCursor curs, AnyObjectId objectId) throws IOException { - if (objectId instanceof LocalObjectToPack) { - LocalObjectToPack lotp = (LocalObjectToPack) objectId; - Pack pack = lotp.pack; - if (pack != null) { - try { - return pack.load(curs, lotp.offset); - } catch (IOException e) { - // lotp potentially repacked, continue as if lotp not provided - } - } - } - 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; } @@ -430,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; } @@ -491,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 { |