@matheusbsbs / matheus-bagliano / commits / 43a7ddb55d
Fork 0

Fix GIT_CEILING_DIRECTORIES on Windows

Using git with GIT_CEILING_DIRECTORIES crashed on Windows due to a failed assertion in normalize_absolute_path(): This function expects absolute paths to start with a slash, while on Windows they can start with a drive letter or a backslash. This fixes it by using the alternative, normalize_path_copy() instead, which can handle Windows-style paths just fine. Secondly, the portability macro PATH_SEP is used instead of expecting colons to be used as path list delimiter. The test script t1504 is also changed to help MSYS's bash recognize some program arguments as path list. (MSYS's bash must translate POSIX-style path lists to Windows-style path lists, and the heuristic did not catch some cases.) Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Feb 7, 2009 at 16:08 UTC 43a7ddb55d82d5c6f0c4d2cbe408a1df71d58ef3
2 files changed +9 -8
path.c
+6 -5
@@ -524,15 +524,16 @@ int longest_ancestor_length(const char *path, const char *prefix_list)
524 return -1;
525
526 for (colon = ceil = prefix_list; *colon; ceil = colon+1) {
527 - for (colon = ceil; *colon && *colon != ':'; colon++);
527 + for (colon = ceil; *colon && *colon != PATH_SEP; colon++);
528 len = colon - ceil;
529 if (len == 0 || len > PATH_MAX || !is_absolute_path(ceil))
530 continue;
531 strlcpy(buf, ceil, len+1);
532 - len = normalize_absolute_path(buf, buf);
533 - /* Strip "trailing slashes" from "/". */
534 - if (len == 1)
535 - len = 0;
532 + if (normalize_path_copy(buf, buf) < 0)
533 + continue;
534 + len = strlen(buf);
535 + if (len > 0 && buf[len-1] == '/')
536 + buf[--len] = '\0';
537
538 if (!strncmp(path, buf, len) &&
539 path[len] == '/' &&
t/t1504-ceiling-dirs.sh
+3 -3
@@ -93,13 +93,13 @@ GIT_CEILING_DIRECTORIES="$TRASH_ROOT/subdi"
93 test_prefix subdir_ceil_at_subdi_slash "sub/dir/"
94
95
96 -GIT_CEILING_DIRECTORIES="foo:$TRASH_ROOT/sub"
96 +GIT_CEILING_DIRECTORIES="/foo:$TRASH_ROOT/sub"
97 test_fail second_of_two
98
99 -GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub:bar"
99 +GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub:/bar"
100 test_fail first_of_two
101
102 -GIT_CEILING_DIRECTORIES="foo:$TRASH_ROOT/sub:bar"
102 +GIT_CEILING_DIRECTORIES="/foo:$TRASH_ROOT/sub:/bar"
103 test_fail second_of_three
104
105