Documentation
¶
Overview ¶
Package sources turns files, git history and diffs into fragments.
Index ¶
- Constants
- func Git(ctx context.Context, o GitOptions, emit func(detect.Fragment)) error
- func ParseDiff(r io.Reader, maxBytes int64, emit func(detect.Fragment)) error
- func ParseDiffLimit(r io.Reader, maxBytes int64, emit func(detect.Fragment), tooLarge func(string)) error
- func Reader(r io.Reader, label string, asDiff bool, maxBytes int64, ...) error
- type FileOptions
- type GitOptions
- type Stats
Constants ¶
const CommitMarker = "\x00"
CommitMarker prefixes commit header lines produced by GitLogFormat.
const GitLogFormat = "--format=%x00%H%x1f%an%x1f%ae%x1f%aI%x1f%s"
GitLogFormat is the --format used for history scans.
Variables ¶
This section is empty.
Functions ¶
func ParseDiff ¶
ParseDiff reads unified diff output (optionally interleaved with commit headers) and emits one fragment per contiguous block of added lines, with accurate new-file line numbers. Removed and context lines are not scanned. Hunk line counts are honored, so added lines that look like headers ("+++ ...") are handled correctly.
func ParseDiffLimit ¶
func ParseDiffLimit(r io.Reader, maxBytes int64, emit func(detect.Fragment), tooLarge func(string)) error
ParseDiffLimit is ParseDiff that also reports each file whose added content exceeded maxBytes and was therefore not (fully) scanned.
func Reader ¶
func Reader(r io.Reader, label string, asDiff bool, maxBytes int64, emit func(detect.Fragment), tooLarge func(string)) error
Reader emits a single fragment for an io.Reader (stdin), or parses it as a unified diff when asDiff is set. Input beyond maxBytes is not scanned; tooLarge (if set) is told the label (or each diff file) when that happens.
Types ¶
type FileOptions ¶
type FileOptions struct {
MaxBytes int64
FollowSymlinks bool
Skip func(relPath string) bool // allowlisted paths
// TooLarge is told about every file skipped for exceeding MaxBytes, so
// the caller can say so: a skipped file is not a clean file.
TooLarge func(relPath string)
}
FileOptions control filesystem scans.
type GitOptions ¶
type GitOptions struct {
Repo string
LogOpts []string // extra `git log` args, e.g. "--since=2024-01-01" or "main~10..main"
Staged bool // scan only the staged diff (pre-commit)
PrePush bool // read pre-push refs from Stdin and scan only outgoing commits
Remote string // remote name passed to the pre-push hook ($1)
Stdin io.Reader // pre-push ref lines
MaxBytes int64 // skip files whose added content in a diff exceeds this
TooLarge func(string) // told about each file skipped for MaxBytes
}
GitOptions selects what part of a repository to scan.