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 <me@ttaylorr.com> Acked-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Taylor Blau committed
Mar 18, 2025 at 18:50 UTC
0baad1f3aee508d84bf74b9670f283f8c91e55dd
4 files changed
+14
-7
refspec.c
+9
-3
@@ -178,10 +178,16 @@ void refspec_item_clear(struct refspec_item *item)
178
item->exact_sha1 = 0;
179
}
180
181
-void refspec_init(struct refspec *rs, int fetch)
181
+void refspec_init_fetch(struct refspec *rs)
182
{
183
- memset(rs, 0, sizeof(*rs));
184
- rs->fetch = fetch;
183
+ struct refspec blank = REFSPEC_INIT_FETCH;
184
+ memcpy(rs, &blank, sizeof(*rs));
185
+}
186
+
187
+void refspec_init_push(struct refspec *rs)
188
+{
189
+ struct refspec blank = REFSPEC_INIT_PUSH;
190
+ memcpy(rs, &blank, sizeof(*rs));
191
}
192
193
void refspec_append(struct refspec *rs, const char *refspec)
refspec.h
+2
-1
@@ -52,7 +52,8 @@ int refspec_item_init(struct refspec_item *item, const char *refspec,
52
void refspec_item_init_or_die(struct refspec_item *item, const char *refspec,
53
int fetch);
54
void refspec_item_clear(struct refspec_item *item);
55
-void refspec_init(struct refspec *rs, int fetch);
55
+void refspec_init_fetch(struct refspec *rs);
56
+void refspec_init_push(struct refspec *rs);
57
void refspec_append(struct refspec *rs, const char *refspec);
58
__attribute__((format (printf,2,3)))
59
void refspec_appendf(struct refspec *rs, const char *fmt, ...);
remote.c
+2
-2
@@ -143,8 +143,8 @@ static struct remote *make_remote(struct remote_state *remote_state,
143
ret->prune = -1; /* unspecified */
144
ret->prune_tags = -1; /* unspecified */
145
ret->name = xstrndup(name, len);
146
- refspec_init(&ret->push, 0);
147
- refspec_init(&ret->fetch, 1);
146
+ refspec_init_push(&ret->push);
147
+ refspec_init_fetch(&ret->fetch);
148
string_list_init_dup(&ret->server_options);
149
150
ALLOC_GROW(remote_state->remotes, remote_state->remotes_nr + 1,
transport-helper.c
+1
-1
@@ -162,7 +162,7 @@ static struct child_process *get_helper(struct transport *transport)
162
163
data->helper = helper;
164
data->no_disconnect_req = 0;
165
- refspec_init(&data->rs, 1);
165
+ refspec_init_fetch(&data->rs);
166
167
/*
168
* Open the output as FILE* so strbuf_getline_*() family of