Skip to content

Commit 43a7ddb

Browse files
René Scharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f3cad0a commit 43a7ddb

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

path.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -524,15 +524,16 @@ int longest_ancestor_length(const char *path, const char *prefix_list)
524524
return -1;
525525

526526
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++);
528528
len = colon - ceil;
529529
if (len == 0 || len > PATH_MAX || !is_absolute_path(ceil))
530530
continue;
531531
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';
536537

537538
if (!strncmp(path, buf, len) &&
538539
path[len] == '/' &&

t/t1504-ceiling-dirs.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ GIT_CEILING_DIRECTORIES="$TRASH_ROOT/subdi"
9393
test_prefix subdir_ceil_at_subdi_slash "sub/dir/"
9494

9595

96-
GIT_CEILING_DIRECTORIES="foo:$TRASH_ROOT/sub"
96+
GIT_CEILING_DIRECTORIES="/foo:$TRASH_ROOT/sub"
9797
test_fail second_of_two
9898

99-
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub:bar"
99+
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub:/bar"
100100
test_fail first_of_two
101101

102-
GIT_CEILING_DIRECTORIES="foo:$TRASH_ROOT/sub:bar"
102+
GIT_CEILING_DIRECTORIES="/foo:$TRASH_ROOT/sub:/bar"
103103
test_fail second_of_three
104104

105105

0 commit comments

Comments
 (0)