Description
Hi,
I recently encountered a bug where the way diffs are calculated differs from GitLab’s approach.
I've created an example to illustrate the issue. There are two lists to simulate lines before and after the changes.
There are two identical blocks of lines, so the changes can be interpreted in two different ways:
Git's approach: The first six lines are replaced with two new lines, while the last two lines remain unchanged.
DiffUtils' approach: The first two lines are replaced with two new lines, the next two lines remain unchanged, and the last four lines are removed.
While both approaches lead to the same final result, DiffUtils returns CHANGE, EQUAL, and DELETE blocks, whereas Git only uses CHANGE and EQUAL.
List<String> beforeChanges = List.of(
"differentLine1",
"differentLine2",
"sameLine1",
"sameLine2",
"differentLine3",
"differentLine4",
"sameLine1",
"sameLine2"
);
List<String> afterChanges = List.of(
"newDifferentLine1",
"newDifferentLine2",
"sameLine1",
"sameLine2"
);
var deltas = DiffUtils.diff(beforeChanges, afterChanges, true).getDeltas();
I'm attaching screens how this operation looks in github and how looks output from DiffUtils
Can you please fix the way the Diffs are calculated to match Git?