diff

package
v1.1.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapOldLineToNew

func MapOldLineToNew(entries []DiffEntry) map[int]int

MapOldLineToNew builds a mapping from old line numbers to new line numbers using the diff entries. For unchanged lines it maps directly. For removed lines it maps to the nearest subsequent new line in the new document. Returns a map[int]int where key=old line, value=new line.

func SplitLines

func SplitLines(content string) []string

SplitLines splits content into lines, returning an empty slice for empty input.

Types

type DiffEntry

type DiffEntry struct {
	Type    string `json:"type"`               // "unchanged", "added", or "removed"
	OldLine int    `json:"old_line,omitempty"` // 1-based line number in old content (0 if added)
	NewLine int    `json:"new_line,omitempty"` // 1-based line number in new content (0 if removed)
	Text    string `json:"text"`
}

DiffEntry represents a single line in the diff output.

func ComputeLineDiff

func ComputeLineDiff(oldContent, newContent string) []DiffEntry

ComputeLineDiff computes a line-level diff between oldContent and newContent using Hirschberg's algorithm (divide-and-conquer LCS in O(n) space). Each line is classified as "unchanged", "added", or "removed".

type DiffHunk

type DiffHunk struct {
	OldStart int
	OldCount int
	NewStart int
	NewCount int
	Header   string // the @@ line text
	Lines    []DiffLine
}

DiffHunk represents a single hunk in a unified diff.

func DiffEntriesToHunks

func DiffEntriesToHunks(entries []DiffEntry) []DiffHunk

DiffEntriesToHunks converts LCS diff entries into DiffHunk format (same as git diff), so the frontend can use one unified renderer. Groups changes with 3 lines of context.

type DiffLine

type DiffLine struct {
	Type    string // "context", "add", "del"
	Content string
	OldNum  int // 0 if add
	NewNum  int // 0 if del
}

DiffLine represents a single line within a diff hunk.

Jump to

Keyboard shortcuts

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