Documentation
¶
Overview ¶
Package merge implements three-way merge for text files.
A three-way merge uses three versions of a file:
- Base: the common ancestor version (what both sides started from)
- Local: the version with our changes
- Remote: the version with their changes
The algorithm computes line-level diffs from base→local and base→remote, then walks through both diffs simultaneously to classify each region:
- Neither side changed → keep base lines
- Only one side changed → take that side's changes (auto-merge)
- Both sides changed identically → take either (they agree)
- Both sides changed differently → conflict (insert markers around just those lines)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conflict ¶
type Conflict struct {
// OutputStartLine is the 1-based line number in the merged output
// where the <<<<<<< marker appears.
OutputStartLine int
// LocalLines are the local side's lines for this conflict.
LocalLines []string
// RemoteLines are the remote side's lines for this conflict.
RemoteLines []string
}
Conflict describes a single conflicting region in the merged output.
type Result ¶
type Result struct {
// Content is the merged file content. If there are conflicts,
// the conflicting regions are wrapped in conflict markers.
Content []byte
// HasConflicts is true if any regions could not be auto-merged.
HasConflicts bool
// Conflicts lists each conflicting region in the output.
Conflicts []Conflict
// AutoResolved is the number of regions where only one side changed
// and the change was applied automatically.
AutoResolved int
}
Result holds the outcome of a three-way merge.
func ThreeWay ¶
ThreeWay performs a three-way merge of base, local, and remote content. remoteName is used to annotate the conflict marker (e.g., "origin").
The merge works at line granularity:
- Compute edit scripts base→local and base→remote
- Convert each edit script into a sequence of "edit regions" — contiguous groups of lines that were changed together
- Walk both edit region lists simultaneously against the base, detecting overlaps and classifying each region
- Produce merged output with inline conflict markers only where needed
Click to show internal directories.
Click to hide internal directories.