@@ -61,41 +61,41 @@ static struct refspec rs = REFSPEC_INIT_PUSH;
6161
6262static struct string_list push_options_config = STRING_LIST_INIT_DUP ;
6363
64- static const char * map_refspec ( const char * ref ,
65- struct remote * remote , struct ref * local_refs )
64+ static void refspec_append_mapped ( struct refspec * refspec , const char * ref ,
65+ struct remote * remote , struct ref * local_refs )
6666{
6767 const char * branch_name ;
6868 struct ref * matched = NULL ;
6969
7070 /* Does "ref" uniquely name our ref? */
71- if (count_refspec_match (ref , local_refs , & matched ) != 1 )
72- return ref ;
71+ if (count_refspec_match (ref , local_refs , & matched ) != 1 ) {
72+ refspec_append (refspec , ref );
73+ return ;
74+ }
7375
7476 if (remote -> push .nr ) {
7577 struct refspec_item query ;
7678 memset (& query , 0 , sizeof (struct refspec_item ));
7779 query .src = matched -> name ;
7880 if (!query_refspecs (& remote -> push , & query ) && query .dst ) {
79- struct strbuf buf = STRBUF_INIT ;
80- strbuf_addf (& buf , "%s%s:%s" ,
81- query .force ? "+" : "" ,
82- query .src , query .dst );
83- return strbuf_detach (& buf , NULL );
81+ refspec_appendf (refspec , "%s%s:%s" ,
82+ query .force ? "+" : "" ,
83+ query .src , query .dst );
84+ return ;
8485 }
8586 }
8687
8788 if (push_default == PUSH_DEFAULT_UPSTREAM &&
8889 skip_prefix (matched -> name , "refs/heads/" , & branch_name )) {
8990 struct branch * branch = branch_get (branch_name );
9091 if (branch -> merge_nr == 1 && branch -> merge [0 ]-> src ) {
91- struct strbuf buf = STRBUF_INIT ;
92- strbuf_addf (& buf , "%s:%s" ,
93- ref , branch -> merge [0 ]-> src );
94- return strbuf_detach (& buf , NULL );
92+ refspec_appendf (refspec , "%s:%s" ,
93+ ref , branch -> merge [0 ]-> src );
94+ return ;
9595 }
9696 }
9797
98- return ref ;
98+ refspec_append ( refspec , ref ) ;
9999}
100100
101101static void set_refspecs (const char * * refs , int nr , const char * repo )
@@ -107,30 +107,26 @@ static void set_refspecs(const char **refs, int nr, const char *repo)
107107 for (i = 0 ; i < nr ; i ++ ) {
108108 const char * ref = refs [i ];
109109 if (!strcmp ("tag" , ref )) {
110- struct strbuf tagref = STRBUF_INIT ;
111110 if (nr <= ++ i )
112111 die (_ ("tag shorthand without <tag>" ));
113112 ref = refs [i ];
114113 if (deleterefs )
115- strbuf_addf ( & tagref , ":refs/tags/%s" , ref );
114+ refspec_appendf ( & rs , ":refs/tags/%s" , ref );
116115 else
117- strbuf_addf (& tagref , "refs/tags/%s" , ref );
118- ref = strbuf_detach (& tagref , NULL );
116+ refspec_appendf (& rs , "refs/tags/%s" , ref );
119117 } else if (deleterefs ) {
120- struct strbuf delref = STRBUF_INIT ;
121118 if (strchr (ref , ':' ))
122119 die (_ ("--delete only accepts plain target ref names" ));
123- strbuf_addf (& delref , ":%s" , ref );
124- ref = strbuf_detach (& delref , NULL );
120+ refspec_appendf (& rs , ":%s" , ref );
125121 } else if (!strchr (ref , ':' )) {
126122 if (!remote ) {
127123 /* lazily grab remote and local_refs */
128124 remote = remote_get (repo );
129125 local_refs = get_local_heads ();
130126 }
131- ref = map_refspec ( ref , remote , local_refs );
132- }
133- refspec_append (& rs , ref );
127+ refspec_append_mapped ( & rs , ref , remote , local_refs );
128+ } else
129+ refspec_append (& rs , ref );
134130 }
135131}
136132
@@ -192,8 +188,6 @@ static const char message_detached_head_die[] =
192188static void setup_push_upstream (struct remote * remote , struct branch * branch ,
193189 int triangular , int simple )
194190{
195- struct strbuf refspec = STRBUF_INIT ;
196-
197191 if (!branch )
198192 die (_ (message_detached_head_die ), remote -> name );
199193 if (!branch -> merge_nr || !branch -> merge || !branch -> remote_name )
@@ -219,18 +213,14 @@ static void setup_push_upstream(struct remote *remote, struct branch *branch,
219213 die_push_simple (branch , remote );
220214 }
221215
222- strbuf_addf (& refspec , "%s:%s" , branch -> refname , branch -> merge [0 ]-> src );
223- refspec_append (& rs , refspec .buf );
216+ refspec_appendf (& rs , "%s:%s" , branch -> refname , branch -> merge [0 ]-> src );
224217}
225218
226219static void setup_push_current (struct remote * remote , struct branch * branch )
227220{
228- struct strbuf refspec = STRBUF_INIT ;
229-
230221 if (!branch )
231222 die (_ (message_detached_head_die ), remote -> name );
232- strbuf_addf (& refspec , "%s:%s" , branch -> refname , branch -> refname );
233- refspec_append (& rs , refspec .buf );
223+ refspec_appendf (& rs , "%s:%s" , branch -> refname , branch -> refname );
234224}
235225
236226static int is_workflow_triangular (struct remote * remote )
0 commit comments