6 static const char *builtin_exec_path
= GIT_EXEC_PATH
;
7 static const char *current_exec_path
= NULL
;
9 void git_set_exec_path(const char *exec_path
)
11 current_exec_path
= exec_path
;
15 /* Returns the highest-priority, location to look for git programs. */
16 const char *git_exec_path(void)
20 if (current_exec_path
)
21 return current_exec_path
;
23 env
= getenv("GIT_EXEC_PATH");
28 return builtin_exec_path
;
32 int execv_git_cmd(const char **argv
)
34 char git_command
[PATH_MAX
+ 1];
36 const char *paths
[] = { current_exec_path
,
37 getenv("GIT_EXEC_PATH"),
40 for (i
= 0; i
< sizeof(paths
)/sizeof(paths
[0]); ++i
) {
41 const char *exec_dir
= paths
[i
];
44 if (!exec_dir
) continue;
46 if (*exec_dir
!= '/') {
47 if (!getcwd(git_command
, sizeof(git_command
))) {
48 fprintf(stderr
, "git: cannot determine "
49 "current directory\n");
52 len
= strlen(git_command
);
55 while (!strncmp(exec_dir
, "./", 2)) {
57 while (*exec_dir
== '/')
60 snprintf(git_command
+ len
, sizeof(git_command
) - len
,
63 strcpy(git_command
, exec_dir
);
66 len
= strlen(git_command
);
67 len
+= snprintf(git_command
+ len
, sizeof(git_command
) - len
,
70 if (sizeof(git_command
) <= len
) {
72 "git: command name given is too long.\n");
76 /* argv[0] must be the git command, but the argv array
77 * belongs to the caller, and my be reused in
78 * subsequent loop iterations. Save argv[0] and
79 * restore it on error.
83 argv
[0] = git_command
;
85 /* execve() can only ever return if it fails */
86 execve(git_command
, (char **)argv
, environ
);
97 int execl_git_cmd(const char *cmd
,...)
100 const char *argv
[MAX_ARGS
+ 1];
104 va_start(param
, cmd
);
107 while (argc
< MAX_ARGS
) {
108 arg
= argv
[argc
++] = va_arg(param
, char *);
113 if (MAX_ARGS
<= argc
)
114 return error("too many args to run %s", cmd
);
117 return execv_git_cmd(argv
);