diff

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangeType

type ChangeType string

ChangeType represents the type of change for a diff line.

const (
	ChangeAdd     ChangeType = "+"
	ChangeRemove  ChangeType = "-"
	ChangeContext ChangeType = " "
	ChangeDivider ChangeType = "~" // separates non-adjacent hunks

)

type DiffLine

type DiffLine struct {
	OldNum     int        // line number in old version (0 for additions)
	NewNum     int        // line number in new version (0 for removals)
	Content    string     // line content without the +/- prefix
	ChangeType ChangeType // changeAdd, ChangeRemove, ChangeContext, or ChangeDivider
}

DiffLine holds parsed line info from a diff.

func ParseUnifiedDiff

func ParseUnifiedDiff(raw string) ([]DiffLine, error)

ParseUnifiedDiff parses unified diff output into a slice of DiffLine entries. It handles the diff header, hunk headers, and content lines.

type FallbackRenderer added in v0.7.0

type FallbackRenderer struct {
	// contains filtered or unexported fields
}

FallbackRenderer wraps a *Git renderer and knows about --only file paths. it delegates to the inner renderer, falling back to disk read for --only files that are not present in the git diff.

func NewFallbackRenderer added in v0.7.0

func NewFallbackRenderer(inner *Git, only []string, workDir string) *FallbackRenderer

NewFallbackRenderer creates a FallbackRenderer that delegates to inner and falls back to reading files from disk for --only patterns not found in the git diff.

func (*FallbackRenderer) ChangedFiles added in v0.7.0

func (fr *FallbackRenderer) ChangedFiles(ref string, staged bool) ([]string, error)

ChangedFiles returns changed files from the inner renderer, then appends any --only files not already present in the result if they exist on disk.

func (*FallbackRenderer) FileDiff added in v0.7.0

func (fr *FallbackRenderer) FileDiff(ref, file string, staged bool) ([]DiffLine, error)

FileDiff returns the diff for a file. for files outside the repo (absolute paths that escape workDir), it skips the inner git renderer entirely and reads from disk. for in-repo files, it calls the inner renderer first; if the result is empty (no error, no lines) and the file matches an --only pattern, it falls back to reading the file from disk as all-context lines.

type FileReader added in v0.7.0

type FileReader struct {
	// contains filtered or unexported fields
}

FileReader is a standalone Renderer for use when no git repo is available. it reads --only files directly from disk and presents them as all-context lines.

func NewFileReader added in v0.7.0

func NewFileReader(files []string, workDir string) *FileReader

NewFileReader creates a FileReader that reads the given files from disk. relative paths are resolved against workDir.

func (*FileReader) ChangedFiles added in v0.7.0

func (r *FileReader) ChangedFiles(_ string, _ bool) ([]string, error)

ChangedFiles returns the file list, resolved against workDir, filtered to only those that exist on disk.

func (*FileReader) FileDiff added in v0.7.0

func (r *FileReader) FileDiff(_, file string, _ bool) ([]DiffLine, error)

FileDiff reads the file from disk and returns all lines as context DiffLines.

type Git

type Git struct {
	// contains filtered or unexported fields
}

Git provides methods to extract changed files and build full-file diff views.

func NewGit

func NewGit(workDir string) *Git

NewGit creates a new Git diff renderer rooted at the given working directory.

func (*Git) ChangedFiles

func (g *Git) ChangedFiles(ref string, staged bool) ([]string, error)

ChangedFiles returns a list of files changed relative to the given ref. If ref is empty, it shows uncommitted changes. If staged is true, shows only staged changes.

func (*Git) FileDiff

func (g *Git) FileDiff(ref, file string, staged bool) ([]DiffLine, error)

FileDiff returns the full-file diff view for a single file. The result is a sequence of DiffLine entries representing unchanged, added, and removed lines interleaved at their correct positions.

Jump to

Keyboard shortcuts

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