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>
This commit is contained in:
parent
46beb55988
commit
e1464ca7bb
10
exec_cmd.c
10
exec_cmd.c
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
extern char **environ;
|
extern char **environ;
|
||||||
static const char *argv_exec_path;
|
static const char *argv_exec_path;
|
||||||
|
static const char *argv0_path;
|
||||||
|
|
||||||
static const char *builtin_exec_path(void)
|
static const char *builtin_exec_path(void)
|
||||||
{
|
{
|
||||||
@ -50,6 +51,11 @@ const char *system_path(const char *path)
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void git_set_argv0_path(const char *path)
|
||||||
|
{
|
||||||
|
argv0_path = path;
|
||||||
|
}
|
||||||
|
|
||||||
void git_set_argv_exec_path(const char *exec_path)
|
void git_set_argv_exec_path(const char *exec_path)
|
||||||
{
|
{
|
||||||
argv_exec_path = exec_path;
|
argv_exec_path = exec_path;
|
||||||
@ -84,7 +90,7 @@ static void add_path(struct strbuf *out, const char *path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup_path(const char *cmd_path)
|
void setup_path(void)
|
||||||
{
|
{
|
||||||
const char *old_path = getenv("PATH");
|
const char *old_path = getenv("PATH");
|
||||||
struct strbuf new_path;
|
struct strbuf new_path;
|
||||||
@ -94,7 +100,7 @@ void setup_path(const char *cmd_path)
|
|||||||
add_path(&new_path, argv_exec_path);
|
add_path(&new_path, argv_exec_path);
|
||||||
add_path(&new_path, getenv(EXEC_PATH_ENVIRONMENT));
|
add_path(&new_path, getenv(EXEC_PATH_ENVIRONMENT));
|
||||||
add_path(&new_path, builtin_exec_path());
|
add_path(&new_path, builtin_exec_path());
|
||||||
add_path(&new_path, cmd_path);
|
add_path(&new_path, argv0_path);
|
||||||
|
|
||||||
if (old_path)
|
if (old_path)
|
||||||
strbuf_addstr(&new_path, old_path);
|
strbuf_addstr(&new_path, old_path);
|
||||||
|
@ -2,8 +2,9 @@
|
|||||||
#define GIT_EXEC_CMD_H
|
#define GIT_EXEC_CMD_H
|
||||||
|
|
||||||
extern void git_set_argv_exec_path(const char *exec_path);
|
extern void git_set_argv_exec_path(const char *exec_path);
|
||||||
|
extern void git_set_argv0_path(const char *path);
|
||||||
extern const char* git_exec_path(void);
|
extern const char* git_exec_path(void);
|
||||||
extern void setup_path(const char *);
|
extern void setup_path(void);
|
||||||
extern int execv_git_cmd(const char **argv); /* NULL terminated */
|
extern int execv_git_cmd(const char **argv); /* NULL terminated */
|
||||||
extern int execl_git_cmd(const char *cmd, ...);
|
extern int execl_git_cmd(const char *cmd, ...);
|
||||||
extern const char *system_path(const char *path);
|
extern const char *system_path(const char *path);
|
||||||
|
5
git.c
5
git.c
@ -418,7 +418,6 @@ int main(int argc, const char **argv)
|
|||||||
{
|
{
|
||||||
const char *cmd = argv[0] && *argv[0] ? argv[0] : "git-help";
|
const char *cmd = argv[0] && *argv[0] ? argv[0] : "git-help";
|
||||||
char *slash = (char *)cmd + strlen(cmd);
|
char *slash = (char *)cmd + strlen(cmd);
|
||||||
const char *cmd_path = NULL;
|
|
||||||
int done_alias = 0;
|
int done_alias = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -431,7 +430,7 @@ int main(int argc, const char **argv)
|
|||||||
while (cmd <= slash && !is_dir_sep(*slash));
|
while (cmd <= slash && !is_dir_sep(*slash));
|
||||||
if (cmd <= slash) {
|
if (cmd <= slash) {
|
||||||
*slash++ = 0;
|
*slash++ = 0;
|
||||||
cmd_path = cmd;
|
git_set_argv0_path(cmd);
|
||||||
cmd = slash;
|
cmd = slash;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,7 +474,7 @@ int main(int argc, const char **argv)
|
|||||||
* environment, and the $(gitexecdir) from the Makefile at build
|
* environment, and the $(gitexecdir) from the Makefile at build
|
||||||
* time.
|
* time.
|
||||||
*/
|
*/
|
||||||
setup_path(cmd_path);
|
setup_path();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
/* See if it's an internal command */
|
/* See if it's an internal command */
|
||||||
|
@ -482,7 +482,7 @@ int main(int argc, char **argv)
|
|||||||
if (!dir)
|
if (!dir)
|
||||||
usage(receive_pack_usage);
|
usage(receive_pack_usage);
|
||||||
|
|
||||||
setup_path(NULL);
|
setup_path();
|
||||||
|
|
||||||
if (!enter_repo(dir, 0))
|
if (!enter_repo(dir, 0))
|
||||||
die("'%s': unable to chdir or not a git archive", dir);
|
die("'%s': unable to chdir or not a git archive", dir);
|
||||||
|
4
shell.c
4
shell.c
@ -15,7 +15,7 @@ static int do_generic_cmd(const char *me, char *arg)
|
|||||||
{
|
{
|
||||||
const char *my_argv[4];
|
const char *my_argv[4];
|
||||||
|
|
||||||
setup_path(NULL);
|
setup_path();
|
||||||
if (!arg || !(arg = sq_dequote(arg)))
|
if (!arg || !(arg = sq_dequote(arg)))
|
||||||
die("bad argument");
|
die("bad argument");
|
||||||
if (prefixcmp(me, "git-"))
|
if (prefixcmp(me, "git-"))
|
||||||
@ -37,7 +37,7 @@ static int do_cvs_cmd(const char *me, char *arg)
|
|||||||
if (!arg || strcmp(arg, "server"))
|
if (!arg || strcmp(arg, "server"))
|
||||||
die("git-cvsserver only handles server: %s", arg);
|
die("git-cvsserver only handles server: %s", arg);
|
||||||
|
|
||||||
setup_path(NULL);
|
setup_path();
|
||||||
return execv_git_cmd(cvsserver_argv);
|
return execv_git_cmd(cvsserver_argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -638,7 +638,7 @@ int main(int argc, char **argv)
|
|||||||
if (i != argc-1)
|
if (i != argc-1)
|
||||||
usage(upload_pack_usage);
|
usage(upload_pack_usage);
|
||||||
|
|
||||||
setup_path(NULL);
|
setup_path();
|
||||||
|
|
||||||
dir = argv[i];
|
dir = argv[i];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user