@matheusbsbs / matheus-bagliano / commits / 024aa7d8d5
Fork 0

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>

Johannes Schindelin committed Feb 19, 2009 at 20:10 UTC 024aa7d8d5114f76e616a0ed8ddcf3b463ff2c14
1 file changed +4 -29
exec_cmd.c
+4 -29
@@ -23,35 +23,10 @@ const char *system_path(const char *path)
23 assert(argv0_path);
24 assert(is_absolute_path(argv0_path));
25
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"))) {
30 prefix = PREFIX;
31 fprintf(stderr, "RUNTIME_PREFIX requested, "
32 "but prefix computation failed. "