diff options
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | crates/printer/src/json.rs | 17 | ||||
-rw-r--r-- | crates/printer/src/standard.rs | 11 | ||||
-rw-r--r-- | crates/printer/src/summary.rs | 17 | ||||
-rw-r--r-- | crates/printer/src/util.rs | 2 | ||||
-rw-r--r-- | tests/feature.rs | 1 |
6 files changed, 47 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index af6dd05b..1057dfcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,6 +77,8 @@ Bug fixes: Fix gitignore parsing bug where a trailing `\/` resulted in an error. * [BUG #2243](https://github.com/BurntSushi/ripgrep/issues/2243): Fix `--sort` flag for values other than `path`. +* [BUG #2246](https://github.com/BurntSushi/ripgrep/issues/2246): + Add note in `--debug` logs when binary files are ignored. * [BUG #2337](https://github.com/BurntSushi/ripgrep/issues/2337): Improve docs to mention that `--stats` is always implied by `--json`. * [BUG #2381](https://github.com/BurntSushi/ripgrep/issues/2381): diff --git a/crates/printer/src/json.rs b/crates/printer/src/json.rs index de4da9cc..82ad94de 100644 --- a/crates/printer/src/json.rs +++ b/crates/printer/src/json.rs @@ -755,6 +755,23 @@ impl<'p, 's, M: Matcher, W: io::Write> Sink for JSONSink<'p, 's, M, W> { Ok(!self.should_quit()) } + fn binary_data( + &mut self, + searcher: &Searcher, + binary_byte_offset: u64, + ) -> Result<bool, io::Error> { + if searcher.binary_detection().quit_byte().is_some() { + if let Some(ref path) = self.path { + log::debug!( + "ignoring {path}: found binary data at \ + offset {binary_byte_offset}", + path = path.display(), + ); + } + } + Ok(true) + } + fn begin(&mut self, _searcher: &Searcher) -> Result<bool, io::Error> { self.json.wtr.reset_count(); self.start_time = Instant::now(); diff --git a/crates/printer/src/standard.rs b/crates/printer/src/standard.rs index 78489906..6cc5374f 100644 --- a/crates/printer/src/standard.rs +++ b/crates/printer/src/standard.rs @@ -884,9 +884,18 @@ impl<'p, 's, M: Matcher, W: WriteColor> Sink for StandardSink<'p, 's, M, W> { fn binary_data( &mut self, - _searcher: &Searcher, + searcher: &Searcher, binary_byte_offset: u64, ) -> Result<bool, io::Error> { + if searcher.binary_detection().quit_byte().is_some() { + if let Some(ref path) = self.path { + log::debug!( + "ignoring {path}: found binary data at \ + offset {binary_byte_offset}", + path = path.as_path().display(), + ); + } + } self.binary_byte_offset = Some(binary_byte_offset); Ok(true) } diff --git a/crates/printer/src/summary.rs b/crates/printer/src/summary.rs index e69703fe..275419d4 100644 --- a/crates/printer/src/summary.rs +++ b/crates/printer/src/summary.rs @@ -688,6 +688,23 @@ impl<'p, 's, M: Matcher, W: WriteColor> Sink for SummarySink<'p, 's, M, W> { Ok(!self.should_quit()) } + fn binary_data( + &mut self, + searcher: &Searcher, + binary_byte_offset: u64, + ) -> Result<bool, io::Error> { + if searcher.binary_detection().quit_byte().is_some() { + if let Some(ref path) = self.path { + log::debug!( + "ignoring {path}: found binary data at \ + offset {binary_byte_offset}", + path = path.as_path().display(), + ); + } + } + Ok(true) + } + fn begin(&mut self, _searcher: &Searcher) -> Result<bool, io::Error> { if self.path.is_none() && self.summary.config.kind.requires_path() { return Err(io::Error::error_message(format!( diff --git a/crates/printer/src/util.rs b/crates/printer/src/util.rs index 04f9e129..825f81c1 100644 --- a/crates/printer/src/util.rs +++ b/crates/printer/src/util.rs @@ -344,7 +344,7 @@ impl<'a> PrinterPath<'a> { } /// Return this path as an actual `Path` type. - fn as_path(&self) -> &Path { + pub(crate) fn as_path(&self) -> &Path { #[cfg(unix)] fn imp<'p>(p: &'p PrinterPath<'_>) -> &'p Path { use std::{ffi::OsStr, os::unix::ffi::OsStrExt}; diff --git a/tests/feature.rs b/tests/feature.rs index ce5459c2..e2786854 100644 --- a/tests/feature.rs +++ b/tests/feature.rs @@ -425,7 +425,6 @@ rgtest!(f411_parallel_search_stats, |dir: Dir, mut cmd: TestCommand| { dir.create("sherlock_2", SHERLOCK); let lines = cmd.arg("-j2").arg("--stats").arg("Sherlock").stdout(); - dbg!(&lines); assert!(lines.contains("4 matched lines")); assert!(lines.contains("2 files contained matches")); assert!(lines.contains("2 files searched")); |