Help us shape the future of Go! Take the 2026 Go Developer Survey

diff

package
v1.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Align added in v1.19.0

func Align[T comparable](a, b []T) []int

Align matches a against b along a longest common subsequence: for each element of a it returns the index of the element of b it is paired with, or -1 when it is not part of the subsequence. Pairs are strictly increasing in both a and b. It runs Myers' O((N+M)D) algorithm in linear space — splitting each problem at the middle of its shortest edit path (the bisection diff-match-patch uses) — so long inputs with many differences need no frontier history and no budget.

func Unified

func Unified(oldBody, newBody string) string

Unified produces a standard unified diff (3 context lines) of two file bodies for the agent harness’s edit/write tools. The output round-trips through Parse so the existing renderDiffBlock pipeline renders agent edits exactly like any other diff block. Returns "" when the bodies are identical. No ---/+++ file header is emitted: toolDiffMsg carries the path separately and Parse drops pre-@@ lines anyway.

Types

type Hunk

type Hunk struct {
	OldStart int
	OldLines int
	NewStart int
	NewLines int
	Lines    []string
}

Hunk represents a unified diff hunk.

func Parse

func Parse(s string) []Hunk

Parse turns a unified diff string into a slice of Hunks. Lines whose first character is neither space, +, -, nor \ are kept verbatim (no prefix re-writing) so renderDiffBlock’s existing prefix-based styling applies. Lines before the first `@@` (file headers like "--- a/f") are dropped — we already know the path from the FileUpdateChange record.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL