Skip to content

Allow empty context lines in fuzzy patch matching - #739

Open
liugedragon wants to merge 1 commit into
kpdecker:masterfrom
liugedragon:fix/fuzzy-blank-context
Open

liugedragon wants to merge 1 commit into
kpdecker:masterfrom
liugedragon:fix/fuzzy-blank-context

Conversation

@liugedragon

Copy link
Copy Markdown

With fuzzFactor: 1, replacing a context line with x works, but replacing it with an empty line can make the same patch fail. An extra empty context line has the same problem.

The matcher uses a truthiness check before trying context substitutions and insertions. An empty string is a valid file line, so use an explicit non-null check, as the deletion branch already does. End-of-file handling and exact matching remain unchanged.

Nine regression tests cover substitutions and insertions with LF, CRLF, and automatic CRLF-to-LF conversion, plus strict matching, missing EOF context, and required deletion lines. On unchanged upstream, four fail and five controls pass; all nine pass with this change.

Validation:

  • Ubuntu 22.04 / Node 22.18.0 / Yarn 4.18.1: yarn install --immutable and the complete yarn test passed: 327 tests, including lint, build, type checks, bundles, and coverage.
  • Windows: complete build and 196 patch tests passed.
  • A bounded 60,000-case comparison against the unchanged matcher with blank source lines encoded as ordinary nonempty tokens agreed throughout; 945 previously rejected cases now apply. Original context lines were unique and nonempty, with one source edit and fuzz budgets 0–2.
  • git diff --check: passed.

The fuzzy-search memoization work in #711 and #716 retains the condition fixed here.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant