Skip to content

Fix diff merge algorithm pairing deletes with wrong inserts across sections #247

Description

@glehmann

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Default priorityimplementedVerified locally; awaiting merge to main

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions