summaryrefslogtreecommitdiff
path: root/exec_cmd.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2007-12-01 22:09:22 -0800
committerJunio C Hamano <gitster@pobox.com>2008-06-23 22:45:41 -0700
commit7550be0a2bbf47aaa63c806bb5d7fcb8ab197cf8 (patch)
tree6039b53ba7b8b3bbd425113734c0a9996eed4d37 /exec_cmd.c
parent0a47dc110e042b5bcc63dc94c8d517e67efe9306 (diff)
downloadgit-7550be0a2bbf47aaa63c806bb5d7fcb8ab197cf8.tar.gz
Prepare execv_git_cmd() for removal of builtins from the filesystem
Currently, execv_git_cmd() always try running the dashed form, which means we cannot easily remove the git-foo hardlinks for built-in commands. This updates the function to always exec "git foo" form, and makes sure "git" potty does not infinitely recurse to itself. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'exec_cmd.c')
-rw-r--r--exec_cmd.c31
1 files changed, 12 insertions, 19 deletions
diff --git a/exec_cmd.c b/exec_cmd.c
index e189caca62..0f8f4b5b7d 100644
--- a/exec_cmd.c
+++ b/exec_cmd.c
@@ -65,32 +65,25 @@ void setup_path(const char *cmd_path)
int execv_git_cmd(const char **argv)
{
- struct strbuf cmd;
- const char *tmp;
-
- strbuf_init(&cmd, 0);
- strbuf_addf(&cmd, "git-%s", argv[0]);
+ int argc;
+ const char **nargv;
- /*
- * argv[0] must be the git command, but the argv array
- * belongs to the caller, and may be reused in
- * subsequent loop iterations. Save argv[0] and
- * restore it on error.
- */
- tmp = argv[0];
- argv[0] = cmd.buf;
+ for (argc = 0; argv[argc]; argc++)
+ ; /* just counting */
+ nargv = xmalloc(sizeof(*nargv) * (argc + 2));
- trace_argv_printf(argv, "trace: exec:");
+ nargv[0] = "git";
+ for (argc = 0; argv[argc]; argc++)
+ nargv[argc + 1] = argv[argc];
+ nargv[argc + 1] = NULL;
+ trace_argv_printf(nargv, "trace: exec:");
/* execvp() can only ever return if it fails */
- execvp(cmd.buf, (char **)argv);
+ execvp("git", (char **)nargv);
trace_printf("trace: exec failed: %s\n", strerror(errno));
- argv[0] = tmp;
-
- strbuf_release(&cmd);
-
+ free(nargv);
return -1;
}