github Romelium/mpatch v1.3.0

latest releases: v1.6.4, v1.6.3, v1.6.2...
7 months ago

Added

  • API: Added mpatch::parse_conflict_markers to parse patches in the "Conflict Marker" format (<<<<, ====, >>>>), commonly used in Git merge conflicts and AI suggestions.
  • API: Added mpatch::PatchFormat enum and mpatch::detect_patch function to programmatically identify if content is a Unified Diff, Markdown block, or Conflict Marker.
  • API: Added mpatch::parse_auto as a robust, unified entry point that automatically detects the format and parses the content accordingly.
  • Parser: parse_diffs now automatically detects and parses conflict marker blocks if standard unified diff parsing fails.
  • API: Added mpatch::parse_single_patch to simplify the common workflow of parsing a diff that is expected to contain exactly one patch. It returns a Result<Patch, SingleParseError>, handling the "zero or many" cases as an error.
  • API: Added ApplyOptions::new(), ApplyOptions::dry_run(), and ApplyOptions::exact() as convenience constructors to simplify common configuration setups.
  • API: Added a high-level mpatch::patch_content_str function 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, and try_apply_patch_to_lines. These functions return a Result and treat partial applications (where some hunks fail) as an Err, simplifying the common apply-or-fail workflow.
  • API: Implemented std::fmt::Display for Patch and Hunk to 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) and ApplyOptions::with_fuzz_factor(f32) to simplify creating custom configurations.
  • API: Added convenience methods ApplyResult::has_failures(), ApplyResult::failure_count(), and ApplyResult::success_count() to simplify inspecting the outcome of a patch operation.
  • Parser: parse_diffs now scans all markdown code blocks for diffs, not just those explicitly tagged with diff or patch. This allows extracting patches from blocks labeled with other languages (e.g., ```rust) often output by LLMs.
  • Parser: parse_diffs is now lenient. Blocks that look like diffs but are syntactically invalid (e.g., missing file headers) are silently ignored instead of returning a ParseError. This prevents the parser from choking on random code snippets that coincidentally resemble diff syntax.

Changed

  • API: patch_content_str and parse_single_patch now use parse_auto internally. This means they now accept raw unified diff strings and conflict markers directly, in addition to the previously supported Markdown blocks.
  • CLI: The mpatch command now automatically detects the input format using parse_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 with N backticks requires a closing fence of at least N backticks. This enables support for files containing nested code blocks.
  • Performance: Optimized Patch::from_texts to 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

Don't miss a new mpatch release

NewReleases is sending notifications on new releases.