The findBestInsertForDelete function in the diff merge algorithm searches for matching inserts in both directions (before and after the delete in the changes array). When a delete and an unrelated insert happen to have identical content (e.g., same parameter name in different functions), the algorithm pairs them across logical sections, leaving the real replacement insert orphaned.
Example from xcp-ng/xcp-ng-tests#595 (tests/storage/linstor/conftest.py):
Delete (old:54): unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]],
Insert (new:53): unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]], ← in NEW function — WRONG PAIR
Insert (new:60): lvm_disk_paths: dict[Host, list[str]], ← orphaned, shows as pure +
Fix: In findBestInsertForDelete, change the lower bound from delIdx - maxDiffDistance to delIdx so only inserts appearing AFTER the delete in the changes array are considered. In git diff format, a paired delete+insert is always ordered - then +, so backward search is never needed.
Changed in three files (same pattern in all):
src/browser/lib/diff-worker.ts:277 — primary web worker
src/browser/ui/diff/utils/parse.ts:139 — UI-side parsing
src/api/diff.ts:261 — API-side parsing
The
findBestInsertForDeletefunction in the diff merge algorithm searches for matching inserts in both directions (before and after the delete in the changes array). When a delete and an unrelated insert happen to have identical content (e.g., same parameter name in different functions), the algorithm pairs them across logical sections, leaving the real replacement insert orphaned.Example from xcp-ng/xcp-ng-tests#595 (tests/storage/linstor/conftest.py):
Fix: In
findBestInsertForDelete, change the lower bound fromdelIdx - maxDiffDistancetodelIdxso only inserts appearing AFTER the delete in the changes array are considered. In git diff format, a paired delete+insert is always ordered-then+, so backward search is never needed.Changed in three files (same pattern in all):
src/browser/lib/diff-worker.ts:277— primary web workersrc/browser/ui/diff/utils/parse.ts:139— UI-side parsingsrc/api/diff.ts:261— API-side parsing