mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-20 11:11:24 +00:00
bsdgrep: Fix --include/--exclude ordering issues
Prior to r332851: * --exclude always win out over --include * --exclude-dir always wins out over --include-dir r332851 broke that behavior, resulting in: * First of --exclude, --include wins * First of --exclude-dir, --include-dir wins As it turns out, both behaviors are wrong by modern grep standards- the latest rule wins. e.g.: `grep --exclude foo --include foo 'thing' foo` foo is included `grep --include foo --exclude foo 'thing' foo` foo is excluded As tested with GNU grep 3.1. This commit makes bsdgrep follow this behavior. Reported by: se
This commit is contained in:
parent
18f48e0c72
commit
ff415f05bf
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=332856
@ -109,10 +109,12 @@ file_matching(const char *fname)
|
||||
|
||||
for (unsigned int i = 0; i < fpatterns; ++i) {
|
||||
if (fnmatch(fpattern[i].pat, fname, 0) == 0 ||
|
||||
fnmatch(fpattern[i].pat, fname_base, 0) == 0) {
|
||||
fnmatch(fpattern[i].pat, fname_base, 0) == 0)
|
||||
/*
|
||||
* The last pattern matched wins exclusion/inclusion
|
||||
* rights, so we can't reasonably bail out early here.
|
||||
*/
|
||||
ret = (fpattern[i].mode != EXCL_PAT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(fname_buf);
|
||||
return (ret);
|
||||
@ -127,7 +129,11 @@ dir_matching(const char *dname)
|
||||
|
||||
for (unsigned int i = 0; i < dpatterns; ++i) {
|
||||
if (dname != NULL && fnmatch(dpattern[i].pat, dname, 0) == 0)
|
||||
return (dpattern[i].mode != EXCL_PAT);
|
||||
/*
|
||||
* The last pattern matched wins exclusion/inclusion
|
||||
* rights, so we can't reasonably bail out early here.
|
||||
*/
|
||||
ret = (dpattern[i].mode != EXCL_PAT);
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user