@@ -182,9 +182,6 @@ struct command {
182182 char ref_name [FLEX_ARRAY ]; /* more */
183183};
184184
185- static const char pre_receive_hook [] = "hooks/pre-receive" ;
186- static const char post_receive_hook [] = "hooks/post-receive" ;
187-
188185static void rp_error (const char * err , ...) __attribute__((format (printf , 1 , 2 )));
189186static void rp_warning (const char * err , ...) __attribute__((format (printf , 1 , 2 )));
190187
@@ -242,10 +239,10 @@ static int run_and_feed_hook(const char *hook_name, feed_fn feed, void *feed_sta
242239 const char * argv [2 ];
243240 int code ;
244241
245- if (access (hook_name , X_OK ) < 0 )
242+ argv [0 ] = find_hook (hook_name );
243+ if (!argv [0 ])
246244 return 0 ;
247245
248- argv [0 ] = hook_name ;
249246 argv [1 ] = NULL ;
250247
251248 memset (& proc , 0 , sizeof (proc ));
@@ -331,15 +328,14 @@ static int run_receive_hook(struct command *commands, const char *hook_name,
331328
332329static int run_update_hook (struct command * cmd )
333330{
334- static const char update_hook [] = "hooks/update" ;
335331 const char * argv [5 ];
336332 struct child_process proc ;
337333 int code ;
338334
339- if (access (update_hook , X_OK ) < 0 )
335+ argv [0 ] = find_hook ("update" );
336+ if (!argv [0 ])
340337 return 0 ;
341338
342- argv [0 ] = update_hook ;
343339 argv [1 ] = cmd -> ref_name ;
344340 argv [2 ] = sha1_to_hex (cmd -> old_sha1 );
345341 argv [3 ] = sha1_to_hex (cmd -> new_sha1 );
@@ -532,24 +528,25 @@ static const char *update(struct command *cmd)
532528 }
533529}
534530
535- static char update_post_hook [] = "hooks/post-update" ;
536-
537531static void run_update_post_hook (struct command * commands )
538532{
539533 struct command * cmd ;
540534 int argc ;
541535 const char * * argv ;
542536 struct child_process proc ;
537+ char * hook ;
543538
539+ hook = find_hook ("post-update" );
544540 for (argc = 0 , cmd = commands ; cmd ; cmd = cmd -> next ) {
545541 if (cmd -> error_string || cmd -> did_not_exist )
546542 continue ;
547543 argc ++ ;
548544 }
549- if (!argc || access ( update_post_hook , X_OK ) < 0 )
545+ if (!argc || ! hook )
550546 return ;
547+
551548 argv = xmalloc (sizeof (* argv ) * (2 + argc ));
552- argv [0 ] = update_post_hook ;
549+ argv [0 ] = hook ;
553550
554551 for (argc = 1 , cmd = commands ; cmd ; cmd = cmd -> next ) {
555552 char * p ;
@@ -704,7 +701,7 @@ static void execute_commands(struct command *commands, const char *unpacker_erro
704701 0 , & cmd ))
705702 set_connectivity_errors (commands );
706703
707- if (run_receive_hook (commands , pre_receive_hook , 0 )) {
704+ if (run_receive_hook (commands , "pre-receive" , 0 )) {
708705 for (cmd = commands ; cmd ; cmd = cmd -> next ) {
709706 if (!cmd -> error_string )
710707 cmd -> error_string = "pre-receive hook declined" ;
@@ -994,7 +991,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
994991 unlink_or_warn (pack_lockfile );
995992 if (report_status )
996993 report (commands , unpack_status );
997- run_receive_hook (commands , post_receive_hook , 1 );
994+ run_receive_hook (commands , "post-receive" , 1 );
998995 run_update_post_hook (commands );
999996 if (auto_gc ) {
1000997 const char * argv_gc_auto [] = {
0 commit comments