@@ -57,19 +57,10 @@ static enum transport_family family;
5757
5858static struct push_cas_option cas ;
5959
60- static const char * * refspec ;
61- static int refspec_nr ;
62- static int refspec_alloc ;
60+ static struct refspec rs = REFSPEC_INIT_PUSH ;
6361
6462static struct string_list push_options_config = STRING_LIST_INIT_DUP ;
6563
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-
7364static const char * map_refspec (const char * ref ,
7465 struct remote * remote , struct ref * local_refs )
7566{
@@ -138,7 +129,7 @@ static void set_refspecs(const char **refs, int nr, const char *repo)
138129 }
139130 ref = map_refspec (ref , remote , local_refs );
140131 }
141- add_refspec ( ref );
132+ refspec_append ( & rs , ref );
142133 }
143134}
144135
@@ -226,7 +217,7 @@ static void setup_push_upstream(struct remote *remote, struct branch *branch,
226217 }
227218
228219 strbuf_addf (& refspec , "%s:%s" , branch -> refname , branch -> merge [0 ]-> src );
229- add_refspec ( refspec .buf );
220+ refspec_append ( & rs , refspec .buf );
230221}
231222
232223static 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)
236227 if (!branch )
237228 die (_ (message_detached_head_die ), remote -> name );
238229 strbuf_addf (& refspec , "%s:%s" , branch -> refname , branch -> refname );
239- add_refspec ( refspec .buf );
230+ refspec_append ( & rs , refspec .buf );
240231}
241232
242233static int is_workflow_triangular (struct remote * remote )
@@ -253,7 +244,7 @@ static void setup_default_push_refspecs(struct remote *remote)
253244 switch (push_default ) {
254245 default :
255246 case PUSH_DEFAULT_MATCHING :
256- add_refspec ( ":" );
247+ refspec_append ( & rs , ":" );
257248 break ;
258249
259250 case PUSH_DEFAULT_UNSPECIFIED :
@@ -341,7 +332,8 @@ static void advise_ref_needs_force(void)
341332 advise (_ (message_advice_ref_needs_force ));
342333}
343334
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 )
345337{
346338 int err ;
347339 unsigned int reject_reasons ;
@@ -363,7 +355,7 @@ static int push_with_options(struct transport *transport, int flags)
363355
364356 if (verbosity > 0 )
365357 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 ,
367359 & reject_reasons );
368360 if (err != 0 ) {
369361 fprintf (stderr , "%s" , push_get_color (PUSH_COLOR_ERROR ));
@@ -397,6 +389,7 @@ static int do_push(const char *repo, int flags,
397389 struct remote * remote = pushremote_get (repo );
398390 const char * * url ;
399391 int url_nr ;
392+ struct refspec * push_refspec = & rs ;
400393
401394 if (!remote ) {
402395 if (repo )
@@ -417,10 +410,9 @@ static int do_push(const char *repo, int flags,
417410 if (push_options -> nr )
418411 flags |= TRANSPORT_PUSH_OPTIONS ;
419412
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 ;
424416 } else if (!(flags & TRANSPORT_PUSH_MIRROR ))
425417 setup_default_push_refspecs (remote );
426418 }
@@ -432,15 +424,15 @@ static int do_push(const char *repo, int flags,
432424 transport_get (remote , url [i ]);
433425 if (flags & TRANSPORT_PUSH_OPTIONS )
434426 transport -> push_options = push_options ;
435- if (push_with_options (transport , flags ))
427+ if (push_with_options (transport , push_refspec , flags ))
436428 errs ++ ;
437429 }
438430 } else {
439431 struct transport * transport =
440432 transport_get (remote , NULL );
441433 if (flags & TRANSPORT_PUSH_OPTIONS )
442434 transport -> push_options = push_options ;
443- if (push_with_options (transport , flags ))
435+ if (push_with_options (transport , push_refspec , flags ))
444436 errs ++ ;
445437 }
446438 return !!errs ;
@@ -631,7 +623,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
631623 flags |= TRANSPORT_RECURSE_SUBMODULES_ONLY ;
632624
633625 if (tags )
634- add_refspec ( "refs/tags/*" );
626+ refspec_append ( & rs , "refs/tags/*" );
635627
636628 if (argc > 0 ) {
637629 repo = argv [0 ];
0 commit comments