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 <luca.milanesio@gmail.com>
This commit is contained in:
Luca Milanesio 2022-05-19 11:12:28 +01:00
parent f4cbf31ae4
commit 66ace4b9af
1 changed files with 9 additions and 1 deletions

View File

@ -1981,12 +1981,16 @@ private static void checkNotAdvertisedWants(UploadPack up,
throws IOException {
ObjectReader reader = up.getRevWalk().getObjectReader();
Set<ObjectId> directlyVisibleObjects = refIdSet(visibleRefs);
List<ObjectId> 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<RevObject> wantsAsObjs = objectIdsToRevObjects(walk,
notAdvertisedWants);
nonTipWants);
List<RevCommit> wantsAsCommits = wantsAsObjs.stream()
.filter(obj -> obj instanceof RevCommit)
.map(obj -> (RevCommit) obj)
@ -2046,6 +2050,10 @@ private static void checkNotAdvertisedWants(UploadPack up,
}
}
private static <T> Predicate<T> not(Predicate<T> t) {
return t.negate();
}
static Stream<Ref> importantRefsFirst(
Collection<Ref> visibleRefs) {
Predicate<Ref> startsWithRefsHeads = ref -> ref.getName()