git

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlameFileAtParent

func BlameFileAtParent(ctx context.Context, repoPath, commitHash, filepath string) ([]string, error)

func DiffTreeFiles

func DiffTreeFiles(ctx context.Context, repoPath, commitHash string) ([]string, error)

func FindCommitAtDate

func FindCommitAtDate(ctx context.Context, repoPath string, before time.Time) (string, error)

FindCommitAtDate returns the latest commit hash on or before the given date.

func FindRevertedCommits added in v1.1.0

func FindRevertedCommits(ctx context.Context, repoPath string) (map[string]bool, error)

FindRevertedCommits detects commits that have been reverted and returns the set of commit hashes that should be excluded from metric calculations.

This handles:

  • Non-merge reverts: `git revert <hash>` → excludes original + revert commit
  • Merge reverts (PR reverts): excludes all commits in the merged branch
  • Revert-of-revert: if a revert is itself reverted, the original is reinstated

Both the reverted original commits and the revert commits themselves are excluded, so the net effect is as if the reverted changes never happened.

func HeadHash

func HeadHash(ctx context.Context, repoPath string) (string, error)

HeadHash returns the current HEAD commit hash for a repo.

func IsShallowRepo

func IsShallowRepo(ctx context.Context, repoPath string) bool

IsShallowRepo checks if the repository is a shallow clone

func ListAllFiles

func ListAllFiles(ctx context.Context, repoPath string) ([]string, error)

ListAllFiles returns all tracked files in the repo (for domain auto-detection)

func ListFiles

func ListFiles(ctx context.Context, repoPath string, patterns []string) ([]string, error)

func ListFilesAtCommit

func ListFilesAtCommit(ctx context.Context, repoPath, commitHash string, patterns []string) ([]string, error)

ListFilesAtCommit returns tracked files at a specific commit hash, filtered by patterns.

func RunLines

func RunLines(ctx context.Context, repoPath string, args ...string) ([]string, error)

func RunStream

func RunStream(ctx context.Context, repoPath string, args ...string) (io.ReadCloser, *exec.Cmd, error)

func SampleFiles

func SampleFiles(files []string, maxFiles int) []string

SampleFiles performs stratified sampling by module to ensure every module is represented. Each module (first 3 directory components) gets at least minPerModule files, with remaining budget allocated proportionally.

Types

type BlameLine

type BlameLine struct {
	Author        string
	CommitterTime time.Time
	Filename      string
}

func BlameFile

func BlameFile(ctx context.Context, repoPath, filepath string) ([]BlameLine, error)

func BlameFileAtCommit

func BlameFileAtCommit(ctx context.Context, repoPath, commitHash, filepath string) ([]BlameLine, error)

BlameFileAtCommit runs blame at a specific commit hash.

func BlameFileStream

func BlameFileStream(ctx context.Context, repoPath, filepath string) ([]BlameLine, error)

BlameFilesStream processes blame with a scanner for memory efficiency on large repos

func BlameFiles

func BlameFiles(ctx context.Context, repoPath string, files []string, maxFiles int, progressFn func(done, total int)) ([]BlameLine, error)

func ConcurrentBlameFiles

func ConcurrentBlameFiles(ctx context.Context, repoPath string, files []string, maxFiles, workers int, progressFn func(done, total int), verboseFn func(string)) ([]BlameLine, error)

ConcurrentBlameFiles runs blame on files concurrently with a worker pool

func ConcurrentBlameFilesAtCommit

func ConcurrentBlameFilesAtCommit(ctx context.Context, repoPath, commitHash string, files []string, maxFiles, workers int, progressFn func(done, total int), verboseFn func(string)) ([]BlameLine, error)

ConcurrentBlameFilesAtCommit runs blame at a specific commit on files concurrently.

type Commit

type Commit struct {
	Hash      string
	Author    string
	Date      time.Time
	Subject   string
	IsMerge   bool
	FileStats []FileStat
}

func ParseLog

func ParseLog(ctx context.Context, repoPath string) ([]Commit, error)

ParseLog returns non-merge commits with numstat file stats.

func ParseMergeCommits

func ParseMergeCommits(ctx context.Context, repoPath string) ([]Commit, error)

ParseMergeCommits returns merge-only commits (no file stats). Used to detect fix/revert subjects in merge commit messages.

type FileStat

type FileStat struct {
	Insertions int
	Deletions  int
	Filename   string
}

Jump to

Keyboard shortcuts

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