v1.3.0
Added
- API: Added
mpatch::parse_conflict_markersto parse patches in the "Conflict Marker" format (<<<<,====,>>>>), commonly used in Git merge conflicts and AI suggestions. - API: Added
mpatch::PatchFormatenum andmpatch::detect_patchfunction to programmatically identify if content is a Unified Diff, Markdown block, or Conflict Marker. - API: Added
mpatch::parse_autoas a robust, unified entry point that automatically detects the format and parses the content accordingly. - Parser:
parse_diffsnow automatically detects and parses conflict marker blocks if standard unified diff parsing fails. - API: Added
mpatch::parse_single_patchto simplify the common workflow of parsing a diff that is expected to contain exactly one patch. It returns aResult<Patch, SingleParseError>, handling the "zero or many" cases as an error. - API: Added
ApplyOptions::new(),ApplyOptions::dry_run(), andApplyOptions::exact()as convenience constructors to simplify common configuration setups. - API: Added a high-level
mpatch::patch_content_strfunction for the common one-shot workflow of parsing a diff string and applying it to a content string. It handles parsing, validates that exactly one patch is present, and performs a strict application, returning the new content or a comprehensive error. - API: Added "strict" variants of the core apply functions:
try_apply_patch_to_file,try_apply_patch_to_content, andtry_apply_patch_to_lines. These functions return aResultand treat partial applications (where some hunks fail) as anErr, simplifying the common apply-or-fail workflow. - API: Implemented
std::fmt::DisplayforPatchandHunkto format them as a valid unified diff string. This provides a canonical representation useful for logging, debugging, and serialization. - API: Added fluent, chainable methods
ApplyOptions::with_dry_run(bool)andApplyOptions::with_fuzz_factor(f32)to simplify creating custom configurations. - API: Added convenience methods
ApplyResult::has_failures(),ApplyResult::failure_count(), andApplyResult::success_count()to simplify inspecting the outcome of a patch operation. - Parser:
parse_diffsnow scans all markdown code blocks for diffs, not just those explicitly tagged withdifforpatch. This allows extracting patches from blocks labeled with other languages (e.g.,```rust) often output by LLMs. - Parser:
parse_diffsis now lenient. Blocks that look like diffs but are syntactically invalid (e.g., missing file headers) are silently ignored instead of returning aParseError. This prevents the parser from choking on random code snippets that coincidentally resemble diff syntax.
Changed
- API:
patch_content_strandparse_single_patchnow useparse_autointernally. This means they now accept raw unified diff strings and conflict markers directly, in addition to the previously supported Markdown blocks. - CLI: The
mpatchcommand now automatically detects the input format usingparse_auto. This enables support for raw unified diffs and conflict markers as input files, alongside the existing Markdown support. - Parser: The Markdown parser now supports variable-length code fences (e.g.,
````). A code block opened withNbackticks requires a closing fence of at leastNbackticks. This enables support for files containing nested code blocks. - Performance: Optimized
Patch::from_textsto use the raw diff parser directly, avoiding unnecessary Markdown wrapping and string allocation.
Fixed
- Parser: Fixed false positives where diffs inside nested code blocks (such as examples in documentation) were incorrectly identified as patches. The parser now checks that patch signatures appear at the top level of the code block.
- CLI: Fixed a deadlock (freeze) that occurred when running with
-vvvv(debug report mode). The report generator now correctly manages file locks to prevent recursive locking when internal functions log debug messages.
Full Changelog: v1.2.0...v1.3.0