Skip to main content

parse_conflicts

Function parse_conflicts 

Source
pub fn parse_conflicts(content: &str) -> Result<Vec<ConflictSegment>>
Expand description

Parse a conflicted file’s content into text/conflict segments.

Errors with ErrorReason::Parse only on a genuinely malformed region: a <<<<<<<-opened region missing its ======= separator or >>>>>>> terminator. A =======/>>>>>>> run outside any region is treated as ordinary content (a Markdown/RST underline, a divider, a quoted email), so a file with no real conflict — or a real conflict alongside marker-like content — parses cleanly.

Contract: only marker runs of length >= 7 open a region (same threshold as has_conflict_markers), to avoid false positives on ordinary text with short </=/> runs. A file whose <<<<<<< markers were written with merge.conflictMarkerSize (or the conflict-marker-size attribute) below 7 will not be recognized as conflicted here: it comes back as a single ConflictSegment::Text even though a real git configured the same way would have treated it as conflicted. Callers that need to support smaller marker sizes must detect that out of band.