On this page
Package scan iterates all git objects (reachable and unreachable) and matches patterns against their textual content for history scrubbing.
#internal/scan
#internal/scan
Package scan iterates all git objects (reachable and unreachable) and matches patterns against their textual content for history scrubbing. Blobs, commit messages, and tag annotations are searched. Binary blobs (NUL in first 8KB) are skipped.
#Match
type Match structMatch records a single pattern hit inside a git object.
#ScanResults
type ScanResults structScanResults holds the aggregate output of a scan across all git objects.
#ScanOpts
type ScanOpts structScanOpts configures which objects to scan and where to find them.
#AddAttribution
func AddAttribution(ctx context.Context, results *ScanResults, opts ScanOpts) errorAddAttribution enriches blob matches with commit and path information. For each match where ObjectType "blob" and Path "", it finds which commit(s) contain the blob and what file path it has. Uses git rev-list --all --objects to build a blob-to-path index. Unreachable blobs (not in rev-list output) keep empty Path/CommitSHA. When opts.GitDir is set, commands target that git directory.
#ScanNonObjects
func ScanNonObjects(ctx context.Context, pattern *regexp.Regexp, gitDir string) ([]Match, error)ScanNonObjects scans non-git-object files for the given pattern. It checks: - git ls-files)
Binary files are skipped (NUL in first 8KB). Non-existent files are skipped.
#ScanObjectsMulti
func ScanObjectsMulti(ctx context.Context, patterns []*regexp.Regexp, opts ScanOpts) ([]*ScanResults, error)ScanObjectsMulti iterates every object in the git object store once and searches for matches against multiple patterns simultaneously. Returns one ScanResults per pattern (same order as input). The reachable set and object iteration happen only once regardless of how many patterns are provided. Uses the same opts as ScanObjects; only EntireHistory mode is supported.
#ScanObjects
func ScanObjects(ctx context.Context, pattern *regexp.Regexp, opts ScanOpts) (*ScanResults, error)ScanObjects iterates git objects and searches for pattern matches. The opts parameter controls which objects are scanned: - EntireHistory=true: uses cat-file --batch-all-objects (all objects including unreachable loose objects). Builds a reachable set to mark each match. - FromSHA set (EntireHistory=false): uses rev-list --objects FromSHA..HEAD (reachable only). All matches are marked reachable by construction. - Both empty/false: returns an error.
When GitDir is set, commands target that git directory instead of CWD. SubmodulePath is set on every returned Match.