diff options
author | Aaron Schrab <aaron@schrab.com> | 2013-01-13 00:17:02 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-01-14 09:25:40 -0800 |
commit | 5a7da2dca166fab74f4514697e26dd80e79933f5 (patch) | |
tree | d00b416154fd3790e7cf23592f6d8815dec8eb4b /builtin/commit.c | |
parent | 94702dd1ac27618b60198f7c8bceafaaaf7743e2 (diff) | |
download | git-5a7da2dca166fab74f4514697e26dd80e79933f5.tar.gz git-5a7da2dca166fab74f4514697e26dd80e79933f5.tar.xz |
hooks: Add function to check if a hook exists
Create find_hook() function to determine if a given hook exists and is
executable. If it is, the path to the script will be returned,
otherwise NULL is returned.
This encapsulates the tests that are used to check for the existence of
a hook in one place, making it easier to modify those checks if that is
found to be necessary. This also makes it simple for places that can
use a hook to check if a hook exists before doing, possibly lengthy,
setup work which would be pointless if no such hook is present.
The returned value is left as a static value from get_pathname() rather
than a duplicate because it is anticipated that the return value will
either be used as a boolean, immediately added to an argv_array list
which would result in it being duplicated at that point, or used to
actually run the command without much intervening work. Callers which
need to hold onto the returned value for a longer time are expected to
duplicate the return value themselves.
Signed-off-by: Aaron Schrab <aaron@schrab.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/commit.c')
-rw-r--r-- | builtin/commit.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/builtin/commit.c b/builtin/commit.c index d6dd3df8b..65d08d21f 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1327,8 +1327,6 @@ static int git_commit_config(const char *k, const char *v, void *cb) return git_status_config(k, v, s); } -static const char post_rewrite_hook[] = "hooks/post-rewrite"; - static int run_rewrite_hook(const unsigned char *oldsha1, const unsigned char *newsha1) { @@ -1339,10 +1337,10 @@ static int run_rewrite_hook(const unsigned char *oldsha1, int code; size_t n; - if (access(git_path(post_rewrite_hook), X_OK) < 0) + argv[0] = find_hook("post-rewrite"); + if (!argv[0]) return 0; - argv[0] = git_path(post_rewrite_hook); argv[1] = "amend"; argv[2] = NULL; |