Skip to content

Commit 235ac3f

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 66f892b commit 235ac3f

File tree

4 files changed

+14
-19
lines changed

4 files changed

+14
-19
lines changed

builtin/clone.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,9 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
523523
struct ref *head = copy_ref(find_ref_by_name(refs, "HEAD"));
524524
struct ref *local_refs = head;
525525
struct ref **tail = head ? &head->next : &local_refs;
526+
struct refspec_item tag_refspec;
527+
528+
refspec_item_init(&tag_refspec, TAG_REFSPEC, 0);
526529

527530
if (option_single_branch) {
528531
struct ref *remote_head = NULL;
@@ -545,7 +548,7 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
545548
&tail, 0);
546549

547550
/* 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);
549552
}
550553
free_refs(remote_head);
551554
} else {
@@ -555,8 +558,9 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
555558
}
556559

557560
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);
559562

563+
refspec_item_clear(&tag_refspec);
560564
return local_refs;
561565
}
562566

builtin/fetch.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,11 +582,16 @@ static struct ref *get_ref_map(struct remote *remote,
582582
}
583583
}
584584

585-
if (tags == TAGS_SET)
585+
if (tags == TAGS_SET) {
586+
struct refspec_item tag_refspec;
587+
586588
/* 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) {
589593
find_non_local_tags(remote_refs, NULL, &ref_map, &tail);
594+
}
590595

591596
/* Now append any refs to be updated opportunistically: */
592597
*tail = orefs;

refspec.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,6 @@
77
#include "refspec.h"
88
#include "strbuf.h"
99

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-
2310
/*
2411
* Parses the provided refspec 'refspec' and populates the refspec_item 'item'.
2512
* Returns 1 if successful and 0 if the refspec is invalid.

refspec.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#define REFSPEC_H
33

44
#define TAG_REFSPEC "refs/tags/*:refs/tags/*"
5-
extern const struct refspec_item *tag_refspec;
65
76
/**
87
* A struct refspec_item holds the parsed interpretation of a refspec. If it

0 commit comments

Comments
 (0)