Releases: Romelium/mpatch
Releases · Romelium/mpatch
v1.3.5
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_linesby pre-allocating buffers for hunk lines, reducing reallocations during parsing.
v1.3.4
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
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
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
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
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
v1.2.0
Full Changelog: v1.1.1...v1.2.0
v1.1.0
Full Changelog: v1.0.0...v1.1.0
v1.0.0
Full Changelog: v0.3.1...v1.0.0
v0.3.1
Full Changelog: v0.3.0...v0.3.1