Skip to content
Myr

printer: fix `--stats` for `--json`

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

Somehow, the JSON printer seems to have never emitted correct summary statistics. And I believe #3178 is the first time anyone has ever reported it. I believe this bug has persisted for years. That's surprising. Anyway, the problem here was that we were bailing out of `finish()` on the sink if we weren't supposed to print anything. But we bailed out before we tallied our summary statistics. Obviously we shouldn't do that. Fixes #3178

authored by Andrew Gallant · committed by Andrew Gallant · parent b610d1c · Browse files · 2 files+5 added−4 removed
This commit

State

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

Diff stats

2 files+5 added−4 removed

  • other:+5 added−4 removed

2 files+5 added−4 removed

modified:crates/printer/src/json.rs+3 added-4 removed
815 unmodified lines
816 &mut self,817 _searcher: &Searcher,818 finish: &SinkFinish,819 ) -> Result<(), io::Error> {820 if !self.begin_printed {821 return Ok(());822 }823820 self.binary_byte_offset = finish.binary_byte_offset();821 self.stats.add_elapsed(self.start_time.elapsed());822 self.stats.add_searches(1);823 if self.match_count > 0 {
1 unmodified line
825 }826 self.stats.add_bytes_searched(finish.byte_count());827 self.stats.add_bytes_printed(self.json.wtr.count());828829 if !self.begin_printed {830 return Ok(());831 }832 let msg = jsont::Message::End(jsont::End {833 path: self.path,834 binary_offset: finish.binary_byte_offset(),835 stats: self.stats.clone(),
222 unmodified lines
modified:CHANGELOG.md+2 added
48 unmodified lines
49* [BUG #3155](https://github.com/BurntSushi/ripgrep/issues/3155):50 Statically compile PCRE2 into macOS release artifacts on `aarch64`.51* [BUG #3173](https://github.com/BurntSushi/ripgrep/issues/3173):52 Fix ancestor ignore filter bug when searching whitelisted hidden files.53* [BUG #3178](https://github.com/BurntSushi/ripgrep/discussions/3178):54 Fix bug causing incorrect summary statistics with `--json` flag.55* [BUG #3179](https://github.com/BurntSushi/ripgrep/issues/3179):56 Fix gitignore bug when searching absolute paths with global gitignores.57* [BUG #3180](https://github.com/BurntSushi/ripgrep/issues/3180):58 Fix a panicking bug when using `-U/--multiline` and `-r/--replace`.
1739 unmodified lines