git

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 16 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChangedLines

func ChangedLines(ctx context.Context, dir, rev string) (arch.ChangedLines, error)

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

func Churn(ctx context.Context, dir, rev string) (arch.Churn, error)

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

func Fixes(ctx context.Context, dir string, a After) (arch.FixHistory, error)

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

func ParseFixes(r io.Reader, n int) (arch.FixHistory, error)

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

func ParseLog(r io.Reader) (map[string][]string, map[string]string, error)

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

func Show(ctx context.Context, dir string, file FileAt) ([]byte, error)

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

func Window(ctx context.Context, dir string, n int) (string, error)

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.

func Worktree

func Worktree(ctx context.Context, dir, rev string) (string, func() error, error)

Worktree checks rev out, detached, into a new temporary directory, and returns the directory that corresponds there to dir, with a function that removes the checkout. The work tree and index of dir are untouched.

Types

type After

type After struct {
	Rev     string
	Commits int
}

After is the first Commits commits of HEAD's first-parent line after Rev.

type FileAt

type FileAt struct {
	Rev  string
	Path string
}

FileAt names a file at a revision: Path is relative to the directory git runs in.

Jump to

Keyboard shortcuts

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