@@ -123,27 +123,27 @@ static struct command *commands;
123123static const char pre_receive_hook [] = "hooks/pre-receive" ;
124124static const char post_receive_hook [] = "hooks/post-receive" ;
125125
126- static int hook_status (int code , const char * hook_name )
126+ static int run_status (int code , const char * cmd_name )
127127{
128128 switch (code ) {
129129 case 0 :
130130 return 0 ;
131131 case - ERR_RUN_COMMAND_FORK :
132- return error ("hook fork failed" );
132+ return error ("fork of %s failed" , cmd_name );
133133 case - ERR_RUN_COMMAND_EXEC :
134- return error ("hook execute failed" );
134+ return error ("execute of %s failed" , cmd_name );
135135 case - ERR_RUN_COMMAND_PIPE :
136- return error ("hook pipe failed" );
136+ return error ("pipe failed" );
137137 case - ERR_RUN_COMMAND_WAITPID :
138138 return error ("waitpid failed" );
139139 case - ERR_RUN_COMMAND_WAITPID_WRONG_PID :
140140 return error ("waitpid is confused" );
141141 case - ERR_RUN_COMMAND_WAITPID_SIGNAL :
142- return error ("%s died of signal" , hook_name );
142+ return error ("%s died of signal" , cmd_name );
143143 case - ERR_RUN_COMMAND_WAITPID_NOEXIT :
144- return error ("%s died strangely" , hook_name );
144+ return error ("%s died strangely" , cmd_name );
145145 default :
146- error ("%s exited with error code %d" , hook_name , - code );
146+ error ("%s exited with error code %d" , cmd_name , - code );
147147 return - code ;
148148 }
149149}
@@ -174,7 +174,7 @@ static int run_receive_hook(const char *hook_name)
174174
175175 code = start_command (& proc );
176176 if (code )
177- return hook_status (code , hook_name );
177+ return run_status (code , hook_name );
178178 for (cmd = commands ; cmd ; cmd = cmd -> next ) {
179179 if (!cmd -> error_string ) {
180180 size_t n = snprintf (buf , sizeof (buf ), "%s %s %s\n" ,
@@ -186,7 +186,7 @@ static int run_receive_hook(const char *hook_name)
186186 }
187187 }
188188 close (proc .in );
189- return hook_status (finish_command (& proc ), hook_name );
189+ return run_status (finish_command (& proc ), hook_name );
190190}
191191
192192static int run_update_hook (struct command * cmd )
@@ -203,7 +203,7 @@ static int run_update_hook(struct command *cmd)
203203 argv [3 ] = sha1_to_hex (cmd -> new_sha1 );
204204 argv [4 ] = NULL ;
205205
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 |
207207 RUN_COMMAND_STDOUT_TO_STDERR ),
208208 update_hook );
209209}
@@ -394,7 +394,7 @@ static char update_post_hook[] = "hooks/post-update";
394394static void run_update_post_hook (struct command * cmd )
395395{
396396 struct command * cmd_p ;
397- int argc ;
397+ int argc , status ;
398398 const char * * argv ;
399399
400400 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)
417417 argc ++ ;
418418 }
419419 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 );
422423}
423424
424425static void execute_commands (const char * unpacker_error )
@@ -534,24 +535,10 @@ static const char *unpack(void)
534535 unpacker [i ++ ] = hdr_arg ;
535536 unpacker [i ++ ] = NULL ;
536537 code = run_command_v_opt (unpacker , RUN_GIT_CMD );
537- switch (code ) {
538- case 0 :
538+ if (!code )
539539 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" ;
555542 } else {
556543 const char * keeper [7 ];
557544 int s , status , i = 0 ;
@@ -574,15 +561,19 @@ static const char *unpack(void)
574561 ip .argv = keeper ;
575562 ip .out = -1 ;
576563 ip .git_cmd = 1 ;
577- if (start_command (& ip ))
564+ status = start_command (& ip );
565+ if (status ) {
566+ run_status (status , keeper [0 ]);
578567 return "index-pack fork failed" ;
568+ }
579569 pack_lockfile = index_pack_lockfile (ip .out );
580570 close (ip .out );
581571 status = finish_command (& ip );
582572 if (!status ) {
583573 reprepare_packed_git ();
584574 return NULL ;
585575 }
576+ run_status (status , keeper [0 ]);
586577 return "index-pack abnormal exit" ;
587578 }
588579}
0 commit comments