FA-75418 / Text diff and three-way merge / Member archive
Patch application with offset search: the discovered offset is not carried to later hunks · case 03
After one hunk applies with an offset, later hunks are searched from stale positions and may be rejected.
Case contract
Hunks [old_start, old_lines, new_lines] are applied in order. The expected index is old_start-1 plus the accumulated shift. The search tries distance 0, then 1, 2, ... up to max_offset, at each distance the earlier position before the later one; the first position where old_lines match replaces them with new_lines. After an applied hunk the shift grows by (found-expected) + len(new)-len(old); a hunk that does not match is rejected and changes nothing. Return lines, 1-based applied positions and rejected hunk indices.
Why this case matters
Patch tools tolerate drift by searching near the expected line and carrying the discovered offset to later hunks.
One recorded failure
Sample boundary fixtureThis sample comes from the broken implementation of a controlled reproducer.
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| carried offset keeps a far hunk in range | {"applied": [5], "lines": ["pre", "pre", "pre", "l1", "L2", "l3", "l4", "l5", "ins1", "ins2", "l6", "l7", "l8", "l9", "l10", "l11", "l12"], "rejected": [1]} | {"applied": [5, 13], "lines": ["pre", "pre", "pre", "l1", "L2", "l3", "l4", "l5", "ins1", "ins2", "l6", "l7", "L83", "l9", "l10", "l11", "l12"], "rejected": []} | Failed |
MEMBER ARCHIVE
The complete case is available to members.
This record includes three runnable implementations, regression fixtures, execution results, and source hashes.
Member access is invitation-based. Sign in with your invited account to inspect the sources.
Sign in to the archive ↗