name-hash: properly fold directory names in adjust_dirname_case()

Correct the pointer arithmetic in adjust_dirname_case() so that it calls find_dir_entry() with the correct string length. Previously passing in "dir1/foo" would pass a length of 6 instead of the correct 4. This resulted in find_dir_entry() never finding the entry and so the subsequent memcpy that would fold the name to the version with the correct case never executed. Add a test to validate the corrected behavior with name folding of directories. Signed-off-by: Ben Peart <benpeart@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ben Peart committed Feb 8, 2018 at 14:23 UTC c95525e90d2f3c75b879ce51fd17d263a6452de3
2 files changed +18 -4
name-hash.c
+3 -3
@@ -201,12 +201,12 @@ void adjust_dirname_case(struct index_state *istate, char *name)
201 if (*ptr == '/') {
202 struct dir_entry *dir;
203
204 - ptr++;
205 - dir = find_dir_entry(istate, name, ptr - name + 1);
204 + dir = find_dir_entry(istate, name, ptr - name);
205 if (dir) {
206 memcpy((void *)startPtr, dir->name + (startPtr - name), ptr - startPtr);
208 - startPtr = ptr;
207 + startPtr = ptr + 1;
208 }
209 + ptr++;
210 }
211 }
212 }
t/t0050-filesystem.sh
+15 -1
@@ -80,7 +80,21 @@ test_expect_success 'merge (case change)' '
80 git merge topic
81 '
82
83 -
83 +test_expect_success CASE_INSENSITIVE_FS 'add directory (with different case)' '
84 + git reset --hard initial &&
85 + mkdir -p dir1/dir2 &&
86 + echo >dir1/dir2/a &&
87 + echo >dir1/dir2/b &&
88 + git add dir1/dir2/a &&
89 + git add dir1/DIR2/b &&
90 + git ls-files >actual &&
91 + cat >expected <<-\EOF &&
92 + camelcase
93 + dir1/dir2/a
94 + dir1/dir2/b
95 + EOF
96 + test_cmp expected actual
97 +'
98
99 test_expect_failure CASE_INSENSITIVE_FS 'add (with different case)' '
100 git reset --hard initial &&