]> Kevux Git Server - rit/commitdiff
refspec: remove global tag refspec structure
authorPatrick Steinhardt <ps@pks.im>
Fri, 7 Jun 2024 06:37:57 +0000 (08:37 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Jun 2024 17:30:49 +0000 (10:30 -0700)
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>
builtin/clone.c
builtin/fetch.c
refspec.c
refspec.h

index 92ab7d7..bde1d28 100644 (file)
@@ -523,6 +523,9 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
        struct ref *head = copy_ref(find_ref_by_name(refs, "HEAD"));
        struct ref *local_refs = head;
        struct ref **tail = head ? &head->next : &local_refs;
+       struct refspec_item tag_refspec;
+
+       refspec_item_init(&tag_refspec, TAG_REFSPEC, 0);
 
        if (option_single_branch) {
                struct ref *remote_head = NULL;
@@ -545,7 +548,7 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
                                              &tail, 0);
 
                        /* if --branch=tag, pull the requested tag explicitly */
-                       get_fetch_map(remote_head, tag_refspec, &tail, 0);
+                       get_fetch_map(remote_head, &tag_refspec, &tail, 0);
                }
                free_refs(remote_head);
        } else {
@@ -555,8 +558,9 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
        }
 
        if (!option_mirror && !option_single_branch && !option_no_tags)
-               get_fetch_map(refs, tag_refspec, &tail, 0);
+               get_fetch_map(refs, &tag_refspec, &tail, 0);
 
+       refspec_item_clear(&tag_refspec);
        return local_refs;
 }
 
index 75255dc..06b6086 100644 (file)
@@ -582,11 +582,16 @@ static struct ref *get_ref_map(struct remote *remote,
                }
        }
 
-       if (tags == TAGS_SET)
+       if (tags == TAGS_SET) {
+               struct refspec_item tag_refspec;
+
                /* also fetch all tags */
-               get_fetch_map(remote_refs, tag_refspec, &tail, 0);
-       else if (tags == TAGS_DEFAULT && *autotags)
+               refspec_item_init(&tag_refspec, TAG_REFSPEC, 0);
+               get_fetch_map(remote_refs, &tag_refspec, &tail, 0);
+               refspec_item_clear(&tag_refspec);
+       } else if (tags == TAGS_DEFAULT && *autotags) {
                find_non_local_tags(remote_refs, NULL, &ref_map, &tail);
+       }
 
        /* Now append any refs to be updated opportunistically: */
        *tail = orefs;
index d60932f..1df5de6 100644 (file)
--- a/refspec.c
+++ b/refspec.c
@@ -7,19 +7,6 @@
 #include "refspec.h"
 #include "strbuf.h"
 
-static struct refspec_item s_tag_refspec = {
-       .force = 0,
-       .pattern = 1,
-       .matching = 0,
-       .exact_sha1 = 0,
-       .negative = 0,
-       .src = "refs/tags/*",
-       .dst = "refs/tags/*",
-};
-
-/* See TAG_REFSPEC for the string version */
-const struct refspec_item *tag_refspec = &s_tag_refspec;
-
 /*
  * Parses the provided refspec 'refspec' and populates the refspec_item 'item'.
  * Returns 1 if successful and 0 if the refspec is invalid.
index 8c0c446..754be45 100644 (file)
--- a/refspec.h
+++ b/refspec.h
@@ -2,7 +2,6 @@
 #define REFSPEC_H
 
 #define TAG_REFSPEC "refs/tags/*:refs/tags/*"
-extern const struct refspec_item *tag_refspec;
 
 /**
  * A struct refspec_item holds the parsed interpretation of a refspec.  If it