Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Fix bug expanding large-diff-gated patches with comments #2007

Merged
merged 4 commits into from
Mar 6, 2019

Conversation

annthurium
Copy link

Description of the Change

Once upon a time, there was a bug where clicking "expand" on a file patch that exceeded the large diff gate size, that had comments, would throw a stacktrace. Sadness!

@vanessayuenn and I determined that the root cause of this bug was that because large patches are initially collapsed, we were never populating the red and black tree used to keep track of the diff offset indices for comment placement.

Solution was to extract a function to populate the diff offset indices, and then call that function when expanding file patches.

Screenshot/Gif

N/A

Alternate Designs

None considered.

Benefits

Users can now expand large-diff-gated file patches that contain comments without errors and sadness. (Well, I can't guarantee there will be no sadness.)

Possible Drawbacks

Can't think of any drawbacks but if you can, I'm open to discussion.

Applicable Issues

Metrics

N/A

Tests

  • Wrote unit test to ensure that:

    • we are only populating the diffOffsetIndices if it's empty
    • after expanding an initially-collapsed too large pass, calling getBufferRowForDiffPosition in fact gives us the correct buffer row.
  • Manually testing expanding the file patch on https://github.com/kuychaco/test-repo/pull/7

Documentation

Added one code comment like a champ.

Release Notes

This bug is for a feature that hasn't been released yet so I'm ok leaving it out of the release notes.

User Experience Research (Optional)

N/A

annthurium and others added 3 commits March 6, 2019 12:07
File patches that exceed the large diff threshold are initially collapsed.  We were not actually populating the diffRowOffsetIndex for these collapsed patches.  When expanding a collapsed patch with comments, we'd try to use the diffRowOffsetIndex which was empty, and throw an error.

Co-Authored-By: Vanessa Yuen <vanessayuenn@users.noreply.github.com>
Co-Authored-By: Vanessa Yuen <vanessayuenn@users.noreply.github.com>
Co-Authored-By: Vanessa Yuen <vanessayuenn@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Mar 6, 2019

Codecov Report

Merging #2007 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2007      +/-   ##
==========================================
- Coverage   92.58%   92.58%   -0.01%     
==========================================
  Files         189      189              
  Lines       11237    11244       +7     
  Branches     1633     1634       +1     
==========================================
+ Hits        10404    10410       +6     
- Misses        833      834       +1
Impacted Files Coverage Δ
lib/models/patch/multi-file-patch.js 100% <100%> (ø) ⬆️
lib/github-package.js 68.09% <0%> (-0.39%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 14c238c...41136a6. Read the comment docs.

@annthurium annthurium requested a review from a team March 6, 2019 20:45
Copy link
Contributor

@kuychaco kuychaco 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 putting in this fix so quickly! It looks good 👍

Just left a couple of comments -- one suggestion and one question about a potential edge case. But I think neither of them are necessarily ship-blocking.

const diffRowOffsetIndex = this.diffRowOffsetIndices.get(filePatch.getPath());
// if the patch was initially collapsed, we need to calculate
// the diffRowOffsetIndices to calculate comment position.
if (diffRowOffsetIndex.index.size === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

🎨minor readability suggestion -- I noticed I had to look at this a couple times, as well as assert.strictEqual(multiFilePatch.diffRowOffsetIndices.get('1.txt').index.size, 0) in the tests.

Perhaps we could add a method diffRowOffsetIndexUnpopulated that does this check and reads more declaratively. And we can also use the method to improve readability in our test assertions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm is there an edge case here for symlink and file mode change diffs that would have empty indexes? I guess we'd just unnecessarily call populateDiffRowOffsetIndices and create a new empty index, which isn't a big deal. It's probably not worth the extra effort to distinguish between empty indexes from large diffs versus symlink or file mode changes, huh?

Copy link
Author

Choose a reason for hiding this comment

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

yeah, I'd take readability and simplicity over dealing with symlink and file mode changes here. Creating a new empty index shouldn't impact performance very much.

I'll work on the other changes though, thanks for the suggestion.

@annthurium annthurium requested a review from a team March 6, 2019 22:54
@annthurium annthurium merged commit c0f6679 into master Mar 6, 2019
@annthurium annthurium deleted the tt-19-mar-destructure-bug branch March 6, 2019 23:35
@vanessayuenn vanessayuenn mentioned this pull request Mar 7, 2019
9 tasks
@smashwilson smashwilson mentioned this pull request Apr 8, 2019
3 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants