push: convert to use struct refspec
Convert the refspecs in builtin/push.c to be stored in a 'struct refspec' instead of being stored in a list of 'struct refspec_item's. 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
aa40289ce9438890368aa1c667d1ed6e3184213c
1 file changed
+15
-23
builtin/push.c
+15
-23
@@ -57,19 +57,10 @@ static enum transport_family family;
57
58
static struct push_cas_option cas;
59
60
-static const char **refspec;
61
-static int refspec_nr;
62
-static int refspec_alloc;
60
+static struct refspec rs = REFSPEC_INIT_PUSH;
61
62
static struct string_list push_options_config = STRING_LIST_INIT_DUP;
63
66
-static void add_refspec(const char *ref)
67
-{
68
- refspec_nr++;
69
- ALLOC_GROW(refspec, refspec_nr, refspec_alloc);
70
- refspec[refspec_nr-1] = ref;
71
-}
72
-
64
static const char *map_refspec(const char *ref,
65
struct remote *remote, struct ref *local_refs)
66
{
@@ -138,7 +129,7 @@ static void set_refspecs(const char **refs, int nr, const char *repo)
129
}
130
ref = map_refspec(ref, remote, local_refs);
131
}
141
- add_refspec(ref);
132
+ refspec_append(&rs, ref);
133
}
134
}
135
@@ -226,7 +217,7 @@ static void setup_push_upstream(struct remote *remote, struct branch *branch,
217
}
218
219
strbuf_addf(&refspec, "%s:%s", branch->refname, branch->merge[0]->src);
229
- add_refspec(refspec.buf);
220
+ refspec_append(&rs, refspec.buf);
221
}
222
223
static void setup_push_current(struct remote *remote, struct branch *branch)
@@ -236,7 +227,7 @@ static void setup_push_current(struct remote *remote, struct branch *branch)
227
if (!branch)
228
die(_(message_detached_head_die), remote->name);
229
strbuf_addf(&refspec, "%s:%s", branch->refname, branch->refname);
239
- add_refspec(refspec.buf);
230
+ refspec_append(&rs, refspec.buf);
231
}
232
233
static int is_workflow_triangular(struct remote *remote)
@@ -253,7 +244,7 @@ static void setup_default_push_refspecs(struct remote *remote)
244
switch (push_default) {
245
default:
246
case PUSH_DEFAULT_MATCHING:
256
- add_refspec(":");
247
+ refspec_append(&rs, ":");
248
break;
249
250
case PUSH_DEFAULT_UNSPECIFIED:
@@ -341,7 +332,8 @@ static void advise_ref_needs_force(void)
332
advise(_(message_advice_ref_needs_force));
333
}
334
344
-static int push_with_options(struct transport *transport, int flags)
335
+static int push_with_options(struct transport *transport, struct refspec *rs,
336
+ int flags)
337
{
338
int err;
339
unsigned int reject_reasons;
@@ -363,7 +355,7 @@ static int push_with_options(struct transport *transport, int flags)
355
356
if (verbosity > 0)
357
fprintf(stderr, _("Pushing to %s\n"), transport->url);
366
- err = transport_push(transport, refspec_nr, refspec, flags,
358
+ err = transport_push(transport, rs->raw_nr, rs->raw, flags,
359
&reject_reasons);
360
if (err != 0) {
361
fprintf(stderr, "%s", push_get_color(PUSH_COLOR_ERROR));
@@ -397,6 +389,7 @@ static int do_push(const char *repo, int flags,
389
struct remote *remote = pushremote_get(repo);
390
const char **url;
391
int url_nr;
392
+ struct refspec *push_refspec = &rs;
393
394
if (!remote) {
395
if (repo)
@@ -417,10 +410,9 @@ static int do_push(const char *repo, int flags,
410
if (push_options->nr)
411
flags |= TRANSPORT_PUSH_OPTIONS;
412
420
- if (!refspec && !(flags & TRANSPORT_PUSH_ALL)) {
421
- if (remote->push.raw_nr) {
422
- refspec = remote->push.raw;
423
- refspec_nr = remote->push.raw_nr;
413
+ if (!push_refspec->nr && !(flags & TRANSPORT_PUSH_ALL)) {
414
+ if (remote->push.nr) {
415
+ push_refspec = &remote->push;
416
} else if (!(flags & TRANSPORT_PUSH_MIRROR))
417
setup_default_push_refspecs(remote);
418
}
@@ -432,7 +424,7 @@ static int do_push(const char *repo, int flags,
424
transport_get(remote, url[i]);
425
if (flags & TRANSPORT_PUSH_OPTIONS)
426
transport->push_options = push_options;
435
- if (push_with_options(transport, flags))
427
+ if (push_with_options(transport, push_refspec, flags))
428
errs++;
429
}
430
} else {
@@ -440,7 +432,7 @@ static int do_push(const char *repo, int flags,
432
transport_get(remote, NULL);
433
if (flags & TRANSPORT_PUSH_OPTIONS)
434
transport->push_options = push_options;
443
- if (push_with_options(transport, flags))
435
+ if (push_with_options(transport, push_refspec, flags))
436
errs++;
437
}
438
return !!errs;
@@ -631,7 +623,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
623
flags |= TRANSPORT_RECURSE_SUBMODULES_ONLY;
624
625
if (tags)
634
- add_refspec("refs/tags/*");
626
+ refspec_append(&rs, "refs/tags/*");
627
628
if (argc > 0) {
629
repo = argv[0];