@@ -123,27 +123,27 @@ static struct command *commands;
123
123
static const char pre_receive_hook [] = "hooks/pre-receive" ;
124
124
static const char post_receive_hook [] = "hooks/post-receive" ;
125
125
126
- static int hook_status (int code , const char * hook_name )
126
+ static int run_status (int code , const char * cmd_name )
127
127
{
128
128
switch (code ) {
129
129
case 0 :
130
130
return 0 ;
131
131
case - ERR_RUN_COMMAND_FORK :
132
- return error ("hook fork failed" );
132
+ return error ("fork of %s failed" , cmd_name );
133
133
case - ERR_RUN_COMMAND_EXEC :
134
- return error ("hook execute failed" );
134
+ return error ("execute of %s failed" , cmd_name );
135
135
case - ERR_RUN_COMMAND_PIPE :
136
- return error ("hook pipe failed" );
136
+ return error ("pipe failed" );
137
137
case - ERR_RUN_COMMAND_WAITPID :
138
138
return error ("waitpid failed" );
139
139
case - ERR_RUN_COMMAND_WAITPID_WRONG_PID :
140
140
return error ("waitpid is confused" );
141
141
case - ERR_RUN_COMMAND_WAITPID_SIGNAL :
142
- return error ("%s died of signal" , hook_name );
142
+ return error ("%s died of signal" , cmd_name );
143
143
case - ERR_RUN_COMMAND_WAITPID_NOEXIT :
144
- return error ("%s died strangely" , hook_name );
144
+ return error ("%s died strangely" , cmd_name );
145
145
default :
146
- error ("%s exited with error code %d" , hook_name , - code );
146
+ error ("%s exited with error code %d" , cmd_name , - code );
147
147
return - code ;
148
148
}
149
149
}
@@ -174,7 +174,7 @@ static int run_receive_hook(const char *hook_name)
174
174
175
175
code = start_command (& proc );
176
176
if (code )
177
- return hook_status (code , hook_name );
177
+ return run_status (code , hook_name );
178
178
for (cmd = commands ; cmd ; cmd = cmd -> next ) {
179
179
if (!cmd -> error_string ) {
180
180
size_t n = snprintf (buf , sizeof (buf ), "%s %s %s\n" ,
@@ -186,7 +186,7 @@ static int run_receive_hook(const char *hook_name)
186
186
}
187
187
}
188
188
close (proc .in );
189
- return hook_status (finish_command (& proc ), hook_name );
189
+ return run_status (finish_command (& proc ), hook_name );
190
190
}
191
191
192
192
static int run_update_hook (struct command * cmd )
@@ -203,7 +203,7 @@ static int run_update_hook(struct command *cmd)
203
203
argv [3 ] = sha1_to_hex (cmd -> new_sha1 );
204
204
argv [4 ] = NULL ;
205
205
206
- return hook_status (run_command_v_opt (argv , RUN_COMMAND_NO_STDIN |
206
+ return run_status (run_command_v_opt (argv , RUN_COMMAND_NO_STDIN |
207
207
RUN_COMMAND_STDOUT_TO_STDERR ),
208
208
update_hook );
209
209
}
@@ -394,7 +394,7 @@ static char update_post_hook[] = "hooks/post-update";
394
394
static void run_update_post_hook (struct command * cmd )
395
395
{
396
396
struct command * cmd_p ;
397
- int argc ;
397
+ int argc , status ;
398
398
const char * * argv ;
399
399
400
400
for (argc = 0 , cmd_p = cmd ; cmd_p ; cmd_p = cmd_p -> next ) {
@@ -417,8 +417,9 @@ static void run_update_post_hook(struct command *cmd)
417
417
argc ++ ;
418
418
}
419
419
argv [argc ] = NULL ;
420
- run_command_v_opt (argv , RUN_COMMAND_NO_STDIN
421
- | RUN_COMMAND_STDOUT_TO_STDERR );
420
+ status = run_command_v_opt (argv , RUN_COMMAND_NO_STDIN
421
+ | RUN_COMMAND_STDOUT_TO_STDERR );
422
+ run_status (status , update_post_hook );
422
423
}
423
424
424
425
static void execute_commands (const char * unpacker_error )
@@ -534,24 +535,10 @@ static const char *unpack(void)
534
535
unpacker [i ++ ] = hdr_arg ;
535
536
unpacker [i ++ ] = NULL ;
536
537
code = run_command_v_opt (unpacker , RUN_GIT_CMD );
537
- switch (code ) {
538
- case 0 :
538
+ if (!code )
539
539
return NULL ;
540
- case - ERR_RUN_COMMAND_FORK :
541
- return "unpack fork failed" ;
542
- case - ERR_RUN_COMMAND_EXEC :
543
- return "unpack execute failed" ;
544
- case - ERR_RUN_COMMAND_WAITPID :
545
- return "waitpid failed" ;
546
- case - ERR_RUN_COMMAND_WAITPID_WRONG_PID :
547
- return "waitpid is confused" ;
548
- case - ERR_RUN_COMMAND_WAITPID_SIGNAL :
549
- return "unpacker died of signal" ;
550
- case - ERR_RUN_COMMAND_WAITPID_NOEXIT :
551
- return "unpacker died strangely" ;
552
- default :
553
- return "unpacker exited with error code" ;
554
- }
540
+ run_status (code , unpacker [0 ]);
541
+ return "unpack-objects abnormal exit" ;
555
542
} else {
556
543
const char * keeper [7 ];
557
544
int s , status , i = 0 ;
@@ -574,15 +561,19 @@ static const char *unpack(void)
574
561
ip .argv = keeper ;
575
562
ip .out = -1 ;
576
563
ip .git_cmd = 1 ;
577
- if (start_command (& ip ))
564
+ status = start_command (& ip );
565
+ if (status ) {
566
+ run_status (status , keeper [0 ]);
578
567
return "index-pack fork failed" ;
568
+ }
579
569
pack_lockfile = index_pack_lockfile (ip .out );
580
570
close (ip .out );
581
571
status = finish_command (& ip );
582
572
if (!status ) {
583
573
reprepare_packed_git ();
584
574
return NULL ;
585
575
}
576
+ run_status (status , keeper [0 ]);
586
577
return "index-pack abnormal exit" ;
587
578
}
588
579
}
0 commit comments