Skip to content

Commit 937a882

Browse files
committed
partial-clone: avoid fetching when looking for objects
When using partial-clone, do_oid_object_info_extended() can trigger a fetch for missing objects. This can be extremely expensive when asking for a tag or commit, as we are completely removed from the context of the missing object and thus supply no "haves" in the request. 6462d5e (fetch: remove fetch_if_missing=0, 2019-11-05) removed a global variable that prevented these fetches in favor of a bitflag. However, some object existence checks were not updated to use this flag. Update find_non_local_tags() to use OBJECT_INFO_SKIP_FETCH_OBJECT in addition to OBJECT_INFO_QUICK. The _QUICK option only prevents repreparing the pack-file structures. We need to be extremely careful about supplying _SKIP_FETCH_OBJECT when we expect an object to not exist due to updated refs. This resolves a broken test in t5616-partial-clone.sh. Signed-off-by: Derrick Stolee <[email protected]>
1 parent dbc1bdc commit 937a882

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

builtin/fetch.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ static void find_non_local_tags(const struct ref *refs,
335335
struct string_list_item *remote_ref_item;
336336
const struct ref *ref;
337337
struct refname_hash_entry *item = NULL;
338+
const int quick_flags = OBJECT_INFO_QUICK | OBJECT_INFO_SKIP_FETCH_OBJECT;
338339

339340
refname_hash_init(&existing_refs);
340341
refname_hash_init(&remote_refs);
@@ -353,10 +354,9 @@ static void find_non_local_tags(const struct ref *refs,
353354
*/
354355
if (ends_with(ref->name, "^{}")) {
355356
if (item &&
356-
!has_object_file_with_flags(&ref->old_oid,
357-
OBJECT_INFO_QUICK) &&
357+
!has_object_file_with_flags(&ref->old_oid, quick_flags) &&
358358
!oidset_contains(&fetch_oids, &ref->old_oid) &&
359-
!has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) &&
359+
!has_object_file_with_flags(&item->oid, quick_flags) &&
360360
!oidset_contains(&fetch_oids, &item->oid))
361361
clear_item(item);
362362
item = NULL;
@@ -370,7 +370,7 @@ static void find_non_local_tags(const struct ref *refs,
370370
* fetch.
371371
*/
372372
if (item &&
373-
!has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) &&
373+
!has_object_file_with_flags(&item->oid, quick_flags) &&
374374
!oidset_contains(&fetch_oids, &item->oid))
375375
clear_item(item);
376376

@@ -391,7 +391,7 @@ static void find_non_local_tags(const struct ref *refs,
391391
* checked to see if it needs fetching.
392392
*/
393393
if (item &&
394-
!has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) &&
394+
!has_object_file_with_flags(&item->oid, quick_flags) &&
395395
!oidset_contains(&fetch_oids, &item->oid))
396396
clear_item(item);
397397

t/t5616-partial-clone.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ test_expect_failure 'verify fetch succeeds when asking for new tags' '
385385
git -C tag-test fetch --tags origin
386386
'
387387

388-
test_expect_failure 'verify fetch downloads only one pack when updating refs' '
388+
test_expect_success 'verify fetch downloads only one pack when updating refs' '
389389
git clone --filter=blob:none "file://$(pwd)/srv.bare" pack-test &&
390390
ls pack-test/.git/objects/pack/*pack >pack-list &&
391391
test_line_count = 2 pack-list &&

0 commit comments

Comments
 (0)