New Diffs: Fetch diffs context in a single CommitDiff RPC
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Summary
In order to highlight the diff of a file, we fetch the old and new versions of a file to get the whole context for the diff.
For example, when a multiline string is opened out of the diff context, we still want to highlight the inner content as a string:
<<~EOS
a
lot
of
content
EOS
a
- lot
+ lot of strings
of
We tried to introduce the improvements here before (diff_line_syntax_highlighting feature flag), but encountered problems with Vue files that contain html and js at the same time.
Fetching the old and new versions of files can take 10mb for each file which is slow and requires transferring/buffering a lot of data.
Proposal
git diff supports -U<n> (--unified<n>) option: https://git-scm.com/docs/git-diff, where n is the number of lines added for the diff context. Instead of fetching the files, we can specify a reasonable number to get the diff with context.
Pros
- Doesn't require fetching old/new versions of the files anymore
- Allows retrieving diffs with contexts within a single RPC
Cons
- May require additional logic for extracting old/new versions of a file from the diff file
- Old version of a file: unchanged lines + removed lines
- New version of a file: unchanged lines + added lines
- Both versions are highlighted
- Highlightlighted diff is generated
- Increases the size and processing time of
CommitDiffRPC output: existing problem that will be fixed by paginating commit diffs anyway