Documentation
¶
Overview ¶
Package history walks the full commit history and blob store of a git repository using go-git, without invoking the git binary. It is the shared object-graph layer shared by secrets, git-spdx, and git-pkgs.
Index ¶
- func CommitSubject(message string) string
- func ShallowGit(repo string) (bool, error)
- func WalkChangesGit(repo string, merges bool, visit func(Change) error) error
- type Blob
- type BlobOptions
- type Change
- type ChangeOptions
- type Commit
- type CommitOptions
- type OpenOptions
- type Repo
- func (r *Repo) Close() error
- func (r *Repo) CommitHashes(opts CommitOptions) ([]plumbing.Hash, error)
- func (r *Repo) CommonDir() string
- func (r *Repo) GitDir() string
- func (r *Repo) Repository() *gogit.Repository
- func (r *Repo) Roots() ([]plumbing.Hash, error)
- func (r *Repo) Shallow() (bool, error)
- func (r *Repo) VisitCommitTrees(visit func(plumbing.Hash) error) error
- func (r *Repo) WalkBlobs(opts BlobOptions, visit func(Blob) error) (total int, resultErr error)
- func (r *Repo) WalkChanges(opts ChangeOptions, visit func(Change) error) error
- func (r *Repo) WalkCommits(opts CommitOptions, visit func(Commit) error) error
- func (r *Repo) WalkTreeEntries(hash plumbing.Hash, visit func(TreeEntry) error) (resultErr error)
- type Spool
- type TreeEntry
- type Tuning
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommitSubject ¶
CommitSubject returns the first paragraph of a commit message as a single line, matching git log --format=%s.
func ShallowGit ¶
ShallowGit reports whether the repository is a shallow clone by shelling out to git rev-parse.
Types ¶
type BlobOptions ¶
type BlobOptions struct {
// Workers is the number of concurrent object readers.
Workers int
// Limit returns the maximum size to read for a blob; larger blobs are
// reported to Skip and not visited. Nil means no limit.
Limit func(oid string) int64
// Skip is called for blobs excluded by Limit. Nil is a no-op.
Skip func(oid string)
}
BlobOptions controls a blob walk.
type Change ¶
type Change struct {
Commit, Date, Subject string
OldOID, NewOID, Path string
OldMode, NewMode string
Merge bool
}
Change is one file-level modification in a single commit, matching a raw entry from git log --raw. OIDs and modes are hex/octal strings so callers can round-trip them through the git-binary backend unchanged.
type ChangeOptions ¶
type ChangeOptions struct {
// Merges includes merge commits in the output.
Merges bool
// Workers is the number of concurrent commit readers and diff workers.
Workers int
}
ChangeOptions controls a change walk.
type CommitOptions ¶
type CommitOptions struct {
// Hashes is an exact commit sequence. Ref and Since are ignored when set.
Hashes []plumbing.Hash
// Ref is the revision to walk. An empty value uses HEAD.
Ref string
// Since excludes this revision and its ancestors.
Since string
// Merges includes first-parent changes for merge commits.
Merges bool
// Workers is the number of concurrent commit readers and diff workers.
Workers int
// PathFilter retains changes whose path returns true.
PathFilter func(string) bool
}
CommitOptions controls an ordered commit walk.
type OpenOptions ¶
type OpenOptions struct {
Tuning Tuning
DetectDotGit bool
AlternatesFS billy.Filesystem
}
OpenOptions controls repository discovery and storage.
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
Repo wraps an open go-git repository configured for history walking.
func OpenWithOptions ¶
func OpenWithOptions(path string, opts OpenOptions) (*Repo, error)
OpenWithOptions opens the repository at path with repository discovery and alternate-object storage options.
func (*Repo) CommitHashes ¶
func (r *Repo) CommitHashes(opts CommitOptions) ([]plumbing.Hash, error)
CommitHashes returns commits oldest-first without reading their trees.
func (*Repo) Repository ¶
func (r *Repo) Repository() *gogit.Repository
Repository returns the underlying go-git handle for callers that need direct storer access.
func (*Repo) VisitCommitTrees ¶
VisitCommitTrees walks every commit reachable from the repository's refs and invokes visit with each commit's root tree hash. Commits beyond a shallow boundary are treated as having no parents.
func (*Repo) WalkBlobs ¶
WalkBlobs decodes every blob object in the repository exactly once and invokes visit from opts.Workers goroutines concurrently. visit must be safe for concurrent use. The returned int is the total blob count including those excluded by opts.Limit.
func (*Repo) WalkChanges ¶
func (r *Repo) WalkChanges(opts ChangeOptions, visit func(Change) error) error
WalkChanges visits every file-level change in date order across all refs. visit is called from a single goroutine in commit order regardless of opts.Workers.
func (*Repo) WalkCommits ¶
func (r *Repo) WalkCommits(opts CommitOptions, visit func(Commit) error) error
WalkCommits visits commits oldest-first. The callback runs serially in the requested order, including for commits with no retained changes.
type Spool ¶
type Spool struct {
// contains filtered or unexported fields
}
Spool buffers a Change stream to a temporary file so it can be replayed after a separate blob-scanning pass has built its index.
func NewSpool ¶
NewSpool creates a temporary spool file. Prefix is used in the temp file name for debugging.
type TreeEntry ¶
TreeEntry is one immediate child of a Git tree. Name is valid only until the visitor returns and must be copied if retained.
type Tuning ¶
type Tuning struct {
MemoryIndex bool
Mmap bool
CacheBytes uint64
CacheShards int
KlauspostZlib bool
}
Tuning controls go-git storage behaviour. The zero value matches go-git defaults.
func DefaultTuning ¶
func DefaultTuning() Tuning
DefaultTuning returns the settings git-spdx converged on after benchmarking.