Skip to content
Myr

flags: disable many flags when indexing is enabled

Before adoption: this commit came in with the history the project adopted, so no landing records it.

The indexing feature will be born with a lot of restrictions on it in order to bootstrap and end-to-end working system. For example, getting the `--pre` flag (and similar) working correctly is somewhat of a hazard, since you'd need to specify the same transformation during both indexing and not. We disable pretty much any kind of filtering or transform related flags other than what the default provides. Again, we'll relax at least most of these in the future. But let's start here.

authored by Andrew Gallant · committed by Andrew Gallant · parent 59e318f · Browse files · 5 files+217 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+217 added−0 removed

  • tests:+135 added−0 removed
  • other:+82 added−0 removed

5 files+217 added−0 removed

modified:crates/core/flags/defs.rs+73 added
153 unmodified lines
154 &NoPcre2Unicode,155 &SortFiles,156];157158impl LowArgs {159 /// Returns a flag that does not support indexing, if it's enabled.160 ///161 /// If there aren't any flags enabled that don't support indexing, then162 /// `None` is returned.163 ///164 /// The idea of this routine is to start out very paranoid about what is165 /// allowed to be used when indexing is enabled. Ideally, most or all of166 /// these would eventually become supported.167 pub(super) fn indexing_unsupported_flag(168 &self,169 ) -> Option<&'static dyn Flag> {170 if matches!(self.mode, Mode::Search(SearchMode::FilesWithoutMatch)) {171 return Some(&FilesWithoutMatch);172 }173 if matches!(self.binary, BinaryMode::AsText) {174 return Some(&Binary);175 }176 if !matches!(self.encoding, EncodingMode::Auto) {177 return Some(&Encoding);178 }179 if matches!(self.engine, EngineChoice::PCRE2) {180 return Some(&Engine);181 }182 if self.follow {183 return Some(&Follow);184 }185 if !self.globs.is_empty() {186 return Some(&Glob);187 }188 if self.hidden {189 return Some(&Hidden);190 }191 if !self.iglobs.is_empty() {192 return Some(&Glob);193 }194 if !self.ignore_file.is_empty() {195 return Some(&IgnoreFile);196 }197 if self.no_ignore_dot {198 return Some(&NoIgnoreDot);199 }200 if self.no_ignore_exclude {201 return Some(&NoIgnoreExclude);202 }203 if self.no_ignore_files {204 return Some(&NoIgnoreFiles);205 }206 if self.no_ignore_global {207 return Some(&NoIgnoreGlobal);208 }209 if self.no_ignore_parent {210 return Some(&NoIgnoreParent);211 }212 if self.no_ignore_vcs {213 return Some(&NoIgnoreVcs);214 }215 if self.no_require_git {216 return Some(&NoRequireGit);217 }218 if self.one_file_system {219 return Some(&OneFileSystem);220 }221 if self.pre.is_some() {222 return Some(&Pre);223 }224 if self.search_zip {225 return Some(&SearchZip);226 }227 None228 }229}230231/// -A/--after-context232#[derive(Debug)]233struct AfterContext;234
7927 unmodified lines
modified:crates/core/flags/hiargs.rs+9 added
119 unmodified lines
120 // `low.sort = None` if `supported()` returns an error.121 if let Some(ref sort) = low.sort {122 sort.supported()?;123 }124 // We aggressively ban things from indexing at present.125 if (low.index > 0 || matches!(low.mode, Mode::Index(_)))126 && let Some(flag) = low.indexing_unsupported_flag()127 {128 anyhow::bail!(129 "flag --{} does not support indexing",130 flag.name_long()131 );132 }133134 // We modify the mode in-place on `low` so that subsequent conversions135 // see the correct mode.136 match low.mode {
1353 unmodified lines
added:tests/index/disallowed.rs+129 added
1use crate::util::{Dir, TestCommand};23rgtest!(search_mode, |dir: Dir, _cmd: TestCommand| {4 dir.create("test", "foobar");5 dir.command()6 .arg("-X")7 .arg("--files-without-match")8 .arg("no-match")9 .assert_err();10});1112rgtest!(binary, |dir: Dir, _cmd: TestCommand| {13 dir.create("test", "foobar");14 dir.command().arg("-X").arg("--text").arg("foobar").assert_err();15});1617rgtest!(encoding, |dir: Dir, _cmd: TestCommand| {18 dir.create("test", "foobar");19 dir.command().arg("-X").arg("-Eutf16").arg("foobar").assert_err();20 dir.command().arg("-X").arg("-Enone").arg("foobar").assert_err();2122 eqnice!(23 "test:foobar\n",24 dir.command().arg("-X").arg("-Eauto").arg("foobar").stdout()25 );26});2728rgtest!(engine, |dir: Dir, _cmd: TestCommand| {29 dir.create("test", "foobar");30 dir.command().arg("-X").arg("--engine=pcre2").arg("foobar").assert_err();3132 eqnice!(33 "test:foobar\n",34 dir.command().arg("-X").arg("--engine=auto").arg("foobar").stdout()35 );36 eqnice!(37 "test:foobar\n",38 dir.command().arg("-X").arg("--engine=default").arg("foobar").stdout()39 );40});4142rgtest!(follow, |dir: Dir, _cmd: TestCommand| {43 dir.create("test", "foobar");44 dir.command().arg("-X").arg("--follow").arg("foobar").assert_err();45});4647rgtest!(glob, |dir: Dir, _cmd: TestCommand| {48 dir.create("test", "foobar");49 dir.command().arg("-X").arg("--glob=test").arg("foobar").assert_err();50});5152rgtest!(hidden, |dir: Dir, _cmd: TestCommand| {53 dir.create(".test", "foobar");54 dir.command().arg("-X").arg("--hidden").arg("foobar").assert_err();55});5657rgtest!(iglob, |dir: Dir, _cmd: TestCommand| {58 dir.create("test", "foobar");59 dir.command().arg("-X").arg("--iglob=test").arg("foobar").assert_err();60});6162rgtest!(ignore_file, |dir: Dir, _cmd: TestCommand| {63 dir.create("test", "foobar");64 dir.create("ignore-file", "");65 dir.command()66 .arg("-X")67 .arg("--ignore-file=ignore-file")68 .arg("foobar")69 .assert_err();70});7172rgtest!(no_ignore, |dir: Dir, _cmd: TestCommand| {73 dir.create("test", "foobar");74 dir.command().arg("-X").arg("--no-ignore").arg("foobar").assert_err();75 dir.command().arg("-X").arg("--no-ignore-dot").arg("foobar").assert_err();76 dir.command()77 .arg("-X")78 .arg("--no-ignore-exclude")79 .arg("foobar")80 .assert_err();81 dir.command()82 .arg("-X")83 .arg("--no-ignore-files")84 .arg("foobar")85 .assert_err();86 dir.command()87 .arg("-X")88 .arg("--no-ignore-global")89 .arg("foobar")90 .assert_err();91 dir.command()92 .arg("-X")93 .arg("--no-ignore-parent")94 .arg("foobar")95 .assert_err();96 dir.command().arg("-X").arg("--no-ignore-vcs").arg("foobar").assert_err();97});9899rgtest!(no_require_git, |dir: Dir, _cmd: TestCommand| {100 dir.create("test", "foobar");101 dir.command().arg("-X").arg("--no-require-git").arg("foobar").assert_err();102});103104rgtest!(one_file_system, |dir: Dir, _cmd: TestCommand| {105 dir.create("test", "foobar");106 dir.command()107 .arg("-X")108 .arg("--one-file-system")109 .arg("foobar")110 .assert_err();111});112113#[cfg(unix)] // in order to use `cat`114rgtest!(pre, |dir: Dir, _cmd: TestCommand| {115 dir.create("test", "foobar");116 dir.command().arg("-X").arg("--pre").arg("cat").arg("foobar").assert_err();117});118119rgtest!(search_zip, |dir: Dir, _cmd: TestCommand| {120 dir.create("test", "foobar");121 dir.command().arg("-X").arg("--search-zip").arg("foobar").assert_err();122});123124rgtest!(unrestricted, |dir: Dir, _cmd: TestCommand| {125 dir.create("test", "foobar");126 dir.command().arg("-X").arg("-u").arg("foobar").assert_err();127 dir.command().arg("-X").arg("-uu").arg("foobar").assert_err();128 dir.command().arg("-X").arg("-uuu").arg("foobar").assert_err();129});
added:tests/index/mod.rs+3 added
1// At present, many features of ripgrep are not allowed when using indexing.2// Ideally some or many of these restrictions will be lifted over time.3mod disallowed;
modified:tests/tests.rs+3 added
10 unmodified lines
11mod binary;12// Tests related to most features in ripgrep. If you're adding something new13// to ripgrep, tests should probably go in here.14mod feature;15// Tests ripgrep's indexing feature.16#[cfg(feature = "unstable-index")]17mod index;18// Tests for ripgrep's JSON format.19mod json;20// Miscellaneous tests grouped in a haphazard manner. Try not to add more.21mod misc;
4 unmodified lines