]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refspec: treat 'fetch' as a Boolean value
authorTaylor Blau <me@ttaylorr.com>
Tue, 18 Mar 2025 22:50:18 +0000 (18:50 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 21 Mar 2025 08:45:15 +0000 (01:45 -0700)
Since 6d4c057859 (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 <me@ttaylorr.com>
Acked-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/pull.c
refspec.c
refspec.h
remote.c
transport-helper.c

index 9c4a00620a053b375294b9895a2b402a3deed6e8..8bbfcce7295911e779274090ba24b1c125ba01e7 100644 (file)
@@ -738,7 +738,7 @@ static const char *get_tracking_branch(const char *remote, const char *refspec)
        const char *spec_src;
        const char *merge_branch;
 
-       refspec_item_init_or_die(&spec, refspec, REFSPEC_FETCH);
+       refspec_item_init_or_die(&spec, refspec, 1);
        spec_src = spec.src;
        if (!*spec_src || !strcmp(spec_src, "HEAD"))
                spec_src = "HEAD";
index c6ad515f041fed8e4fb10b4770a6a0a0629b3587..db5a1c34a5bc2b1bfa3a308a6e5c7552a53c3ae3 100644 (file)
--- a/refspec.c
+++ b/refspec.c
@@ -233,7 +233,7 @@ void refspec_clear(struct refspec *rs)
 int valid_fetch_refspec(const char *fetch_refspec_str)
 {
        struct refspec_item refspec;
-       int ret = refspec_item_init(&refspec, fetch_refspec_str, REFSPEC_FETCH);
+       int ret = refspec_item_init(&refspec, fetch_refspec_str, 1);
        refspec_item_clear(&refspec);
        return ret;
 }
@@ -249,7 +249,7 @@ void refspec_ref_prefixes(const struct refspec *rs,
                if (item->negative)
                        continue;
 
-               if (rs->fetch == REFSPEC_FETCH) {
+               if (rs->fetch) {
                        if (item->exact_sha1)
                                continue;
                        prefix = item->src;
index e2b5cc54efbdf3a652a84e4ea6173af05719702b..155494cd3ae1d012d8e56945dd408aadfc9dce23 100644 (file)
--- a/refspec.h
+++ b/refspec.h
@@ -32,11 +32,8 @@ struct refspec_item {
 
 struct string_list;
 
-#define REFSPEC_FETCH 1
-#define REFSPEC_PUSH 0
-
-#define REFSPEC_INIT_FETCH { .fetch = REFSPEC_FETCH }
-#define REFSPEC_INIT_PUSH { .fetch = REFSPEC_PUSH }
+#define REFSPEC_INIT_FETCH { .fetch = 1 }
+#define REFSPEC_INIT_PUSH { .fetch = 0 }
 
 /**
  * An array of strings can be parsed into a struct refspec using
@@ -47,7 +44,7 @@ struct refspec {
        int alloc;
        int nr;
 
-       int fetch;
+       unsigned fetch : 1;
 };
 
 int refspec_item_init(struct refspec_item *item, const char *refspec,
index e609cf5c56a77217d6316884440d6eaef5851bff..addd4a9999d8d6fe4f772324c221cde4372d7271 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -143,8 +143,8 @@ static struct remote *make_remote(struct remote_state *remote_state,
        ret->prune = -1;  /* unspecified */
        ret->prune_tags = -1;  /* unspecified */
        ret->name = xstrndup(name, len);
-       refspec_init(&ret->push, REFSPEC_PUSH);
-       refspec_init(&ret->fetch, REFSPEC_FETCH);
+       refspec_init(&ret->push, 0);
+       refspec_init(&ret->fetch, 1);
        string_list_init_dup(&ret->server_options);
 
        ALLOC_GROW(remote_state->remotes, remote_state->remotes_nr + 1,
index d457b425501a74d8837cdbb41855a205fc151b01..43cd760119fb6905004538a62ba4eb049e071c21 100644 (file)
@@ -162,7 +162,7 @@ static struct child_process *get_helper(struct transport *transport)
 
        data->helper = helper;
        data->no_disconnect_req = 0;
-       refspec_init(&data->rs, REFSPEC_FETCH);
+       refspec_init(&data->rs, 1);
 
        /*
         * Open the output as FILE* so strbuf_getline_*() family of