Skip to content

Commit 3809633

Browse files
ttaylorrgitster
authored andcommitted
refspec: treat 'fetch' as a Boolean value
Since 6d4c057 (refspec: introduce struct refspec, 2018-05-16), we have macros called REFSPEC_FETCH and REFSPEC_PUSH. This confusingly suggests that we might introduce other modes in the future, which, while possible, is highly unlikely. But these values are treated as a Boolean, and stored in a struct field called 'fetch'. So the following: if (refspec->fetch == REFSPEC_FETCH) { ... } , and if (refspec->fetch) { ... } are equivalent. Let's avoid renaming the Boolean values "true" and "false" here and remove the two REFSPEC_ macros mentioned above. Since this value is truly a Boolean and will only ever take on a value of 0 or 1, we can declare it as a single bit unsigned field. In practice this won't shrink the size of 'struct refspec', but it more clearly indicates the intent. Note that this introduces some awkwardness like: refspec_item_init_or_die(&spec, refspec, 1); , where it's unclear what the final "1" does. This will be addressed in the following commits. Signed-off-by: Taylor Blau <[email protected]> Acked-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f543202 commit 3809633

File tree

5 files changed

+9
-12
lines changed

5 files changed

+9
-12
lines changed

builtin/pull.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ static const char *get_tracking_branch(const char *remote, const char *refspec)
738738
const char *spec_src;
739739
const char *merge_branch;
740740

741-
refspec_item_init_or_die(&spec, refspec, REFSPEC_FETCH);
741+
refspec_item_init_or_die(&spec, refspec, 1);
742742
spec_src = spec.src;
743743
if (!*spec_src || !strcmp(spec_src, "HEAD"))
744744
spec_src = "HEAD";

refspec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ void refspec_clear(struct refspec *rs)
233233
int valid_fetch_refspec(const char *fetch_refspec_str)
234234
{
235235
struct refspec_item refspec;
236-
int ret = refspec_item_init(&refspec, fetch_refspec_str, REFSPEC_FETCH);
236+
int ret = refspec_item_init(&refspec, fetch_refspec_str, 1);
237237
refspec_item_clear(&refspec);
238238
return ret;
239239
}
@@ -249,7 +249,7 @@ void refspec_ref_prefixes(const struct refspec *rs,
249249
if (item->negative)
250250
continue;
251251

252-
if (rs->fetch == REFSPEC_FETCH) {
252+
if (rs->fetch) {
253253
if (item->exact_sha1)
254254
continue;
255255
prefix = item->src;

refspec.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ struct refspec_item {
3232

3333
struct string_list;
3434

35-
#define REFSPEC_FETCH 1
36-
#define REFSPEC_PUSH 0
37-
38-
#define REFSPEC_INIT_FETCH { .fetch = REFSPEC_FETCH }
39-
#define REFSPEC_INIT_PUSH { .fetch = REFSPEC_PUSH }
35+
#define REFSPEC_INIT_FETCH { .fetch = 1 }
36+
#define REFSPEC_INIT_PUSH { .fetch = 0 }
4037

4138
/**
4239
* An array of strings can be parsed into a struct refspec using
@@ -47,7 +44,7 @@ struct refspec {
4744
int alloc;
4845
int nr;
4946

50-
int fetch;
47+
unsigned fetch : 1;
5148
};
5249

5350
int refspec_item_init(struct refspec_item *item, const char *refspec,

remote.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ static struct remote *make_remote(struct remote_state *remote_state,
143143
ret->prune = -1; /* unspecified */
144144
ret->prune_tags = -1; /* unspecified */
145145
ret->name = xstrndup(name, len);
146-
refspec_init(&ret->push, REFSPEC_PUSH);
147-
refspec_init(&ret->fetch, REFSPEC_FETCH);
146+
refspec_init(&ret->push, 0);
147+
refspec_init(&ret->fetch, 1);
148148
string_list_init_dup(&ret->server_options);
149149

150150
ALLOC_GROW(remote_state->remotes, remote_state->remotes_nr + 1,

transport-helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static struct child_process *get_helper(struct transport *transport)
162162

163163
data->helper = helper;
164164
data->no_disconnect_req = 0;
165-
refspec_init(&data->rs, REFSPEC_FETCH);
165+
refspec_init(&data->rs, 1);
166166

167167
/*
168168
* Open the output as FILE* so strbuf_getline_*() family of

0 commit comments

Comments
 (0)