From: Taylor Blau Date: Tue, 18 Mar 2025 22:50:21 +0000 (-0400) Subject: refspec: replace `refspec_init()` with fetch/push variants X-Git-Tag: v2.50.0-rc0~139^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0baad1f3aee508d84bf74b9670f283f8c91e55dd;p=thirdparty%2Fgit.git refspec: replace `refspec_init()` with fetch/push variants To avoid having a Boolean argument in the refspec_init() function, replace it with two variants: - `refspec_init_fetch()` - `refspec_init_push()` to codify the meaning of that Boolean into the function's name itself. Signed-off-by: Taylor Blau Acked-by: Elijah Newren Signed-off-by: Junio C Hamano --- diff --git a/refspec.c b/refspec.c index db5a1c34a5..f6be0c54d7 100644 --- a/refspec.c +++ b/refspec.c @@ -178,10 +178,16 @@ void refspec_item_clear(struct refspec_item *item) item->exact_sha1 = 0; } -void refspec_init(struct refspec *rs, int fetch) +void refspec_init_fetch(struct refspec *rs) { - memset(rs, 0, sizeof(*rs)); - rs->fetch = fetch; + struct refspec blank = REFSPEC_INIT_FETCH; + memcpy(rs, &blank, sizeof(*rs)); +} + +void refspec_init_push(struct refspec *rs) +{ + struct refspec blank = REFSPEC_INIT_PUSH; + memcpy(rs, &blank, sizeof(*rs)); } void refspec_append(struct refspec *rs, const char *refspec) diff --git a/refspec.h b/refspec.h index 155494cd3a..7db68e56c8 100644 --- a/refspec.h +++ b/refspec.h @@ -52,7 +52,8 @@ int refspec_item_init(struct refspec_item *item, const char *refspec, void refspec_item_init_or_die(struct refspec_item *item, const char *refspec, int fetch); void refspec_item_clear(struct refspec_item *item); -void refspec_init(struct refspec *rs, int fetch); +void refspec_init_fetch(struct refspec *rs); +void refspec_init_push(struct refspec *rs); void refspec_append(struct refspec *rs, const char *refspec); __attribute__((format (printf,2,3))) void refspec_appendf(struct refspec *rs, const char *fmt, ...); diff --git a/remote.c b/remote.c index addd4a9999..25af97a44b 100644 --- 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, 0); - refspec_init(&ret->fetch, 1); + refspec_init_push(&ret->push); + refspec_init_fetch(&ret->fetch); string_list_init_dup(&ret->server_options); ALLOC_GROW(remote_state->remotes, remote_state->remotes_nr + 1, diff --git a/transport-helper.c b/transport-helper.c index 43cd760119..69391ee7d2 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -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, 1); + refspec_init_fetch(&data->rs); /* * Open the output as FILE* so strbuf_getline_*() family of