summaryrefslogtreecommitdiff
path: root/run-command.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-12-30 22:42:43 -0800
committerJunio C Hamano <junkio@cox.net>2006-12-30 22:42:43 -0800
commit76d4e079adba461c127641a1104772a62e38cd81 (patch)
tree7a8e335ed577aff47b5a80d8de5a6d7904813c02 /run-command.c
parent2c039da804ee0542ff41d2f22a444d04a2d37856 (diff)
parenta862f97e98decc317437fa3b04081f68fb4ffbf3 (diff)
downloadgit-76d4e079adba461c127641a1104772a62e38cd81.tar.gz
Merge branch 'master' into sp/mmap
* master: Documentation/config.txt (and repo-config manpage): mark-up fix. Teach Git how to parse standard power of 2 suffixes. Use /dev/null for update hook stdin. Redirect update hook stdout to stderr. Remove unnecessary argc parameter from run_command_v. Automatically detect a bare git repository. Replace "GIT_DIR" with GIT_DIR_ENVIRONMENT. Use PATH_MAX constant for --bare. Force core.filemode to false on Cygwin. Fix formatting for urls section of fetch, pull, and push manpages Fix yet another subtle xdl_merge() bug i18n: drop "encoding" header in the output after re-coding. commit-tree: cope with different ways "utf-8" can be spelled. Move commit reencoding parameter parsing to revision.c Documentation: minor rewording for git-log and git-show pages. Documentation: i18n commit log message notes. t3900: test log --encoding=none commit re-encoding: fix confusion between no and default conversion.
Diffstat (limited to 'run-command.c')
-rw-r--r--run-command.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/run-command.c b/run-command.c
index 492ad3e64c..cfbad74d14 100644
--- a/run-command.c
+++ b/run-command.c
@@ -2,19 +2,20 @@
#include "run-command.h"
#include "exec_cmd.h"
-int run_command_v_opt(int argc, const char **argv, int flags)
+int run_command_v_opt(const char **argv, int flags)
{
pid_t pid = fork();
if (pid < 0)
return -ERR_RUN_COMMAND_FORK;
if (!pid) {
- if (flags & RUN_COMMAND_NO_STDIO) {
+ if (flags & RUN_COMMAND_NO_STDIN) {
int fd = open("/dev/null", O_RDWR);
dup2(fd, 0);
- dup2(fd, 1);
close(fd);
}
+ if (flags & RUN_COMMAND_STDOUT_TO_STDERR)
+ dup2(2, 1);
if (flags & RUN_GIT_CMD) {
execv_git_cmd(argv);
} else {
@@ -46,19 +47,17 @@ int run_command_v_opt(int argc, const char **argv, int flags)
}
}
-int run_command_v(int argc, const char **argv)
+int run_command_v(const char **argv)
{
- return run_command_v_opt(argc, argv, 0);
+ return run_command_v_opt(argv, 0);
}
-int run_command(const char *cmd, ...)
+static int run_command_va_opt(int opt, const char *cmd, va_list param)
{
int argc;
const char *argv[MAX_RUN_COMMAND_ARGS];
const char *arg;
- va_list param;
- va_start(param, cmd);
argv[0] = (char*) cmd;
argc = 1;
while (argc < MAX_RUN_COMMAND_ARGS) {
@@ -66,8 +65,29 @@ int run_command(const char *cmd, ...)
if (!arg)
break;
}
- va_end(param);
if (MAX_RUN_COMMAND_ARGS <= argc)
return error("too many args to run %s", cmd);
- return run_command_v_opt(argc, argv, 0);
+ return run_command_v_opt(argv, opt);
+}
+
+int run_command_opt(int opt, const char *cmd, ...)
+{
+ va_list params;
+ int r;
+
+ va_start(params, cmd);
+ r = run_command_va_opt(opt, cmd, params);
+ va_end(params);
+ return r;
+}
+
+int run_command(const char *cmd, ...)
+{
+ va_list params;
+ int r;
+
+ va_start(params, cmd);
+ r = run_command_va_opt(0, cmd, params);
+ va_end(params);
+ return r;
}