Skip to content

Commit 77aa094

Browse files
jonathantanmygitster
authored andcommitted
upload-pack: do not lazy-fetch "have" objects
When upload-pack receives a request containing "have" hashes, it (among other things) checks if the served repository has the corresponding objects. However, it does not do so with the OBJECT_INFO_SKIP_FETCH_OBJECT flag, so if serving a partial clone, a lazy fetch will be triggered first. This was discovered at $DAYJOB when a user fetched from a partial clone (into another partial clone - although this would also happen if the repo to be fetched into is not a partial clone). Therefore, whenever "have" hashes are checked for existence, pass the OBJECT_INFO_SKIP_FETCH_OBJECT flag. Also add the OBJECT_INFO_QUICK flag to improve performance, as it is typical that such objects do not exist in the serving repo, and the consequences of a false negative are minor (usually, a slightly larger pack sent). Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bd42bbe commit 77aa094

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

t/t5616-partial-clone.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,44 @@ test_expect_success 'single-branch tag following respects partial clone' '
422422
test_must_fail git -C single rev-parse --verify refs/tags/C
423423
'
424424

425+
test_expect_success 'fetch from a partial clone, protocol v0' '
426+
rm -rf server client trace &&
427+
428+
# Pretend that the server is a partial clone
429+
git init server &&
430+
git -C server remote add a_remote "file://$(pwd)/" &&
431+
test_config -C server core.repositoryformatversion 1 &&
432+
test_config -C server extensions.partialclone a_remote &&
433+
test_config -C server protocol.version 0 &&
434+
test_commit -C server foo &&
435+
436+
# Fetch from the server
437+
git init client &&
438+
test_config -C client protocol.version 0 &&
439+
test_commit -C client bar &&
440+
GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "file://$(pwd)/server" &&
441+
! grep "version 2" trace
442+
'
443+
444+
test_expect_success 'fetch from a partial clone, protocol v2' '
445+
rm -rf server client trace &&
446+
447+
# Pretend that the server is a partial clone
448+
git init server &&
449+
git -C server remote add a_remote "file://$(pwd)/" &&
450+
test_config -C server core.repositoryformatversion 1 &&
451+
test_config -C server extensions.partialclone a_remote &&
452+
test_config -C server protocol.version 2 &&
453+
test_commit -C server foo &&
454+
455+
# Fetch from the server
456+
git init client &&
457+
test_config -C client protocol.version 2 &&
458+
test_commit -C client bar &&
459+
GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "file://$(pwd)/server" &&
460+
grep "version 2" trace
461+
'
462+
425463
. "$TEST_DIRECTORY"/lib-httpd.sh
426464
start_httpd
427465

upload-pack.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,8 @@ static int got_oid(struct upload_pack_data *data,
482482
{
483483
if (get_oid_hex(hex, oid))
484484
die("git upload-pack: expected SHA1 object, got '%s'", hex);
485-
if (!has_object_file(oid))
485+
if (!has_object_file_with_flags(oid,
486+
OBJECT_INFO_QUICK | OBJECT_INFO_SKIP_FETCH_OBJECT))
486487
return -1;
487488
return do_got_oid(data, oid);
488489
}
@@ -1423,7 +1424,8 @@ static int process_haves(struct upload_pack_data *data, struct oid_array *common
14231424
for (i = 0; i < data->haves.nr; i++) {
14241425
const struct object_id *oid = &data->haves.oid[i];
14251426

1426-
if (!has_object_file(oid))
1427+
if (!has_object_file_with_flags(oid,
1428+
OBJECT_INFO_QUICK | OBJECT_INFO_SKIP_FETCH_OBJECT))
14271429
continue;
14281430

14291431
oid_array_append(common, oid);

0 commit comments

Comments
 (0)