Documentation
¶
Index ¶
- func CurrentBranch() (string, error)
- func FileContentFromIndex(path string) ([]byte, error)
- func IsGitRepo() bool
- type ChangeStatus
- type DeletedLine
- type DiffInfo
- type FileChange
- type InlineSegment
- type Patch
- type PatchFile
- type ReviewSource
- func (s ReviewSource) Content(path string) ([]byte, error)
- func (s ReviewSource) Diff(path, oldPath string) (*DiffInfo, error)
- func (s ReviewSource) Files() ([]FileChange, error)
- func (s ReviewSource) PreviewContent(path string, before bool, limit int64) ([]byte, error)
- func (s ReviewSource) Snapshot() (ReviewSource, string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CurrentBranch ¶
CurrentBranch returns the current branch name, or "HEAD" when detached.
func FileContentFromIndex ¶
FileContentFromIndex returns a file's staged content.
Types ¶
type ChangeStatus ¶
type ChangeStatus int
ChangeStatus represents the type of change to a file.
const ( StatusModified ChangeStatus = iota StatusAdded StatusDeleted StatusRenamed StatusUntracked StatusBinary )
func (ChangeStatus) String ¶
func (s ChangeStatus) String() string
String returns the review.json status string for a change status.
type DeletedLine ¶
type DeletedLine struct {
OldLineNum int
Content string
Inline []InlineSegment
}
DeletedLine represents a line that was deleted from the old version.
type DiffInfo ¶
type DiffInfo struct {
CommonLines map[int]int `json:",omitempty"` // new-to-old coordinates supplied by the patch
ChangedLines map[int]bool // added/modified line numbers (1-based) in new file
InlineChanges map[int][]InlineSegment // inline changes keyed by new-file line number
DeletedAfter map[int][]DeletedLine // deleted lines keyed by the new-file line they appear after (0 = before line 1)
}
DiffInfo contains parsed diff information for a single file.
func DiffFile ¶
DiffFile returns full diff information for a file relative to the given ref. oldPath is the file's previous path when it was renamed, else "".
func DiffFileStaged ¶
DiffFileStaged returns diff information for the indexed version of a file. oldPath is the file's previous path when it was renamed, else "".
func (*DiffInfo) IgnoreWhitespace ¶
IgnoreWhitespace compares each replacement block without horizontal ASCII whitespace. It preserves source text and coordinates, including for partial patches, and never changes the original diff or hides added/deleted lines that have no matching line on the other side.
type FileChange ¶
type FileChange struct {
Path string
Status ChangeStatus
OldPath string // for renames
Binary bool
}
FileChange describes a single changed file.
func (FileChange) IsBinary ¶
func (f FileChange) IsBinary() bool
IsBinary also recognizes snapshots saved before binary detection was separated from the change status.
func (FileChange) ReviewStatus ¶
func (f FileChange) ReviewStatus() string
ReviewStatus preserves the Crit-compatible status for binary files.
type InlineSegment ¶
InlineSegment is a changed or unchanged portion of a replacement line.
type Patch ¶
Patch is a self-contained snapshot: reopening it never reads worktree files.
func ParsePatch ¶
ParsePatch accepts Git-style unified diffs, including git show preambles.
func (*Patch) Changes ¶
func (p *Patch) Changes() []FileChange
type PatchFile ¶
type PatchFile struct {
Change FileChange
Content string
Diff *DiffInfo
// Known is nil for complete content, otherwise it identifies the lines
// supplied by the patch. Empty placeholders must never become anchors.
Known map[int]bool
}
type ReviewSource ¶
ReviewSource describes both sides of a code review without treating refs as command options or reading working-tree contents for committed comparisons.
func ResolveRange ¶
func ResolveRange(value string) (ReviewSource, error)
func (ReviewSource) Diff ¶
func (s ReviewSource) Diff(path, oldPath string) (*DiffInfo, error)
Diff returns the diff of path. oldPath is the file's previous path when it was renamed, else "".
func (ReviewSource) Files ¶
func (s ReviewSource) Files() ([]FileChange, error)
func (ReviewSource) PreviewContent ¶
PreviewContent bounds reads before loading binary data into memory.
func (ReviewSource) Snapshot ¶
func (s ReviewSource) Snapshot() (ReviewSource, string, error)
Snapshot records raw changes, including mode and binary changes, without applying the display's whitespace filtering.