Documentation
¶
Index ¶
- func ApplyHunk(base string, h Hunk) string
- func BaseContent(repoRoot string, staged bool, file string) (string, error)
- func FirstHunkLine(repoRoot string, staged bool, file string) int
- func ParallelStream(n int, work func(i int) string) <-chan string
- func RawNewFileDiff(repoRoot, file string) (string, error)
- func RawUnifiedDiff(repoRoot string, staged bool, file string) (string, error)
- type DiffOpts
- type Display
- type Engine
- type FileDiff
- type Hunk
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyHunk ¶
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 ¶
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
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
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 ¶
RawNewFileDiff generates a unified diff for an untracked file by comparing /dev/null against the file.
Types ¶
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.
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 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.