summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--run-command.c10
-rw-r--r--run-command.h5
2 files changed, 11 insertions, 4 deletions
diff --git a/run-command.c b/run-command.c
index 4d73e90fad..28e1d55cb9 100644
--- a/run-command.c
+++ b/run-command.c
@@ -797,11 +797,13 @@ int finish_async(struct async *async)
const char *find_hook(const char *name)
{
- const char *path = git_path("hooks/%s", name);
- if (access(path, X_OK) < 0)
- path = NULL;
+ static struct strbuf path = STRBUF_INIT;
- return path;
+ strbuf_reset(&path);
+ strbuf_git_path(&path, "hooks/%s", name);
+ if (access(path.buf, X_OK) < 0)
+ return NULL;
+ return path.buf;
}
int run_hook_ve(const char *const *env, const char *name, va_list args)
diff --git a/run-command.h b/run-command.h
index 1103805af1..5b4425a3cb 100644
--- a/run-command.h
+++ b/run-command.h
@@ -52,6 +52,11 @@ int start_command(struct child_process *);
int finish_command(struct child_process *);
int run_command(struct child_process *);
+/*
+ * Returns the path to the hook file, or NULL if the hook is missing
+ * or disabled. Note that this points to static storage that will be
+ * overwritten by further calls to find_hook and run_hook_*.
+ */
extern const char *find_hook(const char *name);
LAST_ARG_MUST_BE_NULL
extern int run_hook_le(const char *const *env, const char *name, ...);