pub fn detect_patch(content: &str) -> PatchFormatExpand description
Automatically detects the patch format of the provided content.
This function scans the content efficiently (without parsing the full structure) to determine if it contains Markdown code blocks, standard unified diff headers, or conflict markers.
§Behavior
The detection follows this priority:
- Markdown: If code fences (3+ backticks) are found containing diff signatures, it is treated as Markdown.
- Unified: If
--- a/ordiff --githeaders are found, it is treated as a Unified Diff. - Conflict: If
<<<<markers are found, it is treated as Conflict Markers.
§Arguments
content- A string slice containing the patch data to analyze.
§Returns
The detected PatchFormat.
§Examples
use mpatch::{detect_patch, PatchFormat};
let md = "```diff\n--- a/f\n+++ b/f\n```";
assert_eq!(detect_patch(md), PatchFormat::Markdown);
let raw = "--- a/f\n+++ b/f\n@@ -1 +1 @@";
assert_eq!(detect_patch(raw), PatchFormat::Unified);