Documentation
¶
Overview ¶
Package merge implements line diffs, unified diff output and three-way merges of text files.
Index ¶
- func IsBinary(data []byte) bool
- func JoinLines(lines []string) []byte
- func LineStats(a, b []byte) (added, deleted int)
- func SplitLines(data []byte) []string
- func Stats(edits []Edit) (added, deleted int)
- func Unified(oldName, newName string, a, b []byte, context int) string
- type Edit
- type EditKind
- type Labels
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsBinary ¶
IsBinary reports whether data looks like binary content (a NUL byte in the first 8000 bytes, the same rule git uses).
func LineStats ¶
LineStats returns the added and deleted line counts between two texts. Binary content counts as zero lines.
func SplitLines ¶
SplitLines splits text into lines that keep their "\n", so joining the lines gives back the exact input. A final line without "\n" is kept.
Types ¶
type Edit ¶
Edit is a run of lines: Equal covers a[A0:A1] == b[B0:B1], Delete removes a[A0:A1], Insert adds b[B0:B1].
type Labels ¶
type Labels struct {
Base, Ours, Theirs string
}
Labels name the sides in conflict markers.
type Result ¶
type Result struct {
Lines []string // merged text; contains conflict markers if Conflicts > 0
Conflicts int // number of conflicting regions
}
Result is the outcome of a three-way merge.
func Merge3 ¶
Merge3 merges ours and theirs, which both started from base. Regions changed on one side only take that side. Regions changed identically on both sides take the change once. Regions changed differently on both sides are conflicts and are written with diff3-style markers.
func Merge3Bytes ¶
Merge3Bytes is Merge3 on raw file contents. It reports ok=false without merging when any side is binary and the sides differ.