New Diffs: Fetch diffs context in a single CommitDiff RPC
<!--IssueSummary start--> <details> <summary> Everyone can contribute. [Help move this issue forward](https://handbook.gitlab.com/handbook/marketing/developer-relations/contributor-success/community-contributors-workflows/#contributor-links) while earning points, leveling up and collecting rewards. </summary> - [Close this issue](https://contributors.gitlab.com/manage-issue?action=close&projectId=278964&issueIid=432554) </details> <!--IssueSummary end--> ## 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: ```ruby <<~EOS a lot of content EOS ``` ```diff a - lot + lot of strings of ``` We tried to introduce the improvements here [before](https://gitlab.com/gitlab-org/gitlab/blob/d5b6111214f5a5d444e7230daa7c054dd01f5717/lib/gitlab/diff/highlight.rb#L78-87) ([`diff_line_syntax_highlighting`](https://gitlab.com/gitlab-org/gitlab/-/issues/324159) 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 `CommitDiff` RPC output: existing problem that will be fixed by paginating commit diffs anyway
issue