replace: die early if replace ref already exists
[gitweb.git] / run-command.c
index 1b7f88eeb1f1971f1568d5991978192c2d00645e..75abc478c6da75471e5fdbb55c74efdfcf3ad160 100644 (file)
@@ -406,13 +406,12 @@ int start_command(struct child_process *cmd)
                                        unsetenv(*cmd->env);
                        }
                }
-               if (cmd->git_cmd) {
+               if (cmd->git_cmd)
                        execv_git_cmd(cmd->argv);
-               } else if (cmd->use_shell) {
+               else if (cmd->use_shell)
                        execv_shell_cmd(cmd->argv);
-               } else {
+               else
                        sane_execvp(cmd->argv[0], (char *const*) cmd->argv);
-               }
                if (errno == ENOENT) {
                        if (!cmd->silent_exec_failure)
                                error("cannot run %s: %s", cmd->argv[0],
@@ -446,7 +445,6 @@ int start_command(struct child_process *cmd)
                cmd->pid = -1;
        }
        close(notify_pipe[0]);
-
 }
 #else
 {
@@ -480,11 +478,10 @@ int start_command(struct child_process *cmd)
        if (cmd->env)
                env = make_augmented_environ(cmd->env);
 
-       if (cmd->git_cmd) {
+       if (cmd->git_cmd)
                cmd->argv = prepare_git_cmd(cmd->argv);
-       } else if (cmd->use_shell) {
+       else if (cmd->use_shell)
                cmd->argv = prepare_shell_cmd(cmd->argv);
-       }
 
        cmd->pid = mingw_spawnvpe(cmd->argv[0], cmd->argv, env, cmd->dir,
                                  fhin, fhout, fherr);
@@ -763,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);
@@ -778,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;
+}