@@ -11,7 +11,6 @@ static const char send_pack_usage[] =
11
11
" --all and explicit <ref> specification are mutually exclusive." ;
12
12
13
13
static struct send_pack_args args = {
14
- /* .receivepack = */ "git-receive-pack" ,
15
14
};
16
15
17
16
static 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)
31
30
/*
32
31
* Make a pack stream and spit it out into file descriptor fd
33
32
*/
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 )
35
34
{
36
35
/*
37
36
* 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
49
48
struct child_process po ;
50
49
int i ;
51
50
52
- if (args . use_thin_pack )
51
+ if (args -> use_thin_pack )
53
52
argv [4 ] = "--thin" ;
54
53
memset (& po , 0 , sizeof (po ));
55
54
po .argv = argv ;
@@ -83,8 +82,6 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext
83
82
return 0 ;
84
83
}
85
84
86
- static struct ref * remote_refs , * * remote_tail ;
87
-
88
85
static int receive_status (int in , struct ref * refs )
89
86
{
90
87
struct ref * hint ;
@@ -300,47 +297,29 @@ static int refs_pushed(struct ref *ref)
300
297
return 0 ;
301
298
}
302
299
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 )
304
304
{
305
- struct ref * ref , * local_refs ;
305
+ int in = fd [0 ];
306
+ int out = fd [1 ];
307
+ struct ref * ref ;
306
308
int new_refs ;
307
309
int ask_for_status_report = 0 ;
308
310
int allow_deleting_refs = 0 ;
309
311
int expect_status_report = 0 ;
310
- int flags = MATCH_REFS_NONE ;
311
312
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 ();
324
313
325
314
/* Does the other end support the reporting? */
326
315
if (server_supports ("report-status" ))
327
316
ask_for_status_report = 1 ;
328
317
if (server_supports ("delete-refs" ))
329
318
allow_deleting_refs = 1 ;
330
319
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
-
340
320
if (!remote_refs ) {
341
321
fprintf (stderr , "No refs in common and none specified; doing nothing.\n"
342
322
"Perhaps you should specify a branch such as 'master'.\n" );
343
- close (out );
344
323
return 0 ;
345
324
}
346
325
@@ -352,7 +331,7 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest
352
331
353
332
if (ref -> peer_ref )
354
333
hashcpy (ref -> new_sha1 , ref -> peer_ref -> new_sha1 );
355
- else if (!args . send_mirror )
334
+ else if (!args -> send_mirror )
356
335
continue ;
357
336
358
337
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
391
370
(!has_sha1_file (ref -> old_sha1 )
392
371
|| !ref_newer (ref -> new_sha1 , ref -> old_sha1 ));
393
372
394
- if (ref -> nonfastforward && !ref -> force && !args . force_update ) {
373
+ if (ref -> nonfastforward && !ref -> force && !args -> force_update ) {
395
374
ref -> status = REF_STATUS_REJECT_NONFASTFORWARD ;
396
375
continue ;
397
376
}
398
377
399
378
if (!ref -> deletion )
400
379
new_refs ++ ;
401
380
402
- if (!args . dry_run ) {
381
+ if (!args -> dry_run ) {
403
382
char * old_hex = sha1_to_hex (ref -> old_sha1 );
404
383
char * new_hex = sha1_to_hex (ref -> new_sha1 );
405
384
@@ -420,27 +399,19 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest
420
399
}
421
400
422
401
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 ;
425
406
return -1 ;
407
+ }
426
408
}
427
- else
428
- close (out );
429
409
430
410
if (expect_status_report )
431
411
ret = receive_status (in , remote_refs );
432
412
else
433
413
ret = 0 ;
434
414
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" );
444
415
if (ret < 0 )
445
416
return ret ;
446
417
for (ref = remote_refs ; ref ; ref = ref -> next ) {
@@ -489,31 +460,39 @@ static void verify_remote_names(int nr_heads, const char **heads)
489
460
490
461
int cmd_send_pack (int argc , const char * * argv , const char * prefix )
491
462
{
492
- int i , nr_heads = 0 ;
493
- const char * * heads = NULL ;
463
+ int i , nr_refspecs = 0 ;
464
+ const char * * refspecs = NULL ;
494
465
const char * remote_name = NULL ;
495
466
struct remote * remote = NULL ;
496
467
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 ;
497
476
498
477
argv ++ ;
499
478
for (i = 1 ; i < argc ; i ++ , argv ++ ) {
500
479
const char * arg = * argv ;
501
480
502
481
if (* arg == '-' ) {
503
482
if (!prefixcmp (arg , "--receive-pack=" )) {
504
- args . receivepack = arg + 15 ;
483
+ receivepack = arg + 15 ;
505
484
continue ;
506
485
}
507
486
if (!prefixcmp (arg , "--exec=" )) {
508
- args . receivepack = arg + 7 ;
487
+ receivepack = arg + 7 ;
509
488
continue ;
510
489
}
511
490
if (!prefixcmp (arg , "--remote=" )) {
512
491
remote_name = arg + 9 ;
513
492
continue ;
514
493
}
515
494
if (!strcmp (arg , "--all" )) {
516
- args . send_all = 1 ;
495
+ send_all = 1 ;
517
496
continue ;
518
497
}
519
498
if (!strcmp (arg , "--dry-run" )) {
@@ -542,8 +521,8 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
542
521
dest = arg ;
543
522
continue ;
544
523
}
545
- heads = (const char * * ) argv ;
546
- nr_heads = argc - i ;
524
+ refspecs = (const char * * ) argv ;
525
+ nr_refspecs = argc - i ;
547
526
break ;
548
527
}
549
528
if (!dest )
@@ -552,8 +531,8 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
552
531
* --all and --mirror are incompatible; neither makes sense
553
532
* with any refspecs.
554
533
*/
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 ))
557
536
usage (send_pack_usage );
558
537
559
538
if (remote_name ) {
@@ -564,24 +543,50 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
564
543
}
565
544
}
566
545
567
- return send_pack (& args , dest , remote , nr_heads , heads );
568
- }
546
+ conn = git_connect (fd , dest , receivepack , args .verbose ? CONNECT_VERBOSE : 0 );
569
547
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 ();
576
556
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
+ }
578
572
579
- verify_remote_names ( nr_heads , heads );
573
+ ret = send_pack ( & args , fd , conn , remote_refs , & extra_have );
580
574
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 ]);
583
576
close (fd [0 ]);
584
- /* do_send_pack always closes fd[1] */
577
+
585
578
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 ;
587
592
}
0 commit comments