Git fork

clone: add tags refspec earlier to fetch refspec

In clone.c we call refspec_ref_prefixes() to copy the fetch refspecs
from the `remote->fetch` refspec into `ref_prefixes` of
`transport_ls_refs_options`. Afterwards we add the tags prefix
`refs/tags/` prefix as well. At a later point, in wanted_peer_refs() we
process refs using both `remote->fetch` and `TAG_REFSPEC`.

Simplify the code by appending `TAG_REFSPEC` to `remote->fetch` before
calling refspec_ref_prefixes().

To be able to do this, we set `option_tags` to 0 when --mirror is given.
This is because --mirror mirrors (hence the name) all the refs,
including tags and they do not need to be treated separately.

Signed-off-by: Toon Claes <toon@iotcl.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Toon Claes and committed by
Junio C Hamano
2ca67c6f 879780f9

+11 -16
+11 -16
builtin/clone.c
··· 435 435 struct ref *head = copy_ref(find_ref_by_name(refs, "HEAD")); 436 436 struct ref *local_refs = head; 437 437 struct ref **tail = local_refs ? &local_refs->next : &local_refs; 438 - struct refspec_item tag_refspec; 439 438 struct ref *to_free = NULL; 440 - 441 - refspec_item_init(&tag_refspec, TAG_REFSPEC, 0); 442 439 443 440 if (option_single_branch) { 444 441 if (!option_branch) ··· 454 451 for (size_t i = 0; i < refspec->nr; i++) 455 452 get_fetch_map(refs, &refspec->items[i], &tail, 0); 456 453 457 - /* 458 - * Grab all refs that match the TAG_REFSPEC. Any tags we don't care 459 - * about won't be present in `refs` anyway. 460 - * Except with option --mirror, where we grab all refs already. 461 - */ 462 - if (!option_mirror) 463 - get_fetch_map(refs, &tag_refspec, &tail, 0); 464 - 465 454 free_one_ref(to_free); 466 - refspec_item_clear(&tag_refspec); 467 455 468 456 return local_refs; 469 457 } ··· 1011 999 die(_("unknown ref storage format '%s'"), ref_format); 1012 1000 } 1013 1001 1014 - if (option_mirror) 1002 + if (option_mirror) { 1015 1003 option_bare = 1; 1004 + option_tags = 0; 1005 + } 1016 1006 1017 1007 if (option_bare) { 1018 1008 if (real_git_dir) ··· 1375 1365 transport->smart_options->check_self_contained_and_connected = 1; 1376 1366 1377 1367 strvec_push(&transport_ls_refs_options.ref_prefixes, "HEAD"); 1368 + 1369 + if (option_tags || option_branch) 1370 + /* 1371 + * Add tags refspec when user asked for tags (implicitly) or 1372 + * specified --branch, whose argument might be a tag. 1373 + */ 1374 + refspec_append(&remote->fetch, TAG_REFSPEC); 1375 + 1378 1376 refspec_ref_prefixes(&remote->fetch, 1379 1377 &transport_ls_refs_options.ref_prefixes); 1380 1378 if (option_branch) 1381 1379 expand_ref_prefix(&transport_ls_refs_options.ref_prefixes, 1382 1380 option_branch); 1383 - if (option_tags) 1384 - strvec_push(&transport_ls_refs_options.ref_prefixes, 1385 - "refs/tags/"); 1386 1381 1387 1382 refs = transport_get_remote_refs(transport, &transport_ls_refs_options); 1388 1383