From 15048f8a9ace23df67161746ca76b4f46114deee Mon Sep 17 00:00:00 2001 From: Benoit Pierre Date: Tue, 18 Mar 2014 11:00:53 +0100 Subject: commit: fix patch hunk editing with "commit -p -m" Don't change git environment: move the GIT_EDITOR=":" override to the hook command subprocess, like it's already done for GIT_INDEX_FILE. Signed-off-by: Benoit Pierre Signed-off-by: Junio C Hamano --- run-command.c | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) (limited to 'run-command.c') diff --git a/run-command.c b/run-command.c index 3914d9c511..75abc478c6 100644 --- a/run-command.c +++ b/run-command.c @@ -760,13 +760,11 @@ char *find_hook(const char *name) return path; } -int run_hook(const char *index_file, const char *name, ...) +int run_hook_ve(const char *const *env, const char *name, va_list args) { struct child_process hook; struct argv_array argv = ARGV_ARRAY_INIT; - const char *p, *env[2]; - char index[PATH_MAX]; - va_list args; + const char *p; int ret; p = find_hook(name); @@ -775,23 +773,45 @@ int run_hook(const char *index_file, const char *name, ...) argv_array_push(&argv, p); - va_start(args, name); while ((p = va_arg(args, const char *))) argv_array_push(&argv, p); - va_end(args); memset(&hook, 0, sizeof(hook)); hook.argv = argv.argv; + hook.env = env; hook.no_stdin = 1; hook.stdout_to_stderr = 1; - if (index_file) { - snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file); - env[0] = index; - env[1] = NULL; - hook.env = env; - } ret = run_command(&hook); argv_array_clear(&argv); return ret; } + +int run_hook_le(const char *const *env, const char *name, ...) +{ + va_list args; + int ret; + + va_start(args, name); + ret = run_hook_ve(env, name, args); + va_end(args); + + return ret; +} + +int run_hook_with_custom_index(const char *index_file, const char *name, ...) +{ + const char *hook_env[3] = { NULL }; + char index[PATH_MAX]; + va_list args; + int ret; + + snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file); + hook_env[0] = index; + + va_start(args, name); + ret = run_hook_ve(hook_env, name, args); + va_end(args); + + return ret; +} -- cgit v1.2.3