[Feature Proposal] Diff: Display Moved lines (ala git diff --color-moved)
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Release notes
Diff viewer has ability to detect and display moved lines of code
Problem to solve
Some changes are conceptually very small, but generate large diffs - for instance, a change that simply moves the location of a single long function, with no code changes. Conceptually, the change is simple: "Moved lines XXX-YYY to UUU-VVV". But for a 100-line function, this will generate 200 lines of diffs - 100 removal lines, and 100 addition lines.
For someone having to review such a change, there is no easy way to tell if any of the lines have been altered or not - generally, the reviewer has to either:
- assume the lines are unchanged
- laboriously manually review all moved lines
- resort to a third party tool, that allows display of moved chunks of code
Proposal
We can leverage an existing solution to this problem: git's support for this feature via it's git diff --color-moved option:
https://git-scm.com/docs/git-diff#Documentation/git-diff.txt-code--color-movedltmodegtcode
We can use this feature as either an inspiration (ie, display moved lines via different colorations) or actual backend (use git's implementation, either via subprocess call of a git binary, or by using the source code - licenses allowing).
The most basic implementation could be as simple as --color-moved - ie, a different color scheme (with perhaps a legend showing how to interpret them).
The next (or alternative) level of implementation might be to add text describing the type of diff block ("Moved Code", "New Lines", "Removed Lines"), with perhaps a link to the corresponding old/new block for "Moved Code".
More UI fanciness could be designed around this feature (ie, similar to those used by SemanticDiff - https://semanticdiff.com/)... though many users might prefer a faster implementation / release to lots of custom UI niceties (myself included).
Most likely, this feature would be implemented as an optional additional way to view diffs, due to the additional complexity, potential changes to the UI, and familiarity of users with "standard" diffs.
However, it's possible that if the the underlying algorithm was reliable / performant enough, and the UI integration was fairly seamless and unobtrusive, then it could be added as an "always on" feature for all diffs.
Related Issues
-
Gitlab Issue 393875: [Feature Request] Add support Semantic Diffs
This feature request is similar (add additional capabilities to diff views, to make them "smarter"), but with a different approach, and is less narrowly defined. Precisely what they mean by a "Semantic Diff" isn't well defined - some definitions of a "Semantic Diff" would encompass this Feature Proposal, and more - for instance, the "SemanticDiff" product (https://semanticdiff.com) includes moved lines detection. However, the approach used by "Difftastic" (https://github.com/Wilfred/difftastic), which the issue author references, does NOT feature moved line detection. The makers of "SemanticDiff" made a post describing the differences: https://semanticdiff.com/blog/semanticdiff-vs-difftastic/.
Note that both of those products feature / rely on knowledge of the synatax of particular languages - I am proposing a language-agnostic approach, which works purely on text diffs, similar to
git diff --color-moved. -
Github Issue 9632: [Feature request] Use "--color-moved" diffing algorithm in PRs
A similar feature request was made for github
Intended users
This would be usable by anyone reviewing code diffs / merge requests, including Developers and Managers. It has the potential to both speed up code reviews and improve code review quality. A one-line accidental typo while moving a large function could be easily detected.
The roles most likely to benefit directly would be those heavily involve in editing and reviewing code, or configuration stored as text in a repository, such as:
- Delaney (Development Team Lead)
- Sasha (Software Developer)
- Priyanka (Platform Engineer)
- Sidney (Systems Administrator)
- Simone (Software Engineer in Test)
- Allison (Application Ops)
- Ingrid (Infrastructure Operator)
- Dana (Data Analyst)
- Eddie (Content Editor)
- Amy (Application Security Engineer)
- Isaac (Infrastructure Engineer)
- Alex (Security Operations Engineer)
Feature Usage Metrics
If this feature is implemented as an optional diff "mode" or "view", then it would be fairly easy to track how often users opt to use this mode.
If it's an "always on" feature, or if you simply wanted more detailed metrics, you could track:
- If UI features specific to this feature are added (ie, links to corresponding chunks of text, or buttons to expand the "other side of the move" in-place) usage of these could be tracked
- You could keep statistics on how often moved lines were detected, and what percentage of the diff lines were detected as moves within a changeset, or how often changesets had a move-percentage that exceeded some threshold (say, > 50% of the altered lines were classified as moves).
Does this feature require an audit event?
No - a diff view in itself results in no changes, and happens too frequently to be of interest to auditors.