exclude: fix a bug in prefix compare optimization
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Mon, 15 Oct 2012 06:24:36 +0000 (13:24 +0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 15 Oct 2012 21:57:16 +0000 (14:57 -0700)
When "namelen" becomes zero at this stage, we have matched the fixed
part, but whether it actually matches the pattern still depends on the
pattern in "exclude". As demonstrated in t3001, path "three/a.3"
exists and it matches the "three/a.3" part in pattern "three/a.3[abc]",
but that does not mean a true match.

Don't be too optimistic and let fnmatch() do the job.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
dir.c
t/t3001-ls-files-others-exclude.sh

diff --git a/dir.c b/dir.c
index d9b55614666e631e6b3ada04e4ee6a51c3e41a33..22d0b7b726b1cd2ad757c6a9fe7b3295c1d52878 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -585,7 +585,7 @@ int excluded_from_list(const char *pathname,
                        namelen -= prefix;
                }
 
-               if (!namelen || !fnmatch_icase(exclude, name, FNM_PATHNAME))
+               if (!fnmatch_icase(exclude, name, FNM_PATHNAME))
                        return to_exclude;
        }
        return -1; /* undecided */
index c8fe9782672c0e6ba2f0fd0c1b708fc980263182..dc2f0458fd0e74a3dcb4769517f5cde2606eb6f2 100755 (executable)
@@ -214,4 +214,10 @@ test_expect_success 'subdirectory ignore (l1)' '
        test_cmp expect actual
 '
 
+test_expect_success 'pattern matches prefix completely' '
+       : >expect &&
+       git ls-files -i -o --exclude "/three/a.3[abc]" >actual &&
+       test_cmp expect actual
+'
+
 test_done