Help us shape the future of Go! Take the 2026 Go Developer Survey

sources

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package sources turns files, git history and diffs into fragments.

Index

Constants

View Source
const CommitMarker = "\x00"

CommitMarker prefixes commit header lines produced by GitLogFormat.

View Source
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 Git

func Git(ctx context.Context, o GitOptions, emit func(detect.Fragment)) error

Git streams fragments from a repository.

func ParseDiff

func ParseDiff(r io.Reader, maxBytes int64, emit func(detect.Fragment)) error

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.

type Stats

type Stats struct {
	Files, Skipped int
	Bytes          int64
}

Stats counts what a source looked at.

func Files

func Files(ctx context.Context, roots []string, o FileOptions, emit func(detect.Fragment)) (Stats, error)

Files walks each root (file or directory) and emits one fragment per text file.

Jump to

Keyboard shortcuts

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