Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solving extra blank line error #441 #651

Closed
wants to merge 1 commit into from

Conversation

deg4uss3r
Copy link

Hi guys taking a stab at #441

There are 3 tests that are failing:

  • search_stream::tests::after_context_invert_one1
  • search_stream::tests::before_context_invert_one1
  • search_stream::tests::invert_match_line_numbers

This has to do with the way the tests are passed, since a command line test produces the correct assertion:

> ../target/debug/rg 'Sherlock' -v -C 1 ./sherlock 
1-For the Doctor Watsons of this world, as opposed to the Sherlock
2:Holmeses, success in the province of detective work must always
3-be, to a very large extent, the result of luck. Sherlock Holmes
4:can extract a clew from a wisp of straw or a flake of cigar ash;
5:but Doctor Watson has to have it taken out for him and dusted,
6:and exhibited clearly, with a label attached.

Copy link
Owner

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for trying, I really appreciate it! Unfortunately, fixing this bug requires quite a bit more work. You need to know when you're at the end of the input, and you need to know it without impacting performance.

@@ -305,6 +306,9 @@ impl<W: WriteColor> Printer<W> {
self.write_path_sep(b':');
}
if let Some(line_number) = line_number {
if line_number > buf.lines().count() as u64 {
return;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but this just won't work on multiple levels. Firstly, buf doesn't necessarily contain the entire contents of the file being searched (this is true for the memory map searcher only). Secondly, buf.lines().count() is recounting all of the lines in the buffer every time a match is written, which would be a devastating performance regression.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Third, if the end user disabled line numbers, then this check won't run at all.

@BurntSushi BurntSushi closed this Nov 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants