@@ -11,7 +11,6 @@ static const char send_pack_usage[] =
1111" --all and explicit <ref> specification are mutually exclusive." ;
1212
1313static struct send_pack_args args = {
14- /* .receivepack = */ "git-receive-pack" ,
1514};
1615
1716static int feed_object (const unsigned char * sha1 , int fd , int negative )
@@ -31,7 +30,7 @@ static int feed_object(const unsigned char *sha1, int fd, int negative)
3130/*
3231 * Make a pack stream and spit it out into file descriptor fd
3332 */
34- static int pack_objects (int fd , struct ref * refs , struct extra_have_objects * extra )
33+ static int pack_objects (int fd , struct ref * refs , struct extra_have_objects * extra , struct send_pack_args * args )
3534{
3635 /*
3736 * The child becomes pack-objects --revs; we feed
@@ -49,7 +48,7 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext
4948 struct child_process po ;
5049 int i ;
5150
52- if (args . use_thin_pack )
51+ if (args -> use_thin_pack )
5352 argv [4 ] = "--thin" ;
5453 memset (& po , 0 , sizeof (po ));
5554 po .argv = argv ;
@@ -83,8 +82,6 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext
8382 return 0 ;
8483}
8584
86- static struct ref * remote_refs , * * remote_tail ;
87-
8885static int receive_status (int in , struct ref * refs )
8986{
9087 struct ref * hint ;
@@ -300,47 +297,29 @@ static int refs_pushed(struct ref *ref)
300297 return 0 ;
301298}
302299
303- static int do_send_pack (int in , int out , struct remote * remote , const char * dest , int nr_refspec , const char * * refspec )
300+ int send_pack (struct send_pack_args * args ,
301+ int fd [], struct child_process * conn ,
302+ struct ref * remote_refs ,
303+ struct extra_have_objects * extra_have )
304304{
305- struct ref * ref , * local_refs ;
305+ int in = fd [0 ];
306+ int out = fd [1 ];
307+ struct ref * ref ;
306308 int new_refs ;
307309 int ask_for_status_report = 0 ;
308310 int allow_deleting_refs = 0 ;
309311 int expect_status_report = 0 ;
310- int flags = MATCH_REFS_NONE ;
311312 int ret ;
312- struct extra_have_objects extra_have ;
313-
314- memset (& extra_have , 0 , sizeof (extra_have ));
315- if (args .send_all )
316- flags |= MATCH_REFS_ALL ;
317- if (args .send_mirror )
318- flags |= MATCH_REFS_MIRROR ;
319-
320- /* No funny business with the matcher */
321- remote_tail = get_remote_heads (in , & remote_refs , 0 , NULL , REF_NORMAL ,
322- & extra_have );
323- local_refs = get_local_heads ();
324313
325314 /* Does the other end support the reporting? */
326315 if (server_supports ("report-status" ))
327316 ask_for_status_report = 1 ;
328317 if (server_supports ("delete-refs" ))
329318 allow_deleting_refs = 1 ;
330319
331- /* match them up */
332- if (!remote_tail )
333- remote_tail = & remote_refs ;
334- if (match_refs (local_refs , remote_refs , & remote_tail ,
335- nr_refspec , refspec , flags )) {
336- close (out );
337- return -1 ;
338- }
339-
340320 if (!remote_refs ) {
341321 fprintf (stderr , "No refs in common and none specified; doing nothing.\n"
342322 "Perhaps you should specify a branch such as 'master'.\n" );
343- close (out );
344323 return 0 ;
345324 }
346325
@@ -352,7 +331,7 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest
352331
353332 if (ref -> peer_ref )
354333 hashcpy (ref -> new_sha1 , ref -> peer_ref -> new_sha1 );
355- else if (!args . send_mirror )
334+ else if (!args -> send_mirror )
356335 continue ;
357336
358337 ref -> deletion = is_null_sha1 (ref -> new_sha1 );
@@ -391,15 +370,15 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest
391370 (!has_sha1_file (ref -> old_sha1 )
392371 || !ref_newer (ref -> new_sha1 , ref -> old_sha1 ));
393372
394- if (ref -> nonfastforward && !ref -> force && !args . force_update ) {
373+ if (ref -> nonfastforward && !ref -> force && !args -> force_update ) {
395374 ref -> status = REF_STATUS_REJECT_NONFASTFORWARD ;
396375 continue ;
397376 }
398377
399378 if (!ref -> deletion )
400379 new_refs ++ ;
401380
402- if (!args . dry_run ) {
381+ if (!args -> dry_run ) {
403382 char * old_hex = sha1_to_hex (ref -> old_sha1 );
404383 char * new_hex = sha1_to_hex (ref -> new_sha1 );
405384
@@ -420,27 +399,19 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest
420399 }
421400
422401 packet_flush (out );
423- if (new_refs && !args .dry_run ) {
424- if (pack_objects (out , remote_refs , & extra_have ) < 0 )
402+ if (new_refs && !args -> dry_run ) {
403+ if (pack_objects (out , remote_refs , extra_have , args ) < 0 ) {
404+ for (ref = remote_refs ; ref ; ref = ref -> next )
405+ ref -> status = REF_STATUS_NONE ;
425406 return -1 ;
407+ }
426408 }
427- else
428- close (out );
429409
430410 if (expect_status_report )
431411 ret = receive_status (in , remote_refs );
432412 else
433413 ret = 0 ;
434414
435- print_push_status (dest , remote_refs );
436-
437- if (!args .dry_run && remote ) {
438- for (ref = remote_refs ; ref ; ref = ref -> next )
439- update_tracking_ref (remote , ref );
440- }
441-
442- if (!refs_pushed (remote_refs ))
443- fprintf (stderr , "Everything up-to-date\n" );
444415 if (ret < 0 )
445416 return ret ;
446417 for (ref = remote_refs ; ref ; ref = ref -> next ) {
@@ -489,31 +460,39 @@ static void verify_remote_names(int nr_heads, const char **heads)
489460
490461int cmd_send_pack (int argc , const char * * argv , const char * prefix )
491462{
492- int i , nr_heads = 0 ;
493- const char * * heads = NULL ;
463+ int i , nr_refspecs = 0 ;
464+ const char * * refspecs = NULL ;
494465 const char * remote_name = NULL ;
495466 struct remote * remote = NULL ;
496467 const char * dest = NULL ;
468+ int fd [2 ];
469+ struct child_process * conn ;
470+ struct extra_have_objects extra_have ;
471+ struct ref * remote_refs , * * remote_tail , * local_refs ;
472+ int ret ;
473+ int send_all = 0 ;
474+ const char * receivepack = "git-receive-pack" ;
475+ int flags ;
497476
498477 argv ++ ;
499478 for (i = 1 ; i < argc ; i ++ , argv ++ ) {
500479 const char * arg = * argv ;
501480
502481 if (* arg == '-' ) {
503482 if (!prefixcmp (arg , "--receive-pack=" )) {
504- args . receivepack = arg + 15 ;
483+ receivepack = arg + 15 ;
505484 continue ;
506485 }
507486 if (!prefixcmp (arg , "--exec=" )) {
508- args . receivepack = arg + 7 ;
487+ receivepack = arg + 7 ;
509488 continue ;
510489 }
511490 if (!prefixcmp (arg , "--remote=" )) {
512491 remote_name = arg + 9 ;
513492 continue ;
514493 }
515494 if (!strcmp (arg , "--all" )) {
516- args . send_all = 1 ;
495+ send_all = 1 ;
517496 continue ;
518497 }
519498 if (!strcmp (arg , "--dry-run" )) {
@@ -542,8 +521,8 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
542521 dest = arg ;
543522 continue ;
544523 }
545- heads = (const char * * ) argv ;
546- nr_heads = argc - i ;
524+ refspecs = (const char * * ) argv ;
525+ nr_refspecs = argc - i ;
547526 break ;
548527 }
549528 if (!dest )
@@ -552,8 +531,8 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
552531 * --all and --mirror are incompatible; neither makes sense
553532 * with any refspecs.
554533 */
555- if ((heads && (args . send_all || args .send_mirror )) ||
556- ( args . send_all && args .send_mirror ))
534+ if ((refspecs && (send_all || args .send_mirror )) ||
535+ ( send_all && args .send_mirror ))
557536 usage (send_pack_usage );
558537
559538 if (remote_name ) {
@@ -564,24 +543,50 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
564543 }
565544 }
566545
567- return send_pack (& args , dest , remote , nr_heads , heads );
568- }
546+ conn = git_connect (fd , dest , receivepack , args .verbose ? CONNECT_VERBOSE : 0 );
569547
570- int send_pack (struct send_pack_args * my_args ,
571- const char * dest , struct remote * remote ,
572- int nr_heads , const char * * heads )
573- {
574- int fd [2 ], ret ;
575- struct child_process * conn ;
548+ memset (& extra_have , 0 , sizeof (extra_have ));
549+
550+ get_remote_heads (fd [0 ], & remote_refs , 0 , NULL , REF_NORMAL ,
551+ & extra_have );
552+
553+ verify_remote_names (nr_refspecs , refspecs );
554+
555+ local_refs = get_local_heads ();
576556
577- memcpy (& args , my_args , sizeof (args ));
557+ flags = MATCH_REFS_NONE ;
558+
559+ if (send_all )
560+ flags |= MATCH_REFS_ALL ;
561+ if (args .send_mirror )
562+ flags |= MATCH_REFS_MIRROR ;
563+
564+ /* match them up */
565+ remote_tail = & remote_refs ;
566+ while (* remote_tail )
567+ remote_tail = & ((* remote_tail )-> next );
568+ if (match_refs (local_refs , remote_refs , & remote_tail ,
569+ nr_refspecs , refspecs , flags )) {
570+ return -1 ;
571+ }
578572
579- verify_remote_names ( nr_heads , heads );
573+ ret = send_pack ( & args , fd , conn , remote_refs , & extra_have );
580574
581- conn = git_connect (fd , dest , args .receivepack , args .verbose ? CONNECT_VERBOSE : 0 );
582- ret = do_send_pack (fd [0 ], fd [1 ], remote , dest , nr_heads , heads );
575+ close (fd [1 ]);
583576 close (fd [0 ]);
584- /* do_send_pack always closes fd[1] */
577+
585578 ret |= finish_connect (conn );
586- return !!ret ;
579+
580+ print_push_status (dest , remote_refs );
581+
582+ if (!args .dry_run && remote ) {
583+ struct ref * ref ;
584+ for (ref = remote_refs ; ref ; ref = ref -> next )
585+ update_tracking_ref (remote , ref );
586+ }
587+
588+ if (!ret && !refs_pushed (remote_refs ))
589+ fprintf (stderr , "Everything up-to-date\n" );
590+
591+ return ret ;
587592}
0 commit comments