Skip to content

Commit 680be04

Browse files
sunshinecogitster
authored andcommitted
dir.c::test_one_path(): work around directory_exists_in_index_icase() breakage
directory_exists_in_index() takes pathname and its length, but its helper function directory_exists_in_index_icase() reads one byte beyond the end of the pathname and expects there to be a '/'. This needs to be fixed, as that one-byte-beyond-the-end location may not even be readable, possibly by not registering directories to name hashes with trailing slashes. In the meantime, update the new caller added recently to treat_one_path() to make sure that the path buffer it gives the function is one byte longer than the path it is asking the function about by appending a slash to it. Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3c56875 commit 680be04

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

dir.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,9 +1202,21 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
12021202
*/
12031203
if ((dir->flags & DIR_COLLECT_KILLED_ONLY) &&
12041204
(dtype == DT_DIR) &&
1205-
!has_path_in_index &&
1206-
(directory_exists_in_index(path->buf, path->len) == index_nonexistent))
1207-
return path_none;
1205+
!has_path_in_index) {
1206+
/*
1207+
* NEEDSWORK: directory_exists_in_index_icase()
1208+
* assumes that one byte past the given path is
1209+
* readable and has '/', which needs to be fixed, but
1210+
* until then, work it around in the caller.
1211+
*/
1212+
strbuf_addch(path, '/');
1213+
if (directory_exists_in_index(path->buf, path->len - 1) ==
1214+
index_nonexistent) {
1215+
strbuf_setlen(path, path->len - 1);
1216+
return path_none;
1217+
}
1218+
strbuf_setlen(path, path->len - 1);
1219+
}
12081220

12091221
exclude = is_excluded(dir, path->buf, &dtype);
12101222

t/t3010-ls-files-killed-modified.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ date >path7
7878
touch path10
7979
>pathx/ju/nk
8080

81-
test_expect_success \
82-
'git ls-files -k to show killed files.' \
83-
'git ls-files -k >.output'
8481
cat >.expected <<EOF
8582
path0/file0
8683
path1/file1
@@ -89,9 +86,15 @@ path3
8986
pathx/ju/nk
9087
EOF
9188

92-
test_expect_success \
93-
'validate git ls-files -k output.' \
94-
'test_cmp .expected .output'
89+
test_expect_success 'git ls-files -k to show killed files (w/o icase)' '
90+
git ls-files -k >.output &&
91+
test_cmp .expected .output
92+
'
93+
94+
test_expect_success 'git ls-files -k to show killed files (w/ icase)' '
95+
git -c core.ignorecase=true ls-files -k >.output &&
96+
test_cmp .expected .output
97+
'
9598

9699
test_expect_success \
97100
'git ls-files -m to show modified files.' \

0 commit comments

Comments
 (0)