send-pack: store refspecs in a struct refspec
Convert send-pack.c to store refspecs in a 'struct refspec' instead of as an array of 'const char *'. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Williams committed
May 16, 2018 at 15:58 UTC
168dba68c9ee2f35b40ec306a7b984e90cce2648
1 file changed
+7
-17
builtin/send-pack.c
+7
-17
@@ -126,8 +126,7 @@ static int send_pack_config(const char *k, const char *v, void *cb)
126
127
int cmd_send_pack(int argc, const char **argv, const char *prefix)
128
{
129
- int i, nr_refspecs = 0;
130
- const char **refspecs = NULL;
129
+ struct refspec rs = REFSPEC_INIT_PUSH;
130
const char *remote_name = NULL;
131
struct remote *remote = NULL;
132
const char *dest = NULL;
@@ -189,8 +188,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
188
argc = parse_options(argc, argv, prefix, options, send_pack_usage, 0);
189
if (argc > 0) {
190
dest = argv[0];
192
- refspecs = (const char **)(argv + 1);
193
- nr_refspecs = argc - 1;
191
+ refspec_appendn(&rs, argv + 1, argc - 1);
192
}
193
194
if (!dest)
@@ -209,31 +207,23 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
207
args.push_options = push_options.nr ? &push_options : NULL;
208
209
if (from_stdin) {
212
- struct argv_array all_refspecs = ARGV_ARRAY_INIT;
213
-
214
- for (i = 0; i < nr_refspecs; i++)
215
- argv_array_push(&all_refspecs, refspecs[i]);
216
-
210
if (args.stateless_rpc) {
211
const char *buf;
212
while ((buf = packet_read_line(0, NULL)))
220
- argv_array_push(&all_refspecs, buf);
213
+ refspec_append(&rs, buf);
214
} else {
215
struct strbuf line = STRBUF_INIT;
216
while (strbuf_getline(&line, stdin) != EOF)
224
- argv_array_push(&all_refspecs, line.buf);
217
+ refspec_append(&rs, line.buf);
218
strbuf_release(&line);
219
}
227
-
228
- refspecs = all_refspecs.argv;
229
- nr_refspecs = all_refspecs.argc;
220
}
221
222
/*
223
* --all and --mirror are incompatible; neither makes sense
224
* with any refspecs.
225
*/
236
- if ((nr_refspecs > 0 && (send_all || args.send_mirror)) ||
226
+ if ((rs.nr > 0 && (send_all || args.send_mirror)) ||
227
(send_all && args.send_mirror))
228
usage_with_options(send_pack_usage, options);
229
@@ -275,7 +265,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
265
BUG("unknown protocol version");
266
}
267
278
- transport_verify_remote_names(nr_refspecs, refspecs);
268
+ transport_verify_remote_names(rs.raw_nr, rs.raw);
269
270
local_refs = get_local_heads();
271
@@ -287,7 +277,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
277
flags |= MATCH_REFS_MIRROR;
278
279
/* match them up */
290
- if (match_push_refs(local_refs, &remote_refs, nr_refspecs, refspecs, flags))
280
+ if (match_push_refs(local_refs, &remote_refs, rs.raw_nr, rs.raw, flags))
281
return -1;
282
283
if (!is_empty_cas(&cas))