Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsGeneratedFile ¶
IsGeneratedFile reports whether the file contains a standard generated-code marker near the top of the file, such as "Code generated ... DO NOT EDIT". Read errors return false so file selection stays conservative.
func ShowAtRef ¶
ShowAtRef returns the bytes of repoRelPath at the given git ref, or (nil, nil) if the path didn't exist there. Other failures (bad ref, not a git repo) bubble up as errors. Used by delta-gating analyzers to compare a changed file's metric against its pre-change baseline.
`git show ref:path` exits 128 for several distinct conditions: path absent in the tree, ref unknown, not a git repo. Only the first should turn into the "no baseline" signal — the others must surface as errors so a broken CI config doesn't silently weaken the gate. We disambiguate on stderr.
Types ¶
type ChangedRegion ¶
ChangedRegion represents a contiguous range of changed lines in a file.
type FileChange ¶
type FileChange struct {
Path string
Regions []ChangedRegion
}
FileChange represents changes to a single file in the diff.
func (FileChange) ContainsLine ¶
func (fc FileChange) ContainsLine(line int) bool
ContainsLine returns true if the given line number falls within a changed region.
func (FileChange) IsNew ¶
func (fc FileChange) IsNew() bool
IsNew returns true if the entire file is new (single region from line 1).
func (FileChange) OverlapsRange ¶
func (fc FileChange) OverlapsRange(start, end int) bool
OverlapsRange returns true if any changed region overlaps [start, end].
type Filter ¶
type Filter struct {
// DiffGlobs is passed to `git diff -- <globs>` to restrict the raw diff
// to language source files.
DiffGlobs []string
// Includes reports whether an analyzable source path (extension matches,
// not a test file) belongs to the caller's language.
Includes func(path string) bool
}
Filter describes the subset of the diff the caller cares about. It is a narrower shape than lang.FileFilter so the diff package doesn't have to import lang (which would pull the full analyzer stack). Callers (usually cmd/diffguard) construct a Filter from their chosen language's lang.FileFilter and pass it here.
type Result ¶
type Result struct {
BaseBranch string
// MergeBase is the resolved commit SHA of merge-base(BaseBranch, HEAD).
// Populated by Parse; empty in refactoring mode (CollectPaths). Used by
// delta-gating analyzers to fetch pre-change file content via `git show`.
MergeBase string
Files []FileChange
}
Result holds all changed source files parsed from a git diff.
func CollectPaths ¶
CollectPaths builds a Result by treating each analyzable source file under the given paths as fully changed. Useful for refactoring mode where you want to analyze entire files rather than diffed regions only.
paths may contain individual files or directories (walked recursively). Files that fail filter.Includes are excluded — test files and non-source files never show up in the result.
func Parse ¶
Parse runs `git diff` against the merge-base of baseBranch..HEAD and returns the changed files that pass the filter. The filter is also used to restrict the raw `git diff` output via -- globs so the parser never has to see files from other languages.
func (Result) ChangedPackages ¶
ChangedPackages returns the unique set of package directories with changes.
func (Result) FilesByPackage ¶
func (r Result) FilesByPackage() map[string][]FileChange
FilesByPackage groups changed files by their package directory.