@@ -153,18 +153,22 @@ static int parse_refspec(struct refspec_item *item, const char *refspec, int fet
153153 return 1 ;
154154}
155155
156- int refspec_item_init (struct refspec_item * item , const char * refspec , int fetch )
156+ static int refspec_item_init (struct refspec_item * item , const char * refspec ,
157+ int fetch )
157158{
158159 memset (item , 0 , sizeof (* item ));
159160 item -> raw = xstrdup (refspec );
160161 return parse_refspec (item , refspec , fetch );
161162}
162163
163- void refspec_item_init_or_die (struct refspec_item * item , const char * refspec ,
164- int fetch )
164+ int refspec_item_init_fetch (struct refspec_item * item , const char * refspec )
165165{
166- if (!refspec_item_init (item , refspec , fetch ))
167- die (_ ("invalid refspec '%s'" ), refspec );
166+ return refspec_item_init (item , refspec , 1 );
167+ }
168+
169+ int refspec_item_init_push (struct refspec_item * item , const char * refspec )
170+ {
171+ return refspec_item_init (item , refspec , 0 );
168172}
169173
170174void refspec_item_clear (struct refspec_item * item )
@@ -178,17 +182,29 @@ void refspec_item_clear(struct refspec_item *item)
178182 item -> exact_sha1 = 0 ;
179183}
180184
181- void refspec_init (struct refspec * rs , int fetch )
185+ void refspec_init_fetch (struct refspec * rs )
186+ {
187+ struct refspec blank = REFSPEC_INIT_FETCH ;
188+ memcpy (rs , & blank , sizeof (* rs ));
189+ }
190+
191+ void refspec_init_push (struct refspec * rs )
182192{
183- memset ( rs , 0 , sizeof ( * rs )) ;
184- rs -> fetch = fetch ;
193+ struct refspec blank = REFSPEC_INIT_PUSH ;
194+ memcpy ( rs , & blank , sizeof ( * rs )) ;
185195}
186196
187197void refspec_append (struct refspec * rs , const char * refspec )
188198{
189199 struct refspec_item item ;
200+ int ret ;
190201
191- refspec_item_init_or_die (& item , refspec , rs -> fetch );
202+ if (rs -> fetch )
203+ ret = refspec_item_init_fetch (& item , refspec );
204+ else
205+ ret = refspec_item_init_push (& item , refspec );
206+ if (!ret )
207+ die (_ ("invalid refspec '%s'" ), refspec );
192208
193209 ALLOC_GROW (rs -> items , rs -> nr + 1 , rs -> alloc );
194210 rs -> items [rs -> nr ] = item ;
@@ -233,7 +249,7 @@ void refspec_clear(struct refspec *rs)
233249int valid_fetch_refspec (const char * fetch_refspec_str )
234250{
235251 struct refspec_item refspec ;
236- int ret = refspec_item_init (& refspec , fetch_refspec_str , REFSPEC_FETCH );
252+ int ret = refspec_item_init_fetch (& refspec , fetch_refspec_str );
237253 refspec_item_clear (& refspec );
238254 return ret ;
239255}
@@ -249,7 +265,7 @@ void refspec_ref_prefixes(const struct refspec *rs,
249265 if (item -> negative )
250266 continue ;
251267
252- if (rs -> fetch == REFSPEC_FETCH ) {
268+ if (rs -> fetch ) {
253269 if (item -> exact_sha1 )
254270 continue ;
255271 prefix = item -> src ;
0 commit comments