diff

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Windows

func Windows(rawDiff string, maxBytes int, opts ...ParseOptions) ([]*DiffWindow, *ChangeInventory)

Windows is a package-level helper to parse and window a raw diff.

Types

type ChangeInventory

type ChangeInventory struct {
	Files      []*FileDiff `json:"files"`
	Omissions  []*Omission `json:"omissions"`
	TotalHunks int         `json:"total_hunks"`
	TotalFiles int         `json:"total_files"`
	Truncated  bool        `json:"truncated"`
}

ChangeInventory holds the parsed diff structure and omission records.

func Parse

func Parse(rawDiff string, options ...ParseOptions) *ChangeInventory

Parse parses a unified git diff into a ChangeInventory with hunk-atomic records and omission accounting.

func (*ChangeInventory) ChangedPRLines

func (inv *ChangeInventory) ChangedPRLines() map[string]map[int]bool

ChangedPRLines returns a map of file -> line -> true for all added lines on the new (RIGHT) side. Matches changedPRLines semantics from reviewer engine.

func (*ChangeInventory) FindFile

func (inv *ChangeInventory) FindFile(path string) *FileDiff

FindFile returns the FileDiff for the given path, or nil if not found.

func (*ChangeInventory) HunksForFile

func (inv *ChangeInventory) HunksForFile(path string) []*Hunk

HunksForFile returns all hunks for the given file path.

func (*ChangeInventory) Window

func (inv *ChangeInventory) Window(maxBytes int) *DiffWindow

Window returns the first hunk-atomic window under maxBytes. If any hunks or files could not fit or were omitted, Truncated is true.

func (*ChangeInventory) Windows

func (inv *ChangeInventory) Windows(maxBytes int) []*DiffWindow

Windows creates one or more hunk-atomic windows under the given byte budget. D-05: diff windowing never cuts inside a hunk. Oversized hunks become omission records.

type CoverageLedger

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

CoverageLedger tracks hunk-level examination and omission accounting across review plans. D-05: CoverageLedger starts every hunk as skipped with reason "not examined".

func NewCoverageLedger

func NewCoverageLedger(inv *ChangeInventory) *CoverageLedger

NewCoverageLedger initializes a ledger where every hunk and omission starts as skipped.

func (*CoverageLedger) Entries

func (l *CoverageLedger) Entries() []*LedgerEntry

Entries returns a copy of all ledger entries.

func (*CoverageLedger) Examined

func (l *CoverageLedger) Examined() []*LedgerEntry

Examined returns all examined ledger entries.

func (*CoverageLedger) ExaminedCount

func (l *CoverageLedger) ExaminedCount() int

ExaminedCount returns the number of examined entries.

func (*CoverageLedger) IsComplete

func (l *CoverageLedger) IsComplete() bool

IsComplete returns true if every tracked entry was examined with zero skipped.

func (*CoverageLedger) IsExamined

func (l *CoverageLedger) IsExamined(hunkID string) bool

IsExamined returns true if the hunk was examined.

func (*CoverageLedger) MarkExamined

func (l *CoverageLedger) MarkExamined(hunkID string)

MarkExamined flips the given hunk ID to examined status.

func (*CoverageLedger) MarkFileExamined

func (l *CoverageLedger) MarkFileExamined(file string)

MarkFileExamined flips all hunks of the given file to examined status (omissions remain skipped).

func (*CoverageLedger) MarkFileSkipped

func (l *CoverageLedger) MarkFileSkipped(file, reason string)

MarkFileSkipped sets all hunks of the file to skipped with reason.

func (*CoverageLedger) MarkSkipped

func (l *CoverageLedger) MarkSkipped(hunkID, reason string)

MarkSkipped sets status to skipped with the provided reason.

func (*CoverageLedger) Skipped

func (l *CoverageLedger) Skipped() []*LedgerEntry

Skipped returns all skipped ledger entries.

func (*CoverageLedger) SkippedCount

func (l *CoverageLedger) SkippedCount() int

SkippedCount returns the number of skipped entries.

func (*CoverageLedger) Summary

func (l *CoverageLedger) Summary() (examined, skipped int)

Summary returns examined and skipped counts.

func (*CoverageLedger) TotalHunks

func (l *CoverageLedger) TotalHunks() int

TotalHunks returns total entries tracked.

type DiffWindow

type DiffWindow struct {
	Index     int         `json:"index"`
	Hunks     []*Hunk     `json:"hunks"`
	Files     []string    `json:"files"`
	Content   string      `json:"content"`
	ByteCount int         `json:"byte_count"`
	Truncated bool        `json:"truncated"`
	Omissions []*Omission `json:"omissions,omitempty"`
}

DiffWindow represents a hunk-atomic window of changes within a byte budget. A window NEVER slices across or inside a hunk.

type FileDiff

type FileDiff struct {
	Path        string   `json:"path"`
	OldPath     string   `json:"old_path,omitempty"`
	IsNew       bool     `json:"is_new,omitempty"`
	IsDeleted   bool     `json:"is_deleted,omitempty"`
	IsRename    bool     `json:"is_rename,omitempty"`
	Similarity  int      `json:"similarity,omitempty"`
	IsBinary    bool     `json:"is_binary,omitempty"`
	IsModeOnly  bool     `json:"is_mode_only,omitempty"`
	OldMode     string   `json:"old_mode,omitempty"`
	NewMode     string   `json:"new_mode,omitempty"`
	HeaderLines []string `json:"header_lines,omitempty"`
	Hunks       []*Hunk  `json:"hunks"`
}

FileDiff represents changes to a single file.

type Hunk

type Hunk struct {
	ID         string       `json:"id"`
	File       string       `json:"file"`
	Header     string       `json:"header"`
	OldStart   int          `json:"old_start"`
	OldCount   int          `json:"old_count"`
	NewStart   int          `json:"new_start"`
	NewCount   int          `json:"new_count"`
	Body       string       `json:"body"`
	Lines      []string     `json:"lines"`
	AddedLines map[int]bool `json:"added_lines"` // line numbers on RIGHT side that were added (+)
}

Hunk represents a single unified diff hunk (@@ ... @@).

type LedgerEntry

type LedgerEntry struct {
	HunkID string `json:"hunk_id"`
	File   string `json:"file"`
	Status string `json:"status"` // "examined" or "skipped"
	Reason string `json:"reason,omitempty"`
}

LedgerEntry represents examination status of a single hunk or omission.

type Omission

type Omission struct {
	File   string `json:"file,omitempty"`
	HunkID string `json:"hunk_id,omitempty"`
	Reason string `json:"reason"`
}

Omission records changes or hunks that could not be parsed, exceeded caps, or were omitted from windows.

type ParseOptions

type ParseOptions struct {
	MaxBytes int64
	MaxFiles int
	MaxHunks int
}

ParseOptions configures limits for diff parsing.

func DefaultParseOptions

func DefaultParseOptions() ParseOptions

DefaultParseOptions returns the standard defaults.

func ParseOptionsFromConfig

func ParseOptionsFromConfig(cfg *config.Config) ParseOptions

ParseOptionsFromConfig builds ParseOptions from a loaded config.

Jump to

Keyboard shortcuts

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