Skip to content

Commit 2ca67c6

Browse files
To1negitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 879780f commit 2ca67c6

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

builtin/clone.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,8 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
435435
struct ref *head = copy_ref(find_ref_by_name(refs, "HEAD"));
436436
struct ref *local_refs = head;
437437
struct ref **tail = local_refs ? &local_refs->next : &local_refs;
438-
struct refspec_item tag_refspec;
439438
struct ref *to_free = NULL;
440439

441-
refspec_item_init(&tag_refspec, TAG_REFSPEC, 0);
442-
443440
if (option_single_branch) {
444441
if (!option_branch)
445442
refs = to_free = guess_remote_head(head, refs, 0);
@@ -454,16 +451,7 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
454451
for (size_t i = 0; i < refspec->nr; i++)
455452
get_fetch_map(refs, &refspec->items[i], &tail, 0);
456453

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-
465454
free_one_ref(to_free);
466-
refspec_item_clear(&tag_refspec);
467455

468456
return local_refs;
469457
}
@@ -1011,8 +999,10 @@ int cmd_clone(int argc,
1011999
die(_("unknown ref storage format '%s'"), ref_format);
10121000
}
10131001

1014-
if (option_mirror)
1002+
if (option_mirror) {
10151003
option_bare = 1;
1004+
option_tags = 0;
1005+
}
10161006

10171007
if (option_bare) {
10181008
if (real_git_dir)
@@ -1375,14 +1365,19 @@ int cmd_clone(int argc,
13751365
transport->smart_options->check_self_contained_and_connected = 1;
13761366

13771367
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+
13781376
refspec_ref_prefixes(&remote->fetch,
13791377
&transport_ls_refs_options.ref_prefixes);
13801378
if (option_branch)
13811379
expand_ref_prefix(&transport_ls_refs_options.ref_prefixes,
13821380
option_branch);
1383-
if (option_tags)
1384-
strvec_push(&transport_ls_refs_options.ref_prefixes,
1385-
"refs/tags/");
13861381

13871382
refs = transport_get_remote_refs(transport, &transport_ls_refs_options);
13881383

0 commit comments

Comments
 (0)