From 22ac2e056e1826957dddfaac6e45dadc4414bbe1 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sun, 22 Jul 2018 11:05:24 -0400 Subject: ripgrep: stop early when --files --quiet is used This commit tweaks the implementation of the --files flag to stop early when --quiet is provided. Fixes #907 --- src/app.rs | 3 +++ src/main.rs | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/app.rs b/src/app.rs index 4bdf5bf4..24851c3b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1402,6 +1402,9 @@ fn flag_quiet(args: &mut Vec) { Do not print anything to stdout. If a match is found in a file, then ripgrep will stop searching. This is useful when ripgrep is used only for its exit code (which will be an error if no matches are found). + +When --files is used, then ripgrep will stop finding files after finding the +first file that matches all ignore rules. "); let arg = RGArg::switch("quiet").short("q") .help(SHORT).long_help(LONG); diff --git a/src/main.rs b/src/main.rs index 73bc8c23..af22373e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -245,6 +245,9 @@ fn run_files_parallel(args: Arc) -> Result { args.no_ignore_messages(), ) { tx.send(dent).unwrap(); + if args.quiet() { + return ignore::WalkState::Quit + } } ignore::WalkState::Continue }) @@ -266,10 +269,12 @@ fn run_files_one_thread(args: &Arc) -> Result { None => continue, Some(dent) => dent, }; - if !args.quiet() { + file_count += 1; + if args.quiet() { + break; + } else { printer.path(dent.path()); } - file_count += 1; } Ok(file_count) } -- cgit v1.2.3