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 <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Aug 23, 2013 at 16:26 UTC 680be044d98b3b703bc33d546a987c19b3779aeb
2 files changed +24 -9
dir.c
+15 -3
@@ -1202,9 +1202,21 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
1202 */
1203 if ((dir->flags & DIR_COLLECT_KILLED_ONLY) &&
1204 (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 + }
1220
1221 exclude = is_excluded(dir, path->buf, &dtype);
1222
t/t3010-ls-files-killed-modified.sh
+9 -6
@@ -78,9 +78,6 @@ date >path7
78 touch path10
79 >pathx/ju/nk
80
81 -test_expect_success \
82 - 'git ls-files -k to show killed files.' \
83 - 'git ls-files -k >.output'
81 cat >.expected <<EOF
82 path0/file0
83 path1/file1
@@ -89,9 +86,15 @@ path3
86 pathx/ju/nk
87 EOF
88
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 +'
98
99 test_expect_success \
100 'git ls-files -m to show modified files.' \