refspec: remove global tag refspec structure
We have a global tag refspec structure that is used by both git-clone(1) and git-fetch(1). Initialization of the structure will break once we enable `-Wwrite-strings`, even though the breakage is harmless. While we could just add casts, the structure isn't really required in the first place as we can simply initialize the structures at the respective callsites. Refactor the code accordingly. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Jun 7, 2024 at 08:37 UTC
235ac3f81ad1950f2e6b47b30561eb96844e1c85
4 files changed
+14
-19
builtin/clone.c
+6
-2
@@ -523,6 +523,9 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
523
struct ref *head = copy_ref(find_ref_by_name(refs, "HEAD"));
524
struct ref *local_refs = head;
525
struct ref **tail = head ? &head->next : &local_refs;
526
+ struct refspec_item tag_refspec;
527
+
528
+ refspec_item_init(&tag_refspec, TAG_REFSPEC, 0);
529
530
if (option_single_branch) {
531
struct ref *remote_head = NULL;
@@ -545,7 +548,7 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
548
&tail, 0);
549
550
/* if --branch=tag, pull the requested tag explicitly */
548
- get_fetch_map(remote_head, tag_refspec, &tail, 0);
551
+ get_fetch_map(remote_head, &tag_refspec, &tail, 0);
552
}
553
free_refs(remote_head);
554
} else {
@@ -555,8 +558,9 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
558
}
559
560
if (!option_mirror && !option_single_branch && !option_no_tags)
558
- get_fetch_map(refs, tag_refspec, &tail, 0);
561
+ get_fetch_map(refs, &tag_refspec, &tail, 0);
562
563
+ refspec_item_clear(&tag_refspec);
564
return local_refs;
565
}
566
builtin/fetch.c
+8
-3
@@ -582,11 +582,16 @@ static struct ref *get_ref_map(struct remote *remote,
582
}
583
}
584
585
- if (tags == TAGS_SET)
585
+ if (tags == TAGS_SET) {
586
+ struct refspec_item tag_refspec;
587
+
588
/* also fetch all tags */
587
- get_fetch_map(remote_refs, tag_refspec, &tail, 0);
588
- else if (tags == TAGS_DEFAULT && *autotags)
589
+ refspec_item_init(&tag_refspec, TAG_REFSPEC, 0);
590
+ get_fetch_map(remote_refs, &tag_refspec, &tail, 0);
591
+ refspec_item_clear(&tag_refspec);
592
+ } else if (tags == TAGS_DEFAULT && *autotags) {
593
find_non_local_tags(remote_refs, NULL, &ref_map, &tail);
594
+ }
595
596
/* Now append any refs to be updated opportunistically: */
597
*tail = orefs;
refspec.c
-13
@@ -7,19 +7,6 @@
7
#include "refspec.h"
8
#include "strbuf.h"
9
10
-static struct refspec_item s_tag_refspec = {
11
- .force = 0,
12
- .pattern = 1,
13
- .matching = 0,
14
- .exact_sha1 = 0,
15
- .negative = 0,
16
- .src = "refs/tags/*",
17
- .dst = "refs/tags/*",
18
-};
19
-
20
-/* See TAG_REFSPEC for the string version */
21
-const struct refspec_item *tag_refspec = &s_tag_refspec;
22
-
10
/*
11
* Parses the provided refspec 'refspec' and populates the refspec_item 'item'.
12
* Returns 1 if successful and 0 if the refspec is invalid.
refspec.h
-1
@@ -2,7 +2,6 @@
2
#define REFSPEC_H
3
4
#define TAG_REFSPEC "refs/tags/*:refs/tags/*"
5
-extern const struct refspec_item *tag_refspec;
5
6
/**
7
* A struct refspec_item holds the parsed interpretation of a refspec. If it