From 3809633d0adb77b02ba8cfe87578134e6a30f54d Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Tue, 18 Mar 2025 18:50:18 -0400 Subject: refspec: treat 'fetch' as a Boolean value 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 Acked-by: Elijah Newren Signed-off-by: Junio C Hamano --- refspec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'refspec.c') diff --git a/refspec.c b/refspec.c index c6ad515f04..db5a1c34a5 100644 --- 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; -- cgit v1.2.3