Documentation
¶
Overview ¶
Package textdiff computes a minimal unified line diff between two texts.
Index ¶
Constants ¶
const MaxDiffCells = 4_000_000
MaxDiffCells bounds the LCS table Hunks will build, after the common prefix and suffix are trimmed: the table is (m+1)*(k+1) ints. Past this the diff is refused rather than computed -- a changed 15,000-line lockfile would otherwise allocate about 1.8 GB inside the daemon to render one file.
Variables ¶
This section is empty.
Functions ¶
func Counts ¶ added in v0.7.0
Counts returns how many lines a change from old to new adds and removes, the "+12 -3" a file list shows. It uses the same prefix/suffix trim and LCS as Hunks; past MaxDiffCells it falls back to counting lines by multiset (a line present more times in new than in old is added, and vice versa), which never undercounts a pure addition or deletion and is cheap at any size -- a live run view must not stall on a rewritten lockfile.
func Hunks ¶ added in v0.5.0
Hunks returns a git-style unified diff of old and new, without file headers: hunks headed "@@ -a,b +c,d @@", lines prefixed ' ', '-' or '+', with three lines of context. ok is false when the changed region is too large to diff within MaxDiffCells; the caller should show the content instead.
Unified above renders the whole file, which suits short documents; a change set diff is read to find what changed, so only the changes and their context are shown.
func Unified ¶
Unified returns a unified diff of old and new, with each line prefixed by "-" (removed), "+" (added), or " " (context). It is a simple LCS-based diff sufficient for artifact-version comparison (documents are small); it is not a full Myers diff and may report a larger-than-minimal edit script.
Types ¶
This section is empty.