git

package
v0.3.0-20260820034428-... Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

README

Git change provider

Reads change metadata — files, line counts, author — out of a git repository, for a remote that offers no API to ask.

The GitHub and Phabricator providers query a service that already knows what a change contains. This one derives it. It keeps its own copy of the remote and computes each change from the commits themselves, which makes a plain git remote a first-class source of change metadata with nothing in front of it: an internal host, a mirror, or a bare repository on disk.

What a change is measured against

A git:// change URI names a commit and the ref it lives on, and nothing else. A pull request carries a base; this does not, so the baseline has to be derived — and for a stack it cannot be the target branch.

A stack's changes are cut one from the next. Measuring every change against the target would report the second as containing the first, and any consumer that sums line counts across a batch would count them twice. So the first change in a request is measured from where it diverged from the target, and each one after it from where it diverged from the change before it. The order of the URIs is the stack order, and it is load-bearing.

A change that shares no history with what it claims to land on is an error, not a change that touches nothing.

What this package is, and isn't

This package is only the derivation: parse the URI, pick the baseline, read the diff and author, shape the result. Everything about reaching the repository — the local bare copy, fetching, merge bases, authentication, the git command environment — is transport plumbing that lives in platform/git/repo (built on platform/git/exec), which the merger and any other git caller share. The provider depends on a small Repository interface it defines, so it holds no os/exec and no credential handling of its own.

Tests

Hermetic, against throwaway repositories, driving the Bazel-pinned git rather than the host's. The test that matters most is the three-step stack: reporting a stack cumulatively is wrong by default, never fails loudly, and shows up only as odd-looking scores.

Documentation

Overview

Package git provides a changeprovider.ChangeProvider that reads change metadata out of a git repository, for a remote that offers no API to ask.

Where the GitHub and Phabricator providers query a service that already knows what a change contains, this one derives it: it keeps its own copy of the remote and computes each change's files, line counts and author from the commits themselves. That makes a plain git remote — an internal host, a mirror, a bare repository on disk — a first-class source of change metadata with no service in front of it.

What a change is measured against

A git:// change URI names a commit and the ref it lives on, and nothing else. Unlike a pull request it carries no base, so the baseline has to be derived, and for a stack it cannot be the target branch: a stack's changes are cut one from the next, so measuring each against the target would report the second change as containing the first as well. Each change is therefore measured from where it diverged from the change before it, and only the first from the target. Callers get per-change numbers that sum, which is what any consumer aggregating over a batch depends on.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

New returns a changeprovider.ChangeProvider reading from repo.

Types

type Params

type Params struct {
	Config       changeprovider.Config
	Repo         Repository
	Logger       *zap.SugaredLogger
	MetricsScope tally.Scope
}

Params carries what a provider needs. The Repository is built once per repository and shared by every queue reading it.

type Repository

type Repository interface {
	sync.Locker
	FetchTarget(ctx context.Context) error
	EnsureCommit(ctx context.Context, sha, ref string) error
	MergeBase(ctx context.Context, a, b string) (string, error)
	// RunRaw returns git's stdout untrimmed, since the diff and author formats
	// this provider reads are NUL-delimited with a meaningful trailing byte.
	RunRaw(ctx context.Context, args ...string) (string, error)
	Remote() string
	Target() string
}

Repository is the local copy this provider reads through. It is the git plumbing the provider needs and nothing more: fetching, commit resolution, merge bases, and a lock the provider holds across a read so a shared copy's object set stays consistent. platform/git/repo.Repo satisfies it.

Jump to

Keyboard shortcuts

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