Skip to content

Commit 37f382a

Browse files
committed
Merge branch 'jt/avoid-lazy-fetching-upon-have-check' into master
Fetching from a lazily cloned repository resulted at the server side in attempts to lazy fetch objects that the client side has, many of which will not be available from the third-party anyway. * jt/avoid-lazy-fetching-upon-have-check: upload-pack: do not lazy-fetch "have" objects
2 parents e163cff + 77aa094 commit 37f382a

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)