X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=git.c;h=4616df6e62de5fb2f4a22ebb04fb87664579bb84;hb=2718435b7b746c3c249525b02fbcbad68f5a45f3;hp=e795ddb8106138920ad02793c4f4b787e05fb4f4;hpb=c63da8d8e8c5b5078e59af15c1a41ff98ad61d59;p=git.git diff --git a/git.c b/git.c index e795ddb8..4616df6e 100644 --- a/git.c +++ b/git.c @@ -10,6 +10,7 @@ #include #include #include "git-compat-util.h" +#include "exec_cmd.h" #ifndef PATH_MAX # define PATH_MAX 4096 @@ -233,17 +234,19 @@ int main(int argc, char **argv, char **envp) { char git_command[PATH_MAX + 1]; char wd[PATH_MAX + 1]; - int i, len, show_help = 0; - char *exec_path = getenv("GIT_EXEC_PATH"); + int i, show_help = 0; + const char *exec_path; getcwd(wd, PATH_MAX); - if (!exec_path) - exec_path = GIT_EXEC_PATH; - for (i = 1; i < argc; i++) { char *arg = argv[i]; + if (!strcmp(arg, "help")) { + show_help = 1; + continue; + } + if (strncmp(arg, "--", 2)) break; @@ -251,10 +254,11 @@ int main(int argc, char **argv, char **envp) if (!strncmp(arg, "exec-path", 9)) { arg += 9; - if (*arg == '=') + if (*arg == '=') { exec_path = arg + 1; - else { - puts(exec_path); + git_set_exec_path(exec_path); + } else { + puts(git_exec_path()); exit(0); } } @@ -270,42 +274,15 @@ int main(int argc, char **argv, char **envp) if (i >= argc || show_help) { if (i >= argc) - cmd_usage(exec_path, NULL); + cmd_usage(git_exec_path(), NULL); show_man_page(argv[i]); } - if (*exec_path != '/') { - if (!getcwd(git_command, sizeof(git_command))) { - fprintf(stderr, - "git: cannot determine current directory\n"); - exit(1); - } - len = strlen(git_command); - - /* Trivial cleanup */ - while (!strncmp(exec_path, "./", 2)) { - exec_path += 2; - while (*exec_path == '/') - exec_path++; - } - snprintf(git_command + len, sizeof(git_command) - len, - "/%s", exec_path); - } - else - strcpy(git_command, exec_path); - len = strlen(git_command); - prepend_to_path(git_command, len); - - len += snprintf(git_command + len, sizeof(git_command) - len, - "/git-%s", argv[i]); - if (sizeof(git_command) <= len) { - fprintf(stderr, "git: command name given is too long.\n"); - exit(1); - } + exec_path = git_exec_path(); + prepend_to_path(exec_path, strlen(exec_path)); - /* execve() can only ever return if it fails */ - execve(git_command, &argv[i], envp); + execv_git_cmd(argv + i); if (errno == ENOENT) cmd_usage(exec_path, "'%s' is not a git-command", argv[i]);