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

Calculate line numbers correctly in raw/color-only mode #272

Merged
merged 2 commits into from
Aug 8, 2020

Conversation

yoichi
Copy link
Contributor

@yoichi yoichi commented Aug 5, 2020

fix #258

  - call handle_hunk_header_line() if line number option is set

  - insert empty line before hunk header line only if decoration style is set
src/delta.rs Outdated
@@ -131,7 +131,7 @@ where
painter.paint_buffered_minus_and_plus_lines();
state = State::HunkHeader;
painter.set_highlighter();
if should_handle(&state, config) {
if config.line_numbers || should_handle(&state, config) {
Copy link
Owner

Choose a reason for hiding this comment

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

Do you think it would make sense to incorporate the if config.line_numbers condition into should_handle so that all the logic is in one place?

@dandavison
Copy link
Owner

Thanks very much for this PR and test @yoichi, and the initial analysis in #258. I just have that question about how you think the code should ideally be organized.

Copy link

@alfredbez alfredbez left a comment

Choose a reason for hiding this comment

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

I can verify, that this will fix the bug

@dandavison
Copy link
Owner

Thanks very much for this work @yoichi. And @alfredbez for testing and reviewing.

I added one failing test in master that will pass when this branch is merged: 0e98077 (asserting that line numbers start at 1, not 0, under color-only)

@dandavison dandavison merged commit 8edff62 into dandavison:master Aug 8, 2020
@dandavison
Copy link
Owner

Now let's figure out what to do about side-by-side and then I'll get these fixes released, since add -p is important.

@yoichi yoichi deleted the line-number-in-raw branch August 8, 2020 23:18
writeln!(painter.writer)?;
if config.hunk_header_style.decoration_style != DecorationStyle::NoDecoration {
writeln!(painter.writer)?;
}
Copy link
Owner

Choose a reason for hiding this comment

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

@yoichi do you recall the logic here -- why do we want a newline only if hunk_header_style.decoration_style != DecorationStyle::NoDecoration? I'm sorry, I should have asked you to add a comment at the time. Given that hunk-header-style=omit is failing (#274), I'm thinking we need to do more work to characterize the conditions under which the newline and other alterations are permitted. If you have any thoughts then great, but if not don't worry!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the README configuration example, we instruct to use color-only option with interactive.diffFilter.
On the other hand, as a limitation of git, interactive.diffFilter requires one-to-one correspondence between input and output lines.
I guessed that we originally inserted the line break here because of the layout of the header, so I thought it would be reasonable to skip the layout change of inserting the line when there is no style. And it resolve the break of one-to-one correspondence noted above.

hunk-header-style=omit removes the header line so it also breaks one-to-one correspondence by another reason. Not to omit header in raw/color-only mode may solve that problem, I think.

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks @yoichi! I wonder whether I should get rid of that extra newline character completely, at least in order to get the code into an easy-to-understand state. And then consider re-introducing it. I think I added it in the big v0.2 update because I thought that the extra space made the diff easier to read.

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.

🐛 Mismatch in line numbers between git diff and git add -p
3 participants