Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

batches: Fix Diffs render incorrectly#39377

Merged
Piszmog merged 4 commits into
mainfrom
rc/diff-render
Jul 26, 2022
Merged

batches: Fix Diffs render incorrectly#39377
Piszmog merged 4 commits into
mainfrom
rc/diff-render

Conversation

@Piszmog

@Piszmog Piszmog commented Jul 25, 2022

Copy link
Copy Markdown
Contributor

Closes #35492.

I removed a function at the bottom of a Go file to replicate the rendering issue. What I found was when an empty - line (not followed by unchanged lines) is removed, this causes the index of highlightedBase and hunkLines to be off (hunkLines is behind by one). This is because highlightedBase still includes the empty - line. So each hunkLine corresponds to the previous highlighted line.

To fix this, I simply increment baseLine by one if the empty - line is removed.

Test plan

Added Go test

Before

Screen Shot 2022-07-25 at 10 47 06

After

Screen Shot 2022-07-25 at 10 46 34

@cla-bot cla-bot Bot added the cla-signed label Jul 25, 2022
@Piszmog Piszmog requested a review from eseliger July 25, 2022 17:01
@Piszmog Piszmog marked this pull request as ready for review July 25, 2022 17:03
@Piszmog Piszmog requested review from a team and removed request for eseliger July 25, 2022 17:03
@Piszmog

Piszmog commented Jul 25, 2022

Copy link
Copy Markdown
Contributor Author

@mrnugget & @camdencheek I would appreciate a review on this since I see your names a lot when it comes to file diffs and this portion of the code.

@Piszmog Piszmog requested review from camdencheek and mrnugget July 25, 2022 17:05

@camdencheek camdencheek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This section of code is a mess of off-by-one footguns. I've had this issue sitting around forever because this part of the code scares me. Thank you for the additional tests. I don't think I can provide a meaningful review because it's been too long since my head has been in this code, but I'm happy to stamp a fix that solves your issue, includes tests, and doesn't cause any other test failures.

@eseliger eseliger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice, one more down in this nasty function. Thank you so much for picking this up, truly appreciated!

@mrnugget mrnugget left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similarily to @camdencheek I locked away all previous memories of working with this code in a vault hidden deeply in my mind, so I can't provide meaningful feedback on whether these 3 lines you changed are correct, but I can give you a huge 👍 on the test:code ratio for this part of the codebase.

@Piszmog Piszmog merged commit 7571e18 into main Jul 26, 2022
@Piszmog Piszmog deleted the rc/diff-render branch July 26, 2022 14:12
efritz pushed a commit that referenced this pull request Jul 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Diffs render incorrectly in preview mode

5 participants