@@ -57,19 +57,10 @@ static enum transport_family family;
57
57
58
58
static struct push_cas_option cas ;
59
59
60
- static const char * * refspec ;
61
- static int refspec_nr ;
62
- static int refspec_alloc ;
60
+ static struct refspec rs = REFSPEC_INIT_PUSH ;
63
61
64
62
static struct string_list push_options_config = STRING_LIST_INIT_DUP ;
65
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
-
73
64
static const char * map_refspec (const char * ref ,
74
65
struct remote * remote , struct ref * local_refs )
75
66
{
@@ -138,7 +129,7 @@ static void set_refspecs(const char **refs, int nr, const char *repo)
138
129
}
139
130
ref = map_refspec (ref , remote , local_refs );
140
131
}
141
- add_refspec ( ref );
132
+ refspec_append ( & rs , ref );
142
133
}
143
134
}
144
135
@@ -226,7 +217,7 @@ static void setup_push_upstream(struct remote *remote, struct branch *branch,
226
217
}
227
218
228
219
strbuf_addf (& refspec , "%s:%s" , branch -> refname , branch -> merge [0 ]-> src );
229
- add_refspec ( refspec .buf );
220
+ refspec_append ( & rs , refspec .buf );
230
221
}
231
222
232
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)
236
227
if (!branch )
237
228
die (_ (message_detached_head_die ), remote -> name );
238
229
strbuf_addf (& refspec , "%s:%s" , branch -> refname , branch -> refname );
239
- add_refspec ( refspec .buf );
230
+ refspec_append ( & rs , refspec .buf );
240
231
}
241
232
242
233
static int is_workflow_triangular (struct remote * remote )
@@ -253,7 +244,7 @@ static void setup_default_push_refspecs(struct remote *remote)
253
244
switch (push_default ) {
254
245
default :
255
246
case PUSH_DEFAULT_MATCHING :
256
- add_refspec ( ":" );
247
+ refspec_append ( & rs , ":" );
257
248
break ;
258
249
259
250
case PUSH_DEFAULT_UNSPECIFIED :
@@ -341,7 +332,8 @@ static void advise_ref_needs_force(void)
341
332
advise (_ (message_advice_ref_needs_force ));
342
333
}
343
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 )
345
337
{
346
338
int err ;
347
339
unsigned int reject_reasons ;
@@ -363,7 +355,7 @@ static int push_with_options(struct transport *transport, int flags)
363
355
364
356
if (verbosity > 0 )
365
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 ,
367
359
& reject_reasons );
368
360
if (err != 0 ) {
369
361
fprintf (stderr , "%s" , push_get_color (PUSH_COLOR_ERROR ));
@@ -397,6 +389,7 @@ static int do_push(const char *repo, int flags,
397
389
struct remote * remote = pushremote_get (repo );
398
390
const char * * url ;
399
391
int url_nr ;
392
+ struct refspec * push_refspec = & rs ;
400
393
401
394
if (!remote ) {
402
395
if (repo )
@@ -417,10 +410,9 @@ static int do_push(const char *repo, int flags,
417
410
if (push_options -> nr )
418
411
flags |= TRANSPORT_PUSH_OPTIONS ;
419
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 ;
424
416
} else if (!(flags & TRANSPORT_PUSH_MIRROR ))
425
417
setup_default_push_refspecs (remote );
426
418
}
@@ -432,15 +424,15 @@ static int do_push(const char *repo, int flags,
432
424
transport_get (remote , url [i ]);
433
425
if (flags & TRANSPORT_PUSH_OPTIONS )
434
426
transport -> push_options = push_options ;
435
- if (push_with_options (transport , flags ))
427
+ if (push_with_options (transport , push_refspec , flags ))
436
428
errs ++ ;
437
429
}
438
430
} else {
439
431
struct transport * transport =
440
432
transport_get (remote , NULL );
441
433
if (flags & TRANSPORT_PUSH_OPTIONS )
442
434
transport -> push_options = push_options ;
443
- if (push_with_options (transport , flags ))
435
+ if (push_with_options (transport , push_refspec , flags ))
444
436
errs ++ ;
445
437
}
446
438
return !!errs ;
@@ -631,7 +623,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
631
623
flags |= TRANSPORT_RECURSE_SUBMODULES_ONLY ;
632
624
633
625
if (tags )
634
- add_refspec ( "refs/tags/*" );
626
+ refspec_append ( & rs , "refs/tags/*" );
635
627
636
628
if (argc > 0 ) {
637
629
repo = argv [0 ];
0 commit comments