Skip to content

Commit e1464ca

Browse files
Johannes Sixtgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 46beb55 commit e1464ca

File tree

6 files changed

+16
-10
lines changed

6 files changed

+16
-10
lines changed

exec_cmd.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
extern char **environ;
77
static const char *argv_exec_path;
8+
static const char *argv0_path;
89

910
static const char *builtin_exec_path(void)
1011
{
@@ -50,6 +51,11 @@ const char *system_path(const char *path)
5051
return path;
5152
}
5253

54+
void git_set_argv0_path(const char *path)
55+
{
56+
argv0_path = path;
57+
}
58+
5359
void git_set_argv_exec_path(const char *exec_path)
5460
{
5561
argv_exec_path = exec_path;
@@ -84,7 +90,7 @@ static void add_path(struct strbuf *out, const char *path)
8490
}
8591
}
8692

87-
void setup_path(const char *cmd_path)
93+
void setup_path(void)
8894
{
8995
const char *old_path = getenv("PATH");
9096
struct strbuf new_path;
@@ -94,7 +100,7 @@ void setup_path(const char *cmd_path)
94100
add_path(&new_path, argv_exec_path);
95101
add_path(&new_path, getenv(EXEC_PATH_ENVIRONMENT));
96102
add_path(&new_path, builtin_exec_path());
97-
add_path(&new_path, cmd_path);
103+
add_path(&new_path, argv0_path);
98104

99105
if (old_path)
100106
strbuf_addstr(&new_path, old_path);

exec_cmd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
#define GIT_EXEC_CMD_H
33

44
extern void git_set_argv_exec_path(const char *exec_path);
5+
extern void git_set_argv0_path(const char *path);
56
extern const char* git_exec_path(void);
6-
extern void setup_path(const char *);
7+
extern void setup_path(void);
78
extern int execv_git_cmd(const char **argv); /* NULL terminated */
89
extern int execl_git_cmd(const char *cmd, ...);
910
extern const char *system_path(const char *path);

git.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ int main(int argc, const char **argv)
418418
{
419419
const char *cmd = argv[0] && *argv[0] ? argv[0] : "git-help";
420420
char *slash = (char *)cmd + strlen(cmd);
421-
const char *cmd_path = NULL;
422421
int done_alias = 0;
423422

424423
/*
@@ -431,7 +430,7 @@ int main(int argc, const char **argv)
431430
while (cmd <= slash && !is_dir_sep(*slash));
432431
if (cmd <= slash) {
433432
*slash++ = 0;
434-
cmd_path = cmd;
433+
git_set_argv0_path(cmd);
435434
cmd = slash;
436435
}
437436

@@ -475,7 +474,7 @@ int main(int argc, const char **argv)
475474
* environment, and the $(gitexecdir) from the Makefile at build
476475
* time.
477476
*/
478-
setup_path(cmd_path);
477+
setup_path();
479478

480479
while (1) {
481480
/* See if it's an internal command */

receive-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ int main(int argc, char **argv)
482482
if (!dir)
483483
usage(receive_pack_usage);
484484

485-
setup_path(NULL);
485+
setup_path();
486486

487487
if (!enter_repo(dir, 0))
488488
die("'%s': unable to chdir or not a git archive", dir);

shell.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ static int do_generic_cmd(const char *me, char *arg)
1515
{
1616
const char *my_argv[4];
1717

18-
setup_path(NULL);
18+
setup_path();
1919
if (!arg || !(arg = sq_dequote(arg)))
2020
die("bad argument");
2121
if (prefixcmp(me, "git-"))
@@ -37,7 +37,7 @@ static int do_cvs_cmd(const char *me, char *arg)
3737
if (!arg || strcmp(arg, "server"))
3838
die("git-cvsserver only handles server: %s", arg);
3939

40-
setup_path(NULL);
40+
setup_path();
4141
return execv_git_cmd(cvsserver_argv);
4242
}
4343

upload-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ int main(int argc, char **argv)
638638
if (i != argc-1)
639639
usage(upload_pack_usage);
640640

641-
setup_path(NULL);
641+
setup_path();
642642

643643
dir = argv[i];
644644

0 commit comments

Comments
 (0)