diff

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyHunk

func ApplyHunk(base string, h Hunk) string

ApplyHunk applies a single hunk to the base file content, producing a new file with only that hunk's changes. This gives difftastic a full file for tree-sitter parsing.

func BaseContent

func BaseContent(repoRoot string, staged bool, file string) (string, error)

BaseContent retrieves the base file content for diffing. For unstaged diffs: the index version (git show :file). For staged diffs: the HEAD version (git show HEAD:file).

func FirstHunkLine added in v0.2.0

func FirstHunkLine(repoRoot string, staged bool, file string) int

FirstHunkLine returns the new-file line of the first hunk in file's diff, so an editor can open at the change rather than the top of the file. Returns 0 (no specific line) when the diff can't be produced or parsed.

func ParallelStream added in v0.3.0

func ParallelStream(n int, work func(i int) string) <-chan string

ParallelStream runs work(0..n-1) concurrently, bounded to the CPU count, and returns a channel yielding each result in index order, closed when done. A changeset's files are diffed in parallel — difftastic is CPU-bound at ~1s per large file — while a progressive consumer gets each file as soon as the ones before it are ready. The channel is buffered to n so the workers never block if the consumer stops reading early (e.g. the user navigated away).

func RawNewFileDiff

func RawNewFileDiff(repoRoot, file string) (string, error)

RawNewFileDiff generates a unified diff for an untracked file by comparing /dev/null against the file.

func RawUnifiedDiff

func RawUnifiedDiff(repoRoot string, staged bool, file string) (string, error)

Types

type DiffOpts

type DiffOpts struct {
	Staged  bool
	Base    string
	Target  string
	Color   bool
	Width   int
	Display Display
}

type Display added in v0.2.0

type Display int

Display selects difftastic's layout. Auto picks side-by-side only when the pane is wide enough, otherwise inline — side-by-side halves an already-narrow pane and difftastic doesn't reliably honor --width.

const (
	DisplayAuto Display = iota
	DisplayInline
	DisplaySideBySide
)

func (Display) Next added in v0.2.0

func (d Display) Next() Display

Next cycles Auto → Inline → SideBySide → Auto for the layout toggle.

type Engine

type Engine interface {
	Diff(ctx context.Context, repoRoot, file string, opts DiffOpts) (string, error)
	DiffHunks(ctx context.Context, hunks []Hunk, filename, baseContent string, color bool, width int) []string
	Name() string
}

func NewEngine

func NewEngine() Engine

func NewPlainEngine added in v0.2.0

func NewPlainEngine() Engine

NewPlainEngine returns the plain git-diff engine — the non-structural alternative offered by the engine toggle.

type FileDiff

type FileDiff struct {
	Header string
	Path   string
	Hunks  []Hunk
}

func ParseUnifiedDiff

func ParseUnifiedDiff(raw string) []FileDiff

type Hunk

type Hunk struct {
	Header   string
	OldStart int
	OldCount int
	NewStart int
	NewCount int
	Lines    []string
}

func (Hunk) Patch

func (h Hunk) Patch(fileHeader string) string

Jump to

Keyboard shortcuts

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