Repository navigation
grep: let the last matching --include or --exclude decide - #146
Conversation
--include and --exclude were two separate sets: a file was skipped when any --exclude matched or no --include did, whatever the order. GNU grep applies them in the order given: the last pattern that matches a name decides, and a name that matches none is skipped only when the first pattern is an --include. So "--exclude=a* --include=*.txt" searched nothing where GNU searches a.txt and every file that matches neither. Keep the patterns in one list in command-line order, with --exclude-from patterns at the position of that option.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
Merging this PR will not alter performance
Comparing Footnotes
|
GlobSet now keeps whether each pattern is an include or an exclude, so FileGlobs and its copy of add() go away. --exclude-dir adds its patterns as excludes, which skips the same directories as before.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
Thanks, went with changing |
|
Thanks for your PR |
--includeand--excludeare kept as two separate sets: a file is skipped when any--excludematches it or no--includedoes, whatever the order. GNU grep goes by order. Its man page: "If contradictory --include and --exclude options are given, the last matching one wins. If no --include or --exclude options match, a file is included unless the first such option is --include." So mixing them gives different files:a.txtmatches both, and the--includecomes last.b.logmatches neither, and the first pattern is an--exclude.--exclude=zz --include='*.txt'has the same problem: GNU keepsb.log, and this skips it.The patterns now go into one list in command-line order (from clap's indices).
--exclude-frompatterns sit at the position of that option.GlobSetstays for--exclude-dir, and itsis_emptygoes since nothing uses it anymore.Tests:
recursive_include_exclude_last_match_winscovers both orders above and an--includefollowed by--exclude-from. It fails on main. The existing include/exclude tests pass unchanged.cargo test: 116 passed (115 on main), clippy and rustfmt clean. I compared 12 include/exclude/exclude-from orderings with GNU grep 3.12 under-r -l, and they all give the same files now.