From: Aaron Schrab <aaron@schrab.com>
To: git@vger.kernel.org
Subject: [PATCH 1/4] hooks: Add function to check if a hook exists
Date: Fri, 28 Dec 2012 17:57:29 -0500 [thread overview]
Message-ID: <1356735452-21667-2-git-send-email-aaron@schrab.com> (raw)
In-Reply-To: <1356735452-21667-1-git-send-email-aaron@schrab.com>
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 is in support for an upcoming run_hook_argv() function which will
expect the full path to the hook script as the first element in the
argv_array. 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, or immediately added to an argv_array list
which would result in it being duplicated at that point.
Signed-off-by: Aaron Schrab <aaron@schrab.com>
---
run-command.c | 15 +++++++++++++--
run-command.h | 1 +
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/run-command.c b/run-command.c
index 3b982e4..49c8fa0 100644
--- a/run-command.c
+++ b/run-command.c
@@ -735,6 +735,15 @@ int finish_async(struct async *async)
#endif
}
+char *find_hook(const char *name)
+{
+ char *path = git_path("hooks/%s", name);
+ if (access(path, X_OK) < 0)
+ path = NULL;
+
+ return path;
+}
+
int run_hook(const char *index_file, const char *name, ...)
{
struct child_process hook;
@@ -744,11 +753,13 @@ int run_hook(const char *index_file, const char *name, ...)
va_list args;
int ret;
- if (access(git_path("hooks/%s", name), X_OK) < 0)
+ p = find_hook(name);
+ if (!p)
return 0;
+ argv_array_push(&argv, p);
+
va_start(args, name);
- argv_array_push(&argv, git_path("hooks/%s", name));
while ((p = va_arg(args, const char *)))
argv_array_push(&argv, p);
va_end(args);
diff --git a/run-command.h b/run-command.h
index 850c638..221ce33 100644
--- a/run-command.h
+++ b/run-command.h
@@ -45,6 +45,7 @@ int start_command(struct child_process *);
int finish_command(struct child_process *);
int run_command(struct child_process *);
+extern char *find_hook(const char *name);
extern int run_hook(const char *index_file, const char *name, ...);
#define RUN_COMMAND_NO_STDIN 1
--
1.7.10.4
next prev parent reply other threads:[~2012-12-28 22:58 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-28 22:57 [PATCH 0/4] pre-push hook support Aaron Schrab
2012-12-28 22:57 ` Aaron Schrab [this message]
2012-12-29 2:08 ` [PATCH 1/4] hooks: Add function to check if a hook exists Junio C Hamano
2012-12-29 14:50 ` Aaron Schrab
2012-12-29 16:54 ` Junio C Hamano
2012-12-28 22:57 ` [PATCH 2/4] hooks: support variable number of parameters Aaron Schrab
2012-12-28 22:57 ` [PATCH 3/4] push: Add support for pre-push hooks Aaron Schrab
2012-12-28 22:57 ` [PATCH 4/4] Add sample pre-push hook script Aaron Schrab
2012-12-29 2:01 ` [PATCH 0/4] pre-push hook support Junio C Hamano
2012-12-29 14:50 ` Aaron Schrab
2012-12-29 16:48 ` Junio C Hamano
2013-01-13 5:17 ` [PATCH v2 0/3] " Aaron Schrab
2013-01-14 17:42 ` Junio C Hamano
2013-01-14 22:54 ` Junio C Hamano
2013-01-15 0:24 ` Junio C Hamano
2013-01-13 5:17 ` [PATCH v2 1/3] hooks: Add function to check if a hook exists Aaron Schrab
2013-01-13 5:17 ` [PATCH v2 2/3] push: Add support for pre-push hooks Aaron Schrab
2013-01-14 17:39 ` Junio C Hamano
2013-01-15 0:36 ` Junio C Hamano
2013-01-15 3:12 ` Junio C Hamano
2013-01-13 5:17 ` [PATCH v2 3/3] Add sample pre-push hook script Aaron Schrab
2013-01-14 17:42 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1356735452-21667-2-git-send-email-aaron@schrab.com \
--to=aaron@schrab.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).