Performance
- Patch Creation: Optimized
Patch::from_textsto construct hunks directly from diff operations, avoiding the overhead of generating and re-parsing a unified diff string. - Formatting: Optimized
Hunk::fmtto calculate line counts in a single pass.
Fixed
- Patch Application: Fixed a bug where a trailing newline was incorrectly added to files lacking one, even if the patch only modified lines at the beginning or middle of the file. The original newline status is now preserved unless the patch explicitly modifies the end of the file.
- Patch Application: Fixed a bug where files resulting in exactly one newline (e.g., replacing all content with a single empty line) were incorrectly truncated to 0 bytes.
- Parser: Fixed handling of the
\ No newline at end of filemarker. It now correctly verifies that the marker immediately follows a context or addition line. - Parser: Fixed parsing of empty hunks (e.g.,
@@ -0,0 +0,0 @@) which were previously ignored. - Parser: Fixed a bug where a context line in a diff that looks like a closing fence (e.g.,
```) would incorrectly terminate the markdown code block. The parser now enforces that a closing fence must not be more indented than the opening fence. - Parser: Improved Conflict Marker detection to prevent false positives from Markdown H1 headers (lines of
====). Detection now strictly requires a start marker (<<<<) followed by a middle (====) or end (>>>>) marker. - CLI: Fixed formatting in the debug report (
-vvvv) where final summary logs were appended outside the markdown code block, breaking the report structure.
Added
- CLI: Added
-R/--reverseflag to reverse patches before applying them (useful for undoing changes). - API: Added
mpatch::invert_patcheshelper function to programmatically invert a list of patches. - API: Added
HunkApplier::set_original_newline_statusto manually control the expected newline behavior when using the line-based API. - API: Derived
PartialEqforApplyOptions.
Changed
- Patch Application: Files are now automatically deleted if the patch application results in empty content.
- Internal: Refactored debug report finalization to be more robust and prevent redundant file locking.