Documentation/git-bisect.txt: git bisect term → git bisect terms
[gitweb.git] / run-command.c
index 0b432cc9713251b4d116bedf52ae1f51bd9d80cf..4d73e90fad159184bfdd204b82dd8637ad28a955 100644 (file)
@@ -4,10 +4,6 @@
 #include "sigchain.h"
 #include "argv-array.h"
 
-#ifndef SHELL_PATH
-# define SHELL_PATH "/bin/sh"
-#endif
-
 void child_process_init(struct child_process *child)
 {
        memset(child, 0, sizeof(*child));
@@ -561,7 +557,12 @@ int finish_command(struct child_process *cmd)
 
 int run_command(struct child_process *cmd)
 {
-       int code = start_command(cmd);
+       int code;
+
+       if (cmd->out < 0 || cmd->err < 0)
+               die("BUG: run_command with a pipe can cause deadlock");
+
+       code = start_command(cmd);
        if (code)
                return code;
        return finish_command(cmd);
@@ -794,9 +795,9 @@ int finish_async(struct async *async)
 #endif
 }
 
-char *find_hook(const char *name)
+const char *find_hook(const char *name)
 {
-       char *path = git_path("hooks/%s", name);
+       const char *path = git_path("hooks/%s", name);
        if (access(path, X_OK) < 0)
                path = NULL;
 
@@ -833,3 +834,19 @@ int run_hook_le(const char *const *env, const char *name, ...)
 
        return ret;
 }
+
+int capture_command(struct child_process *cmd, struct strbuf *buf, size_t hint)
+{
+       cmd->out = -1;
+       if (start_command(cmd) < 0)
+               return -1;
+
+       if (strbuf_read(buf, cmd->out, hint) < 0) {
+               close(cmd->out);
+               finish_command(cmd); /* throw away exit code */
+               return -1;
+       }
+
+       close(cmd->out);
+       return finish_command(cmd);
+}