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()
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(char **argv
)
34 char git_command
[PATH_MAX
+ 1];
37 const char *paths
[] = { current_exec_path
,
38 getenv("GIT_EXEC_PATH"),
41 for (i
= 0; i
< sizeof(paths
)/sizeof(paths
[0]); ++i
) {
42 const char *exec_dir
= paths
[i
];
43 if (!exec_dir
) continue;
45 if (*exec_dir
!= '/') {
46 if (!getcwd(git_command
, sizeof(git_command
))) {
47 fprintf(stderr
, "git: cannot determine "
48 "current directory\n");
51 len
= strlen(git_command
);
54 while (!strncmp(exec_dir
, "./", 2)) {
56 while (*exec_dir
== '/')
59 snprintf(git_command
+ len
, sizeof(git_command
) - len
,
62 strcpy(git_command
, exec_dir
);
65 len
= strlen(git_command
);
66 len
+= snprintf(git_command
+ len
, sizeof(git_command
) - len
,
69 if (sizeof(git_command
) <= len
) {
71 "git: command name given is too long.\n");
75 /* argv[0] must be the git command, but the argv array
76 * belongs to the caller, and my be reused in
77 * subsequent loop iterations. Save argv[0] and
78 * restore it on error.
82 argv
[0] = git_command
;
84 /* execve() can only ever return if it fails */
85 execve(git_command
, argv
, environ
);
96 int execl_git_cmd(char *cmd
,...)
99 char *argv
[MAX_ARGS
+ 1];
103 va_start(param
, cmd
);
106 while (argc
< MAX_ARGS
) {
107 arg
= argv
[argc
++] = va_arg(param
, char *);
112 if (MAX_ARGS
<= argc
)
113 return error("too many args to run %s", cmd
);
116 return execv_git_cmd(argv
);