From: Johannes Sixt <j6t@kdbg.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Johannes Sixt <j6t@kdbg.org>
Subject: [PATCH 1/3] Simplify some instances of run_command() by using run_command_v_opt().
Date: Mon, 8 Jun 2009 22:34:29 +0200 [thread overview]
Message-ID: <e4b190906055eb86077ca3e7257c983befcfb511.1244492659.git.j6t@kdbg.org> (raw)
In-Reply-To: <cover.1244492658.git.j6t@kdbg.org>
In-Reply-To: <cover.1244492658.git.j6t@kdbg.org>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
builtin-receive-pack.c | 10 +++-------
ll-merge.c | 11 ++---------
merge-index.c | 42 +++++++++++++-----------------------------
3 files changed, 18 insertions(+), 45 deletions(-)
diff --git a/builtin-receive-pack.c b/builtin-receive-pack.c
index 0b08da9..33d345d 100644
--- a/builtin-receive-pack.c
+++ b/builtin-receive-pack.c
@@ -192,7 +192,6 @@ static int run_receive_hook(const char *hook_name)
static int run_update_hook(struct command *cmd)
{
static const char update_hook[] = "hooks/update";
- struct child_process proc;
const char *argv[5];
if (access(update_hook, X_OK) < 0)
@@ -204,12 +203,9 @@ static int run_update_hook(struct command *cmd)
argv[3] = sha1_to_hex(cmd->new_sha1);
argv[4] = NULL;
- memset(&proc, 0, sizeof(proc));
- proc.argv = argv;
- proc.no_stdin = 1;
- proc.stdout_to_stderr = 1;
-
- return hook_status(run_command(&proc), update_hook);
+ return hook_status(run_command_v_opt(argv, RUN_COMMAND_NO_STDIN |
+ RUN_COMMAND_STDOUT_TO_STDERR),
+ update_hook);
}
static int is_ref_checked_out(const char *ref)
diff --git a/ll-merge.c b/ll-merge.c
index 81c02ad..31d6f0a 100644
--- a/ll-merge.c
+++ b/ll-merge.c
@@ -175,8 +175,7 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
{ "B", temp[2] },
{ NULL }
};
- struct child_process child;
- const char *args[20];
+ const char *args[] = { "sh", "-c", NULL, NULL };
int status, fd, i;
struct stat st;
@@ -191,14 +190,8 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
strbuf_expand(&cmd, fn->cmdline, strbuf_expand_dict_cb, &dict);
- memset(&child, 0, sizeof(child));
- child.argv = args;
- args[0] = "sh";
- args[1] = "-c";
args[2] = cmd.buf;
- args[3] = NULL;
-
- status = run_command(&child);
+ status = run_command_v_opt(args, 0);
if (status < -ERR_RUN_COMMAND_FORK)
; /* failure in run-command */
else
diff --git a/merge-index.c b/merge-index.c
index aa9cf23..19ddd03 100644
--- a/merge-index.c
+++ b/merge-index.c
@@ -3,45 +3,20 @@
#include "exec_cmd.h"
static const char *pgm;
-static const char *arguments[9];
static int one_shot, quiet;
static int err;
-static void run_program(void)
-{
- struct child_process child;
- memset(&child, 0, sizeof(child));
- child.argv = arguments;
- if (run_command(&child)) {
- if (one_shot) {
- err++;
- } else {
- if (!quiet)
- die("merge program failed");
- exit(1);
- }
- }
-}
-
static int merge_entry(int pos, const char *path)
{
int found;
+ const char *arguments[] = { pgm, "", "", "", path, "", "", "", NULL };
+ char hexbuf[4][60];
+ char ownbuf[4][60];
if (pos >= active_nr)
die("git merge-index: %s not in the cache", path);
- arguments[0] = pgm;
- arguments[1] = "";
- arguments[2] = "";
- arguments[3] = "";
- arguments[4] = path;
- arguments[5] = "";
- arguments[6] = "";
- arguments[7] = "";
- arguments[8] = NULL;
found = 0;
do {
- static char hexbuf[4][60];
- static char ownbuf[4][60];
struct cache_entry *ce = active_cache[pos];
int stage = ce_stage(ce);
@@ -55,7 +30,16 @@ static int merge_entry(int pos, const char *path)
} while (++pos < active_nr);
if (!found)
die("git merge-index: %s not in the cache", path);
- run_program();
+
+ if (run_command_v_opt(arguments, 0)) {
+ if (one_shot)
+ err++;
+ else {
+ if (!quiet)
+ die("merge program failed");
+ exit(1);
+ }
+ }
return found;
}
--
1.6.3.17.g1665f
next prev parent reply other threads:[~2009-06-08 20:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-08 20:34 [PATCH 0/3] Miscellanous cleanups around start_command/run_command callers Johannes Sixt
2009-06-08 20:34 ` Johannes Sixt [this message]
2009-06-08 20:34 ` [PATCH 2/3] diff.c: plug a memory leak in an error path Johannes Sixt
2009-06-08 20:34 ` [PATCH 3/3] Simplify some 'fprintf(stderr); return -1;' by using 'return error()' Johannes Sixt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e4b190906055eb86077ca3e7257c983befcfb511.1244492659.git.j6t@kdbg.org \
--to=j6t@kdbg.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).