@@ -126,8 +126,7 @@ static int send_pack_config(const char *k, const char *v, void *cb)
126126
127127int cmd_send_pack (int argc , const char * * argv , const char * prefix )
128128{
129- int i , nr_refspecs = 0 ;
130- const char * * refspecs = NULL ;
129+ struct refspec rs = REFSPEC_INIT_PUSH ;
131130 const char * remote_name = NULL ;
132131 struct remote * remote = NULL ;
133132 const char * dest = NULL ;
@@ -189,8 +188,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
189188 argc = parse_options (argc , argv , prefix , options , send_pack_usage , 0 );
190189 if (argc > 0 ) {
191190 dest = argv [0 ];
192- refspecs = (const char * * )(argv + 1 );
193- nr_refspecs = argc - 1 ;
191+ refspec_appendn (& rs , argv + 1 , argc - 1 );
194192 }
195193
196194 if (!dest )
@@ -209,31 +207,23 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
209207 args .push_options = push_options .nr ? & push_options : NULL ;
210208
211209 if (from_stdin ) {
212- struct argv_array all_refspecs = ARGV_ARRAY_INIT ;
213-
214- for (i = 0 ; i < nr_refspecs ; i ++ )
215- argv_array_push (& all_refspecs , refspecs [i ]);
216-
217210 if (args .stateless_rpc ) {
218211 const char * buf ;
219212 while ((buf = packet_read_line (0 , NULL )))
220- argv_array_push ( & all_refspecs , buf );
213+ refspec_append ( & rs , buf );
221214 } else {
222215 struct strbuf line = STRBUF_INIT ;
223216 while (strbuf_getline (& line , stdin ) != EOF )
224- argv_array_push ( & all_refspecs , line .buf );
217+ refspec_append ( & rs , line .buf );
225218 strbuf_release (& line );
226219 }
227-
228- refspecs = all_refspecs .argv ;
229- nr_refspecs = all_refspecs .argc ;
230220 }
231221
232222 /*
233223 * --all and --mirror are incompatible; neither makes sense
234224 * with any refspecs.
235225 */
236- if ((nr_refspecs > 0 && (send_all || args .send_mirror )) ||
226+ if ((rs . nr > 0 && (send_all || args .send_mirror )) ||
237227 (send_all && args .send_mirror ))
238228 usage_with_options (send_pack_usage , options );
239229
@@ -275,7 +265,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
275265 BUG ("unknown protocol version" );
276266 }
277267
278- transport_verify_remote_names (nr_refspecs , refspecs );
268+ transport_verify_remote_names (rs . raw_nr , rs . raw );
279269
280270 local_refs = get_local_heads ();
281271
@@ -287,7 +277,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
287277 flags |= MATCH_REFS_MIRROR ;
288278
289279 /* match them up */
290- if (match_push_refs (local_refs , & remote_refs , nr_refspecs , refspecs , flags ))
280+ if (match_push_refs (local_refs , & remote_refs , rs . raw_nr , rs . raw , flags ))
291281 return -1 ;
292282
293283 if (!is_empty_cas (& cas ))
0 commit comments