@matheusbsbs / matheus-bagliano / commits / e1464ca7bb
Fork 0

Record the command invocation path early

We will need the command invocation path in system_path(). This path was passed to setup_path(), but system_path() can be called earlier, for example via: main commit_pager_choice setup_pager git_config git_etc_gitconfig system_path Therefore, we introduce git_set_argv0_path() and call it as soon as possible. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Sixt committed Jul 21, 2008 at 21:19 UTC e1464ca7bb0d705210ba7198f004b2fb2b807e12
6 files changed +16 -10
exec_cmd.c
+8 -2
@@ -5,6 +5,7 @@
5
6 extern char **environ;
7 static const char *argv_exec_path;
8 +static const char *argv0_path;
9
10 static const char *builtin_exec_path(void)
11 {
@@ -50,6 +51,11 @@ const char *system_path(const char *path)
51 return path;
52 }
53
54 +void git_set_argv0_path(const char *path)
55 +{
56 + argv0_path = path;
57 +}
58 +
59 void git_set_argv_exec_path(const char *exec_path)
60 {
61 argv_exec_path = exec_path;
@@ -84,7 +90,7 @@ static void add_path(struct strbuf *out, const char *path)
90 }
91 }
92
87 -void setup_path(const char *cmd_path)
93 +void setup_path(void)
94 {
95 const char *old_path = getenv("PATH");
96 struct strbuf new_path;
@@ -94,7 +100,7 @@ void setup_path(const char *cmd_path)
100 add_path(&new_path, argv_exec_path);
101 add_path(&new_path, getenv(EXEC_PATH_ENVIRONMENT));
102 add_path(&new_path, builtin_exec_path());
97 - add_path(&new_path, cmd_path);
103 + add_path(&new_path, argv0_path);
104
105 if (old_path)
106 strbuf_addstr(&new_path, old_path);
exec_cmd.h
+2 -1
@@ -2,8 +2,9 @@
2 #define GIT_EXEC_CMD_H
3
4 extern void git_set_argv_exec_path(const char *exec_path);
5 +extern void git_set_argv0_path(const char *path);
6 extern const char* git_exec_path(void);
6 -extern void setup_path(const char *);
7 +extern void setup_path(void);
8 extern int execv_git_cmd(const char **argv); /* NULL terminated */
9 extern int execl_git_cmd(const char *cmd, ...);
10 extern const char *system_path(const char *path);
git.c
+2 -3
@@ -418,7 +418,6 @@ int main(int argc, const char **argv)
418 {
419 const char *cmd = argv[0] && *argv[0] ? argv[0] : "git-help";
420 char *slash = (char *)cmd + strlen(cmd);
421 - const char *cmd_path = NULL;
421 int done_alias = 0;
422
423 /*
@@ -431,7 +430,7 @@ int main(int argc, const char **argv)
430 while (cmd <= slash && !is_dir_sep(*slash));
431 if (cmd <= slash) {
432 *slash++ = 0;
434 - cmd_path = cmd;
433 + git_set_argv0_path(cmd);
434 cmd = slash;
435 }
436
@@ -475,7 +474,7 @@ int main(int argc, const char **argv)
474 * environment, and the $(gitexecdir) from the Makefile at build
475 * time.
476 */
478 - setup_path(cmd_path);
477 + setup_path();
478
479 while (1) {
480 /* See if it's an internal command */
receive-pack.c
+1 -1
@@ -482,7 +482,7 @@ int main(int argc, char **argv)
482 if (!dir)
483 usage(receive_pack_usage);
484
485 - setup_path(NULL);
485 + setup_path();
486
487 if (!enter_repo(dir, 0))
488 die("'%s': unable to chdir or not a git archive", dir);
shell.c
+2 -2
@@ -15,7 +15,7 @@ static int do_generic_cmd(const char *me, char *arg)
15 {
16 const char *my_argv[4];
17
18 - setup_path(NULL);
18 + setup_path();
19 if (!arg || !(arg = sq_dequote(arg)))
20 die("bad argument");
21 if (prefixcmp(me, "git-"))
@@ -37,7 +37,7 @@ static int do_cvs_cmd(const char *me, char *arg)
37 if (!arg || strcmp(arg, "server"))
38 die("git-cvsserver only handles server: %s", arg);
39
40 - setup_path(NULL);
40 + setup_path();
41 return execv_git_cmd(cvsserver_argv);
42 }
43
upload-pack.c
+1 -1
@@ -638,7 +638,7 @@ int main(int argc, char **argv)
638 if (i != argc-1)
639 usage(upload_pack_usage);
640
641 - setup_path(NULL);
641 + setup_path();
642
643 dir = argv[i];
644