Documentation
¶
Overview ¶
Package git reads the lines a change touched and the commits that changed each file, by running the git command line tool. It is the only package that runs git.
Diffs are parsed by github.com/bluekeyes/go-gitdiff (MIT), not revgrep, which answers only point queries and has known parsing faults, nor golangci-lint's diff processor, which is GPL-licensed (mmi-ref-plan.md §3).
Index ¶
- func ChangedLines(ctx context.Context, dir, rev string) (arch.ChangedLines, error)
- func Churn(ctx context.Context, dir, rev string) (arch.Churn, error)
- func Fixes(ctx context.Context, dir string, a After) (arch.FixHistory, error)
- func ParseDiff(r io.Reader) (arch.ChangedLines, error)
- func ParseFixes(r io.Reader, n int) (arch.FixHistory, error)
- func ParseLog(r io.Reader) (map[string][]string, map[string]string, error)
- func Show(ctx context.Context, dir string, file FileAt) ([]byte, error)
- func Window(ctx context.Context, dir string, n int) (string, error)
- func Worktree(ctx context.Context, dir, rev string) (string, func() error, error)
- type After
- type FileAt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChangedLines ¶
ChangedLines returns the lines added or modified since rev in the work tree of dir, relative to dir, plus every line of each untracked file, which a diff does not show. Deleted lines touch nothing: no code remains there.
func Churn ¶
Churn returns the commits since rev, up to HEAD, that changed each file of dir's work tree, with paths relative to dir; an empty rev means every commit HEAD reaches. Rename detection is off, so a renamed file's history starts at the rename and the result does not depend on git's similarity guesses. Since and Head are the full hashes the range resolved to, Since "" for the whole history.
func Fixes ¶
Fixes returns what a validation reads of the commits a names: how many there were, and the files each one whose subject reads as a fix changed, with paths relative to dir. Rename detection is off, as for Churn. Since is the revision's full hash, and Until the last commit read, the revision's own when none follows it.
Requires: a.Commits > 0.
func ParseDiff ¶
func ParseDiff(r io.Reader) (arch.ChangedLines, error)
ParseDiff parses a unified diff, as git diff writes it, into the ranges of added or modified lines of each new file, using github.com/bluekeyes/go-gitdiff. A deleted file contributes nothing, and "\ No newline at end of file" is not a line. A malformed diff is EINVALID.
func ParseFixes ¶
ParseFixes parses git log --reverse --format=%x00%H%x00%s --name-only, the oldest commit first: each commit is a NUL, its hash, a NUL and its subject, and the names of the files it changed. It reads the first n commits, and returns how many it read, the last of them, and the files of each fix among them, each file's fixes sorted.
func ParseLog ¶
ParseLog parses git log --format=%x00%H%x00%ae --name-only: each commit is a NUL, its hash, a NUL and its author's email, and the names of the files it changed. It returns each file's commits, sorted, and each commit's author.
func Show ¶
Show returns the contents of a file at a revision, in the repository that holds dir. An unknown revision, such as one a shallow clone lacks, is EINVALID; a revision without the file is ENOTFOUND.
func Window ¶
Window returns the revision that bounds the last n commits of HEAD's first-parent line, HEAD~n, as Churn's rev: the window moves with HEAD, so two runs at one commit agree, and a commit never worsens the measures only by being one more. A history of n commits or fewer gives "", the whole of it. A shallow clone hides how long the history is, so there an unreachable HEAD~n is ENOTFOUND rather than a silently shorter window.
Requires: n > 0.