Skip to content

Commit 024aa7d

Browse files
dschogitster
authored andcommitted
system_path(): simplify using strip_path_suffix(), and add suffix "git"
At least for the author of this patch, the logic in system_path() was too hard to understand. Using the function strip_path_suffix() documents the idea of the code better. The real change is to add the suffix "git", so that a runtime prefix will be computed correctly even when the executable was called in /git/ as is the case in msysGit (Windows insists to search the current directory before the PATH when looking for an executable). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Acked-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 4fcc86b commit 024aa7d

File tree

1 file changed

+4
-29
lines changed

1 file changed

+4
-29
lines changed

exec_cmd.c

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,10 @@ const char *system_path(const char *path)
2323
assert(argv0_path);
2424
assert(is_absolute_path(argv0_path));
2525

26-
if (!prefix) {
27-
const char *strip[] = {
28-
GIT_EXEC_PATH,
29-
BINDIR,
30-
0
31-
};
32-
const char **s;
33-
34-
for (s = strip; *s; s++) {
35-
const char *sargv = argv0_path + strlen(argv0_path);
36-
const char *ss = *s + strlen(*s);
37-
while (argv0_path < sargv && *s < ss
38-
&& (*sargv == *ss ||
39-
(is_dir_sep(*sargv) && is_dir_sep(*ss)))) {
40-
sargv--;
41-
ss--;
42-
}
43-
if (*s == ss) {
44-
struct strbuf d = STRBUF_INIT;
45-
/* We also skip the trailing directory separator. */
46-
assert(sargv - argv0_path - 1 >= 0);
47-
strbuf_add(&d, argv0_path, sargv - argv0_path - 1);
48-
prefix = strbuf_detach(&d, NULL);
49-
break;
50-
}
51-
}
52-
}
53-
54-
if (!prefix) {
26+
if (!prefix &&
27+
!(prefix = strip_path_suffix(argv0_path, GIT_EXEC_PATH)) &&
28+
!(prefix = strip_path_suffix(argv0_path, BINDIR)) &&
29+
!(prefix = strip_path_suffix(argv0_path, "git"))) {
5530
prefix = PREFIX;
5631
fprintf(stderr, "RUNTIME_PREFIX requested, "
5732
"but prefix computation failed. "

0 commit comments

Comments
 (0)