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>
Toon Claes committed
Feb 6, 2025 at 07:33 UTC
2ca67c6f1433586e61487295bb04cc424992db12
1 file changed
+11
-16
builtin/clone.c
+11
-16
@@ -435,11 +435,8 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
435
struct ref *head = copy_ref(find_ref_by_name(refs, "HEAD"));
436
struct ref *local_refs = head;
437
struct ref **tail = local_refs ? &local_refs->next : &local_refs;
438
- struct refspec_item tag_refspec;
438
struct ref *to_free = NULL;
439
441
- refspec_item_init(&tag_refspec, TAG_REFSPEC, 0);
442
-
440
if (option_single_branch) {
441
if (!option_branch)
442
refs = to_free = guess_remote_head(head, refs, 0);
@@ -454,16 +451,7 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
451
for (size_t i = 0; i < refspec->nr; i++)
452
get_fetch_map(refs, &refspec->items[i], &tail, 0);
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
-
454
free_one_ref(to_free);
466
- refspec_item_clear(&tag_refspec);
455
456
return local_refs;
457
}
@@ -1011,8 +999,10 @@ int cmd_clone(int argc,
999
die(_("unknown ref storage format '%s'"), ref_format);
1000
}
1001
1014
- if (option_mirror)
1002
+ if (option_mirror) {
1003
option_bare = 1;
1004
+ option_tags = 0;
1005
+ }
1006
1007
if (option_bare) {
1008
if (real_git_dir)
@@ -1375,14 +1365,19 @@ int cmd_clone(int argc,
1365
transport->smart_options->check_self_contained_and_connected = 1;
1366
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
+
1376
refspec_ref_prefixes(&remote->fetch,
1377
&transport_ls_refs_options.ref_prefixes);
1378
if (option_branch)
1379
expand_ref_prefix(&transport_ls_refs_options.ref_prefixes,
1380
option_branch);
1383
- if (option_tags)
1384
- strvec_push(&transport_ls_refs_options.ref_prefixes,
1385
- "refs/tags/");
1381
1382
refs = transport_get_remote_refs(transport, &transport_ls_refs_options);
1383