Skip to content

Commit

Permalink
exclude: fix a bug in prefix compare optimization
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
pclouds authored and gitster committed Oct 15, 2012
1 parent 593cb88 commit a3ea4d7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dir.c
Expand Up @@ -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 */
Expand Down
6 changes: 6 additions & 0 deletions t/t3001-ls-files-others-exclude.sh
Expand Up @@ -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

0 comments on commit a3ea4d7

Please sign in to comment.