Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FileEntryPaths ¶
FileEntryPaths extracts just the paths from a slice of FileEntry.
func RelativeAge ¶
RelativeAge formats a timestamp as a compact relative age string (3 chars wide). Examples: " 5m" (minutes), " 3h" (hours), " 2d" (days), " 1w" (weeks), " 4M" (months), " 2y" (years).
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 // MaxLineLength is the maximum line length (in bytes) that scanners will accept. // used by parseUnifiedDiff, readReaderAsContext, and parseBlame. MaxLineLength = 1024 * 1024 // BinaryPlaceholder is the content used for binary file placeholders. // parseUnifiedDiff returns this when git reports "Binary files ... differ". BinaryPlaceholder = "(binary file)" )
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
IsBinary bool // true when this line is a binary file placeholder
IsPlaceholder bool // true for non-content placeholders (broken symlink, non-regular file, too-long lines)
}
DiffLine holds parsed line info from a diff.
func ReadFileAsAdded ¶
ReadFileAsAdded reads a file from disk and returns all lines as ChangeAdd type. single-line placeholder results (broken symlinks, non-regular files, binary, too-long lines) keep ChangeContext.
type DirectoryReader ¶
type DirectoryReader struct {
// contains filtered or unexported fields
}
DirectoryReader is a Renderer that lists all git-tracked files and reads them as context lines. used for --all-files mode where every tracked file is browsable, not just changed files.
func NewDirectoryReader ¶
func NewDirectoryReader(workDir string) *DirectoryReader
NewDirectoryReader creates a DirectoryReader rooted at the given working directory. the directory must be inside a git repository.
func (*DirectoryReader) ChangedFiles ¶
func (dr *DirectoryReader) ChangedFiles(_ string, _ bool) ([]FileEntry, error)
ChangedFiles returns all git-tracked files as sorted relative paths. ref and staged parameters are ignored since all tracked files are returned.
type ExcludeFilter ¶
type ExcludeFilter struct {
// contains filtered or unexported fields
}
ExcludeFilter wraps a renderer and filters out files matching any of the given prefixes. filtering is applied only at the file list level (ChangedFiles); FileDiff delegates directly.
func NewExcludeFilter ¶
func NewExcludeFilter(inner renderer, prefixes []string) *ExcludeFilter
NewExcludeFilter creates an ExcludeFilter that removes files matching any prefix from results.
func (*ExcludeFilter) ChangedFiles ¶
func (ef *ExcludeFilter) ChangedFiles(ref string, staged bool) ([]FileEntry, error)
ChangedFiles returns files from the inner renderer, excluding any that match a prefix.
type FallbackRenderer ¶
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 ¶
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 ¶
func (fr *FallbackRenderer) ChangedFiles(ref string, staged bool) ([]FileEntry, 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 ¶
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 FileEntry ¶
type FileEntry struct {
Path string // file path relative to repo root
Status FileStatus // file change status, empty for non-git renderers
}
FileEntry represents a file with its change status from git diff.
type FileReader ¶
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 ¶
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 ¶
func (r *FileReader) ChangedFiles(_ string, _ bool) ([]FileEntry, error)
ChangedFiles returns the file list, resolved against workDir, filtered to only those that exist on disk.
type FileStatus ¶
type FileStatus string
FileStatus represents the change type of a file in a git diff.
const ( FileAdded FileStatus = "A" FileModified FileStatus = "M" FileDeleted FileStatus = "D" FileRenamed FileStatus = "R" FileUntracked FileStatus = "?" )
type Git ¶
type Git struct {
// contains filtered or unexported fields
}
Git provides methods to extract changed files and build full-file diff views.
func (*Git) ChangedFiles ¶
ChangedFiles returns a list of files changed relative to the given ref with their change status. If ref is empty, it shows uncommitted changes. If staged is true, shows only staged changes. Uses -z for NUL-terminated output to handle filenames with special characters.
func (*Git) FileBlame ¶
FileBlame returns blame information for each line of the rendered side of a file diff. For unstaged single-ref diffs this is the worktree; for two-ref diffs this is the target ref. For staged diffs this is the index snapshot. The returned map is keyed by 1-based line number (matching DiffLine.NewNum).
func (*Git) FileDiff ¶
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. For binary files, it returns a single placeholder line with size delta information.
func (*Git) UntrackedFiles ¶
UntrackedFiles returns untracked files (not in .gitignore) using git ls-files --others --exclude-standard.
type StdinReader ¶
type StdinReader struct {
// contains filtered or unexported fields
}
StdinReader is an in-memory renderer for scratch-buffer review mode.
func NewStdinReader ¶
func NewStdinReader(name string, lines []DiffLine) *StdinReader
NewStdinReader creates a renderer that exposes a single synthetic file backed by in-memory lines.
func NewStdinReaderFromReader ¶
func NewStdinReaderFromReader(name string, r io.Reader) (*StdinReader, error)
NewStdinReaderFromReader reads arbitrary content into context lines and exposes it as one synthetic file.
func (*StdinReader) ChangedFiles ¶
func (r *StdinReader) ChangedFiles(_ string, _ bool) ([]FileEntry, error)
ChangedFiles returns the single synthetic filename.