Merge branch 'sg/completion-no-column' into maint
[gitweb.git] / run-command.c
index fe116bc2b144cfa59204745a9667fd1bbd239508..84e4ce66e9d3da22be318813d75cbb3a94b614e4 100644 (file)
@@ -11,6 +11,12 @@ void child_process_init(struct child_process *child)
        argv_array_init(&child->env_array);
 }
 
+void child_process_clear(struct child_process *child)
+{
+       argv_array_clear(&child->args);
+       argv_array_clear(&child->env_array);
+}
+
 struct child_to_clean {
        pid_t pid;
        struct child_to_clean *next;
@@ -201,7 +207,6 @@ static int execv_shell_cmd(const char **argv)
 #endif
 
 #ifndef GIT_WINDOWS_NATIVE
-static int child_err = 2;
 static int child_notifier = -1;
 
 static void notify_parent(void)
@@ -213,17 +218,6 @@ static void notify_parent(void)
         */
        xwrite(child_notifier, "", 1);
 }
-
-static NORETURN void die_child(const char *err, va_list params)
-{
-       vwritef(child_err, "fatal: ", err, params);
-       exit(128);
-}
-
-static void error_child(const char *err, va_list params)
-{
-       vwritef(child_err, "error: ", err, params);
-}
 #endif
 
 static inline void set_cloexec(int fd)
@@ -339,8 +333,7 @@ int start_command(struct child_process *cmd)
 fail_pipe:
                        error("cannot create %s pipe for %s: %s",
                                str, cmd->argv[0], strerror(failed_errno));
-                       argv_array_clear(&cmd->args);
-                       argv_array_clear(&cmd->env_array);
+                       child_process_clear(cmd);
                        errno = failed_errno;
                        return -1;
                }
@@ -365,11 +358,10 @@ int start_command(struct child_process *cmd)
                 * in subsequent call paths use the parent's stderr.
                 */
                if (cmd->no_stderr || need_err) {
-                       child_err = dup(2);
+                       int child_err = dup(2);
                        set_cloexec(child_err);
+                       set_error_handle(fdopen(child_err, "w"));
                }
-               set_die_routine(die_child);
-               set_error_routine(error_child);
 
                close(notify_pipe[0]);
                set_cloexec(notify_pipe[1]);
@@ -526,8 +518,7 @@ int start_command(struct child_process *cmd)
                        close_pair(fderr);
                else if (cmd->err)
                        close(cmd->err);
-               argv_array_clear(&cmd->args);
-               argv_array_clear(&cmd->env_array);
+               child_process_clear(cmd);
                errno = failed_errno;
                return -1;
        }
@@ -553,8 +544,7 @@ int start_command(struct child_process *cmd)
 int finish_command(struct child_process *cmd)
 {
        int ret = wait_or_whine(cmd->pid, cmd->argv[0], 0);
-       argv_array_clear(&cmd->args);
-       argv_array_clear(&cmd->env_array);
+       child_process_clear(cmd);
        return ret;
 }
 
@@ -806,11 +796,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)