Skip to main content

Module conflict

Module conflict 

Source
Expand description

Typed model of git conflict markers — parse a conflicted file’s content into structured regions and write a chosen resolution back. Pure functions (no subprocess), so everything here is hermetic.

Handles git’s three merge.conflictStyles with one grammar: merge (2-way: ours/theirs), diff3 (3-way: ours/base/theirs), and zdiff3 (same markers as diff3 — the common affixes are already outside the region). Marker length is variable (merge.conflictMarkerSize, default 7) and is detected per region. Lines are kept verbatim (including \r\n and a missing trailing newline), so render is a byte-exact roundtrip.

jj note: files materialized with jj’s ui.conflict-marker-style = "git" use this exact grammar (with jj’s own labels) and parse here; jj’s native diff/snapshot styles live in vcs_jj::conflict.

Structs§

ConflictRegion
One conflicted region: the lines of each side plus the verbatim marker lines (kept so rendering is byte-exact).

Enums§

ConflictSegment
A conflicted file as a sequence of plain-text runs and conflict regions — the shape that keeps render a byte-exact roundtrip.
ResolutionSide
Which side of a conflict a resolution keeps.

Functions§

has_conflict_markers
Does content contain a line that looks like a conflict-start marker? Cheap pre-check before a full parse_conflicts.
parse_conflicts
Parse a conflicted file’s content into text/conflict segments.
render
Re-render segments verbatim — the byte-exact inverse of parse_conflicts.
resolve
Produce the file content with every conflict resolved to side.