@@ -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 ;
@@ -172,16 +169,6 @@ static void update_tracking_ref(struct remote *remote, struct ref *ref)
172
169
}
173
170
}
174
171
175
- static const char * prettify_ref (const struct ref * ref )
176
- {
177
- const char * name = ref -> name ;
178
- return name + (
179
- !prefixcmp (name , "refs/heads/" ) ? 11 :
180
- !prefixcmp (name , "refs/tags/" ) ? 10 :
181
- !prefixcmp (name , "refs/remotes/" ) ? 13 :
182
- 0 );
183
- }
184
-
185
172
#define SUMMARY_WIDTH (2 * DEFAULT_ABBREV + 3)
186
173
187
174
static void print_ref_status (char flag , const char * summary , struct ref * to , struct ref * from , const char * msg )
@@ -310,47 +297,29 @@ static int refs_pushed(struct ref *ref)
310
297
return 0 ;
311
298
}
312
299
313
- 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 )
314
304
{
315
- struct ref * ref , * local_refs ;
305
+ int in = fd [0 ];
306
+ int out = fd [1 ];
307
+ struct ref * ref ;
316
308
int new_refs ;
317
309
int ask_for_status_report = 0 ;
318
310
int allow_deleting_refs = 0 ;
319
311
int expect_status_report = 0 ;
320
- int flags = MATCH_REFS_NONE ;
321
312
int ret ;
322
- struct extra_have_objects extra_have ;
323
-
324
- memset (& extra_have , 0 , sizeof (extra_have ));
325
- if (args .send_all )
326
- flags |= MATCH_REFS_ALL ;
327
- if (args .send_mirror )
328
- flags |= MATCH_REFS_MIRROR ;
329
-
330
- /* No funny business with the matcher */
331
- remote_tail = get_remote_heads (in , & remote_refs , 0 , NULL , REF_NORMAL ,
332
- & extra_have );
333
- local_refs = get_local_heads ();
334
313
335
314
/* Does the other end support the reporting? */
336
315
if (server_supports ("report-status" ))
337
316
ask_for_status_report = 1 ;
338
317
if (server_supports ("delete-refs" ))
339
318
allow_deleting_refs = 1 ;
340
319
341
- /* match them up */
342
- if (!remote_tail )
343
- remote_tail = & remote_refs ;
344
- if (match_refs (local_refs , remote_refs , & remote_tail ,
345
- nr_refspec , refspec , flags )) {
346
- close (out );
347
- return -1 ;
348
- }
349
-
350
320
if (!remote_refs ) {
351
321
fprintf (stderr , "No refs in common and none specified; doing nothing.\n"
352
322
"Perhaps you should specify a branch such as 'master'.\n" );
353
- close (out );
354
323
return 0 ;
355
324
}
356
325
@@ -362,7 +331,7 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest
362
331
363
332
if (ref -> peer_ref )
364
333
hashcpy (ref -> new_sha1 , ref -> peer_ref -> new_sha1 );
365
- else if (!args . send_mirror )
334
+ else if (!args -> send_mirror )
366
335
continue ;
367
336
368
337
ref -> deletion = is_null_sha1 (ref -> new_sha1 );
@@ -401,15 +370,15 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest
401
370
(!has_sha1_file (ref -> old_sha1 )
402
371
|| !ref_newer (ref -> new_sha1 , ref -> old_sha1 ));
403
372
404
- if (ref -> nonfastforward && !ref -> force && !args . force_update ) {
373
+ if (ref -> nonfastforward && !ref -> force && !args -> force_update ) {
405
374
ref -> status = REF_STATUS_REJECT_NONFASTFORWARD ;
406
375
continue ;
407
376
}
408
377
409
378
if (!ref -> deletion )
410
379
new_refs ++ ;
411
380
412
- if (!args . dry_run ) {
381
+ if (!args -> dry_run ) {
413
382
char * old_hex = sha1_to_hex (ref -> old_sha1 );
414
383
char * new_hex = sha1_to_hex (ref -> new_sha1 );
415
384
@@ -430,27 +399,19 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest
430
399
}
431
400
432
401
packet_flush (out );
433
- if (new_refs && !args .dry_run ) {
434
- 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 ;
435
406
return -1 ;
407
+ }
436
408
}
437
- else
438
- close (out );
439
409
440
410
if (expect_status_report )
441
411
ret = receive_status (in , remote_refs );
442
412
else
443
413
ret = 0 ;
444
414
445
- print_push_status (dest , remote_refs );
446
-
447
- if (!args .dry_run && remote ) {
448
- for (ref = remote_refs ; ref ; ref = ref -> next )
449
- update_tracking_ref (remote , ref );
450
- }
451
-
452
- if (!refs_pushed (remote_refs ))
453
- fprintf (stderr , "Everything up-to-date\n" );
454
415
if (ret < 0 )
455
416
return ret ;
456
417
for (ref = remote_refs ; ref ; ref = ref -> next ) {
@@ -499,31 +460,39 @@ static void verify_remote_names(int nr_heads, const char **heads)
499
460
500
461
int cmd_send_pack (int argc , const char * * argv , const char * prefix )
501
462
{
502
- int i , nr_heads = 0 ;
503
- const char * * heads = NULL ;
463
+ int i , nr_refspecs = 0 ;
464
+ const char * * refspecs = NULL ;
504
465
const char * remote_name = NULL ;
505
466
struct remote * remote = NULL ;
506
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 ;
507
476
508
477
argv ++ ;
509
478
for (i = 1 ; i < argc ; i ++ , argv ++ ) {
510
479
const char * arg = * argv ;
511
480
512
481
if (* arg == '-' ) {
513
482
if (!prefixcmp (arg , "--receive-pack=" )) {
514
- args . receivepack = arg + 15 ;
483
+ receivepack = arg + 15 ;
515
484
continue ;
516
485
}
517
486
if (!prefixcmp (arg , "--exec=" )) {
518
- args . receivepack = arg + 7 ;
487
+ receivepack = arg + 7 ;
519
488
continue ;
520
489
}
521
490
if (!prefixcmp (arg , "--remote=" )) {
522
491
remote_name = arg + 9 ;
523
492
continue ;
524
493
}
525
494
if (!strcmp (arg , "--all" )) {
526
- args . send_all = 1 ;
495
+ send_all = 1 ;
527
496
continue ;
528
497
}
529
498
if (!strcmp (arg , "--dry-run" )) {
@@ -552,8 +521,8 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
552
521
dest = arg ;
553
522
continue ;
554
523
}
555
- heads = (const char * * ) argv ;
556
- nr_heads = argc - i ;
524
+ refspecs = (const char * * ) argv ;
525
+ nr_refspecs = argc - i ;
557
526
break ;
558
527
}
559
528
if (!dest )
@@ -562,8 +531,8 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
562
531
* --all and --mirror are incompatible; neither makes sense
563
532
* with any refspecs.
564
533
*/
565
- if ((heads && (args . send_all || args .send_mirror )) ||
566
- ( args . send_all && args .send_mirror ))
534
+ if ((refspecs && (send_all || args .send_mirror )) ||
535
+ ( send_all && args .send_mirror ))
567
536
usage (send_pack_usage );
568
537
569
538
if (remote_name ) {
@@ -574,24 +543,50 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
574
543
}
575
544
}
576
545
577
- return send_pack (& args , dest , remote , nr_heads , heads );
578
- }
546
+ conn = git_connect (fd , dest , receivepack , args .verbose ? CONNECT_VERBOSE : 0 );
579
547
580
- int send_pack (struct send_pack_args * my_args ,
581
- const char * dest , struct remote * remote ,
582
- int nr_heads , const char * * heads )
583
- {
584
- int fd [2 ], ret ;
585
- 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 );
586
552
587
- memcpy (& args , my_args , sizeof (args ));
553
+ verify_remote_names (nr_refspecs , refspecs );
554
+
555
+ local_refs = get_local_heads ();
556
+
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
+ }
588
572
589
- verify_remote_names ( nr_heads , heads );
573
+ ret = send_pack ( & args , fd , conn , remote_refs , & extra_have );
590
574
591
- conn = git_connect (fd , dest , args .receivepack , args .verbose ? CONNECT_VERBOSE : 0 );
592
- ret = do_send_pack (fd [0 ], fd [1 ], remote , dest , nr_heads , heads );
575
+ close (fd [1 ]);
593
576
close (fd [0 ]);
594
- /* do_send_pack always closes fd[1] */
577
+
595
578
ret |= finish_connect (conn );
596
- 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 ;
597
592
}
0 commit comments