Skip to content

Smart automatic diff expansion to entire function/logical block

Problem to solve.

When reviewing code, only 3 lines of context are shown around the change, but this is often insufficient. Reviewers can expand the diffs 20 lines at a time, but this is annoying when nearly every code change has insufficient context.

Further details

A simple improvement might be to increase the default context to +/- 5 lines, but this might also be insufficient. Increasing the default too much would make diffs larger, and make them harder to read.

Proposal

Simple changes:

  • increase default context to +/- 5 lines
  • if the gap between two hunks is less than 3 lines, just don't collapse the region between hunks

Complex proposal:

  • using indentation, expand up to +/- 10 lines within the same region of indentation so that hunk can expand to include the surrounding function/loop/iterator boundary if it is just outside the +/- 5 lines.

Ideally these change would be entirely automatic, and not be user configurable so that GitLab has great diffs by default.

Links / references

Edited by James Ramsay (ex-GitLab)