diff options
author | David Torosyan <davidtorosyan.git@gmail.com> | 2019-01-20 17:32:34 -0800 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2019-01-22 20:03:59 -0500 |
commit | 718a00f6f2f88238546f7d33c1ea52217002495e (patch) | |
tree | 6dc4db1c1d1af1f5d87957754341b4f74ff41984 /src | |
parent | 7cbc535d70a53c81dfa3e58552c01f21c2e38d28 (diff) |
ripgrep: add --ignore-file-case-insensitive
The --ignore-file-case-insensitive flag causes all
.gitignore/.rgignore/.ignore files to have their globs matched without
regard for case. Because this introduces a potentially significant
performance regression, this is always disabled by default. Users that
need case insensitive matching can enable it on a case by case basis.
Closes #1164, Closes #1170
Diffstat (limited to 'src')
-rw-r--r-- | src/app.rs | 22 | ||||
-rw-r--r-- | src/args.rs | 10 |
2 files changed, 30 insertions, 2 deletions
@@ -571,6 +571,7 @@ pub fn all_args_and_flags() -> Vec<RGArg> { flag_iglob(&mut args); flag_ignore_case(&mut args); flag_ignore_file(&mut args); + flag_ignore_file_case_insensitive(&mut args); flag_invert_match(&mut args); flag_json(&mut args); flag_line_buffered(&mut args); @@ -1209,6 +1210,27 @@ directly on the command line, then used -g instead. args.push(arg); } +fn flag_ignore_file_case_insensitive(args: &mut Vec<RGArg>) { + const SHORT: &str = + "Process ignore files (.gitignore, .ignore, etc.) case insensitively."; + const LONG: &str = long!("\ +Process ignore files (.gitignore, .ignore, etc.) case insensitively. Note that +this comes with a performance penalty and is most useful on case insensitive +file systems (such as Windows). + +This flag can be disabled with the --no-ignore-file-case-insensitive flag. +"); + let arg = RGArg::switch("ignore-file-case-insensitive") + .help(SHORT).long_help(LONG) + .overrides("no-ignore-file-case-insensitive"); + args.push(arg); + + let arg = RGArg::switch("no-ignore-file-case-insensitive") + .hidden() + .overrides("ignore-file-case-insensitive"); + args.push(arg); +} + fn flag_invert_match(args: &mut Vec<RGArg>) { const SHORT: &str = "Invert matching."; const LONG: &str = long!("\ diff --git a/src/args.rs b/src/args.rs index 70af9df1..df55df25 100644 --- a/src/args.rs +++ b/src/args.rs @@ -797,7 +797,8 @@ impl ArgMatches { && !self.no_ignore_vcs() && !self.no_ignore_global()) .git_ignore(!self.no_ignore() && !self.no_ignore_vcs()) - .git_exclude(!self.no_ignore() && !self.no_ignore_vcs()); + .git_exclude(!self.no_ignore() && !self.no_ignore_vcs()) + .ignore_case_insensitive(self.ignore_file_case_insensitive()); if !self.no_ignore() { builder.add_custom_ignore_filename(".rgignore"); } @@ -1003,6 +1004,11 @@ impl ArgMatches { self.is_present("hidden") || self.unrestricted_count() >= 2 } + /// Returns true if ignore files should be processed case insensitively. + fn ignore_file_case_insensitive(&self) -> bool { + self.is_present("ignore-file-case-insensitive") + } + /// Return all of the ignore file paths given on the command line. fn ignore_paths(&self) -> Vec<PathBuf> { let paths = match self.values_of_os("ignore-file") { @@ -1143,7 +1149,7 @@ impl ArgMatches { builder.add(&glob)?; } // This only enables case insensitivity for subsequent globs. - builder.case_insensitive(true)?; + builder.case_insensitive(true).unwrap(); for glob in self.values_of_lossy_vec("iglob") { builder.add(&glob)?; } |