Skip to content

Releases: Romelium/mpatch

v1.3.5

28 Dec 00:31

Choose a tag to compare

Performance

  • Search: Optimized the exact and whitespace-insensitive search logic to avoid unnecessary heap allocations (Box<dyn Iterator>), improving efficiency for exact matches.
  • Parser: Optimized memory allocation in parse_patches_from_lines by pre-allocating buffers for hunk lines, reducing reallocations during parsing.

🆚 Compare changes

v1.3.4

11 Dec 10:59

Choose a tag to compare

Fixed

  • Fuzzy Matching: Enhanced the fuzzy matching algorithm to be robust against indentation differences. It now calculates a "loose" similarity score based on trimmed lines, allowing patches with extra indentation (e.g., nested in Markdown lists) to correctly match flat code in the target file.
  • Patch Application: Implemented smart indentation adjustment. When applying a patch via fuzzy matching or whitespace-insensitive matching, the indentation of added lines is now dynamically adjusted to match the surrounding context of the target file, preventing "drift" or corruption of indentation styles.
  • Parser: Fixed a bug where indented code blocks inside a diff (e.g., within a list item in the diff content) were incorrectly interpreted as the end of the diff block. The parser now checks indentation to distinguish nested blocks from the closing fence.

Full Changelog: v1.3.3...v1.3.4

v1.3.3

23 Nov 05:41

Choose a tag to compare

Fixed

  • Parser: Fixed a bug where Git extended headers (e.g., diff --git, index, new file mode) appearing between file sections were incorrectly parsed as context lines for the preceding hunk. This prevents patch corruption when parsing raw Git output containing multiple files or metadata changes.

Full Changelog: v1.3.2...v1.3.3

v1.3.2

22 Nov 12:21

Choose a tag to compare

Fixed

  • Fuzzy Matching: Fixed a critical bug where applying a patch via fuzzy matching would overwrite local changes in the context lines (e.g., updated comments, different indentation). The application logic now performs a granular merge to preserve the target file's content while applying the patch's specific changes.
  • Context Restoration: Improved the heuristic for handling missing context lines. Missing lines at the end of a file are now restored (fixing truncated files), while missing lines in the middle of a block are treated as stale and skipped.

🆚 For more detail compare changes since 1.3.1.

v1.3.1

21 Nov 09:03

Choose a tag to compare

Performance

  • Search: Optimized the fuzzy matching algorithm by pre-calculating trimmed lines and using string references. This significantly reduces memory allocation and CPU usage when searching for hunk locations, especially in large files.

Full Changelog: v1.3.0...v1.3.1

v1.3.0

21 Nov 05:46

Choose a tag to compare

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

v1.2.0

17 Nov 14:30

Choose a tag to compare

Full Changelog: v1.1.1...v1.2.0

v1.1.0

11 Nov 08:45

Choose a tag to compare

Full Changelog: v1.0.0...v1.1.0

v1.0.0

05 Nov 02:21

Choose a tag to compare

Full Changelog: v0.3.1...v1.0.0

v0.3.1

02 Nov 04:31

Choose a tag to compare

Full Changelog: v0.3.0...v0.3.1