@@ -134,8 +134,6 @@ struct command {
134
134
char ref_name [FLEX_ARRAY ]; /* more */
135
135
};
136
136
137
- static struct command * commands ;
138
-
139
137
static const char pre_receive_hook [] = "hooks/pre-receive" ;
140
138
static const char post_receive_hook [] = "hooks/post-receive" ;
141
139
@@ -188,7 +186,7 @@ static int copy_to_sideband(int in, int out, void *arg)
188
186
return 0 ;
189
187
}
190
188
191
- static int run_receive_hook (const char * hook_name )
189
+ static int run_receive_hook (struct command * commands , const char * hook_name )
192
190
{
193
191
static char buf [sizeof (commands -> old_sha1 ) * 2 + PATH_MAX + 4 ];
194
192
struct command * cmd ;
@@ -447,15 +445,15 @@ static const char *update(struct command *cmd)
447
445
448
446
static char update_post_hook [] = "hooks/post-update" ;
449
447
450
- static void run_update_post_hook (struct command * cmd )
448
+ static void run_update_post_hook (struct command * commands )
451
449
{
452
- struct command * cmd_p ;
450
+ struct command * cmd ;
453
451
int argc ;
454
452
const char * * argv ;
455
453
struct child_process proc ;
456
454
457
- for (argc = 0 , cmd_p = cmd ; cmd_p ; cmd_p = cmd_p -> next ) {
458
- if (cmd_p -> error_string )
455
+ for (argc = 0 , cmd = commands ; cmd ; cmd = cmd -> next ) {
456
+ if (cmd -> error_string )
459
457
continue ;
460
458
argc ++ ;
461
459
}
@@ -464,12 +462,12 @@ static void run_update_post_hook(struct command *cmd)
464
462
argv = xmalloc (sizeof (* argv ) * (2 + argc ));
465
463
argv [0 ] = update_post_hook ;
466
464
467
- for (argc = 1 , cmd_p = cmd ; cmd_p ; cmd_p = cmd_p -> next ) {
465
+ for (argc = 1 , cmd = commands ; cmd ; cmd = cmd -> next ) {
468
466
char * p ;
469
- if (cmd_p -> error_string )
467
+ if (cmd -> error_string )
470
468
continue ;
471
- p = xmalloc (strlen (cmd_p -> ref_name ) + 1 );
472
- strcpy (p , cmd_p -> ref_name );
469
+ p = xmalloc (strlen (cmd -> ref_name ) + 1 );
470
+ strcpy (p , cmd -> ref_name );
473
471
argv [argc ] = p ;
474
472
argc ++ ;
475
473
}
@@ -488,37 +486,32 @@ static void run_update_post_hook(struct command *cmd)
488
486
}
489
487
}
490
488
491
- static void execute_commands (const char * unpacker_error )
489
+ static void execute_commands (struct command * commands , const char * unpacker_error )
492
490
{
493
- struct command * cmd = commands ;
491
+ struct command * cmd ;
494
492
unsigned char sha1 [20 ];
495
493
496
494
if (unpacker_error ) {
497
- while (cmd ) {
495
+ for (cmd = commands ; cmd ; cmd = cmd -> next )
498
496
cmd -> error_string = "n/a (unpacker error)" ;
499
- cmd = cmd -> next ;
500
- }
501
497
return ;
502
498
}
503
499
504
- if (run_receive_hook (pre_receive_hook )) {
505
- while (cmd ) {
500
+ if (run_receive_hook (commands , pre_receive_hook )) {
501
+ for (cmd = commands ; cmd ; cmd = cmd -> next )
506
502
cmd -> error_string = "pre-receive hook declined" ;
507
- cmd = cmd -> next ;
508
- }
509
503
return ;
510
504
}
511
505
512
506
head_name = resolve_ref ("HEAD" , sha1 , 0 , NULL );
513
507
514
- while (cmd ) {
508
+ for (cmd = commands ; cmd ; cmd = cmd -> next )
515
509
cmd -> error_string = update (cmd );
516
- cmd = cmd -> next ;
517
- }
518
510
}
519
511
520
- static void read_head_info (void )
512
+ static struct command * read_head_info (void )
521
513
{
514
+ struct command * commands = NULL ;
522
515
struct command * * p = & commands ;
523
516
for (;;) {
524
517
static char line [1000 ];
@@ -557,6 +550,7 @@ static void read_head_info(void)
557
550
* p = cmd ;
558
551
p = & cmd -> next ;
559
552
}
553
+ return commands ;
560
554
}
561
555
562
556
static const char * parse_pack_header (struct pack_header * hdr )
@@ -643,7 +637,7 @@ static const char *unpack(void)
643
637
}
644
638
}
645
639
646
- static void report (const char * unpack_status )
640
+ static void report (struct command * commands , const char * unpack_status )
647
641
{
648
642
struct command * cmd ;
649
643
struct strbuf buf = STRBUF_INIT ;
@@ -667,12 +661,12 @@ static void report(const char *unpack_status)
667
661
strbuf_release (& buf );
668
662
}
669
663
670
- static int delete_only (struct command * cmd )
664
+ static int delete_only (struct command * commands )
671
665
{
672
- while (cmd ) {
666
+ struct command * cmd ;
667
+ for (cmd = commands ; cmd ; cmd = cmd -> next ) {
673
668
if (!is_null_sha1 (cmd -> new_sha1 ))
674
669
return 0 ;
675
- cmd = cmd -> next ;
676
670
}
677
671
return 1 ;
678
672
}
@@ -722,6 +716,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
722
716
int stateless_rpc = 0 ;
723
717
int i ;
724
718
char * dir = NULL ;
719
+ struct command * commands ;
725
720
726
721
argv ++ ;
727
722
for (i = 1 ; i < argc ; i ++ ) {
@@ -772,18 +767,17 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
772
767
if (advertise_refs )
773
768
return 0 ;
774
769
775
- read_head_info ();
776
- if (commands ) {
770
+ if ((commands = read_head_info ()) != NULL ) {
777
771
const char * unpack_status = NULL ;
778
772
779
773
if (!delete_only (commands ))
780
774
unpack_status = unpack ();
781
- execute_commands (unpack_status );
775
+ execute_commands (commands , unpack_status );
782
776
if (pack_lockfile )
783
777
unlink_or_warn (pack_lockfile );
784
778
if (report_status )
785
- report (unpack_status );
786
- run_receive_hook (post_receive_hook );
779
+ report (commands , unpack_status );
780
+ run_receive_hook (commands , post_receive_hook );
787
781
run_update_post_hook (commands );
788
782
if (auto_gc ) {
789
783
const char * argv_gc_auto [] = {
0 commit comments