]> git.ipfire.org Git - thirdparty/git.git/commitdiff
name-hash: properly fold directory names in adjust_dirname_case()
authorBen Peart <benpeart@microsoft.com>
Thu, 8 Feb 2018 19:23:33 +0000 (14:23 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 8 Feb 2018 20:20:56 +0000 (12:20 -0800)
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>
name-hash.c
t/t0050-filesystem.sh

index 6d9f23e932559c58c9ebf4679a6035889f726ed2..139263b5e071f5b92eb5ead6809e7c5a4a2b8734 100644 (file)
@@ -201,12 +201,12 @@ void adjust_dirname_case(struct index_state *istate, char *name)
                if (*ptr == '/') {
                        struct dir_entry *dir;
 
-                       ptr++;
-                       dir = find_dir_entry(istate, name, ptr - name + 1);
+                       dir = find_dir_entry(istate, name, ptr - name);
                        if (dir) {
                                memcpy((void *)startPtr, dir->name + (startPtr - name), ptr - startPtr);
-                               startPtr = ptr;
+                               startPtr = ptr + 1;
                        }
+                       ptr++;
                }
        }
 }
index b29d749bb7b33406b2d433d96c35d252e305eed0..192c94eccd13c3b251cfc6910ad6ef175312ea13 100755 (executable)
@@ -80,7 +80,21 @@ test_expect_success 'merge (case change)' '
        git merge topic
 '
 
-
+test_expect_success CASE_INSENSITIVE_FS 'add directory (with different case)' '
+       git reset --hard initial &&
+       mkdir -p dir1/dir2 &&
+       echo >dir1/dir2/a &&
+       echo >dir1/dir2/b &&
+       git add dir1/dir2/a &&
+       git add dir1/DIR2/b &&
+       git ls-files >actual &&
+       cat >expected <<-\EOF &&
+               camelcase
+               dir1/dir2/a
+               dir1/dir2/b
+       EOF
+       test_cmp expected actual
+'
 
 test_expect_failure CASE_INSENSITIVE_FS 'add (with different case)' '
        git reset --hard initial &&