From 66ace4b9af137466a4dd6187a11e473351c306a8 Mon Sep 17 00:00:00 2001 From: Luca Milanesio Date: Thu, 19 May 2022 11:12:28 +0100 Subject: [PATCH] UploadPack: do not check reachability of visible SHA1s When JGit needs to serve a Git client requesting SHA1s during the want phase, it needs to make a full reachability check from the advertised refs to the ones requested to keep all objects in the correct scope of confidentiality allowed by the avertised refs. The check is also performed when the SHA1 corresponds to one of the tips of the advertised refs which is a waste of resources. Example: fetch> ref-prefix refs/heads/foo fetch< 900505eb8ce8ced2a1757906da1b25c357b9654e refs/heads/foo fetch< 0000 fetch> command=fetch fetch> 0001 fetch> thin-pack fetch> ofs-delta fetch> want 900505eb8ce8ced2a1757906da1b25c357b9654e The SHA1 in the want is the tip of refs/heads/foo and therefore the full reachability check can be shortened and resolved more quickly. Change-Id: I49bd9e2464e0bd3bca2abf14c6e9df550d07383b Signed-off-by: Luca Milanesio --- .../src/org/eclipse/jgit/transport/UploadPack.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java index 9080f51d7..c389ce44f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -1981,12 +1981,16 @@ private static void checkNotAdvertisedWants(UploadPack up, throws IOException { ObjectReader reader = up.getRevWalk().getObjectReader(); + Set directlyVisibleObjects = refIdSet(visibleRefs); + List nonTipWants = notAdvertisedWants.stream() + .filter(not(directlyVisibleObjects::contains)) + .collect(Collectors.toList()); try (RevWalk walk = new RevWalk(reader)) { walk.setRetainBody(false); // Missing "wants" throw exception here List wantsAsObjs = objectIdsToRevObjects(walk, - notAdvertisedWants); + nonTipWants); List wantsAsCommits = wantsAsObjs.stream() .filter(obj -> obj instanceof RevCommit) .map(obj -> (RevCommit) obj) @@ -2046,6 +2050,10 @@ private static void checkNotAdvertisedWants(UploadPack up, } } + private static Predicate not(Predicate t) { + return t.negate(); + } + static Stream importantRefsFirst( Collection visibleRefs) { Predicate startsWithRefsHeads = ref -> ref.getName()