git

package
v0.0.0-...-56a2066 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

Package git manages a cache of git commit info that's stored in the database.

Index

Constants

This section is empty.

Variables

View Source
var (
	// BadCommit is returned on errors from functions that return Commits.
	BadCommit = provider.Commit{
		CommitNumber: types.BadCommitNumber,
	}
)

Functions

This section is empty.

Types

type Git

type Git interface {
	// StartBackgroundPolling starts a background process that periodically adds
	// new commits to the database.
	StartBackgroundPolling(ctx context.Context, duration time.Duration)

	// Update finds all the new commits added to the repo since our last Update.
	Update(ctx context.Context) error

	// GetCommitNumber looks up the commit number from Commits table given a git hash or commit number
	GetCommitNumber(ctx context.Context, githash string, commitNumber types.CommitNumber) (types.CommitNumber, error)

	// CommitNumberFromGitHash looks up the commit number given the git hash.
	CommitNumberFromGitHash(ctx context.Context, githash string) (types.CommitNumber, error)

	// CommitFromCommitNumber returns all the stored details for a given CommitNumber.
	CommitFromCommitNumber(ctx context.Context, commitNumber types.CommitNumber) (provider.Commit, error)

	// CommitSliceFromCommitNumberSlice returns all the stored details for a given slice of CommitNumbers.
	CommitSliceFromCommitNumberSlice(ctx context.Context, commitNumberSlice []types.CommitNumber) ([]provider.Commit, error)

	// CommitNumberFromTime finds the index of the closest commit with a commit time
	// less than or equal to 't'.
	//
	// Pass in zero time, i.e. time.Time{} to indicate to just get the most recent
	// commit.
	CommitNumberFromTime(ctx context.Context, t time.Time) (types.CommitNumber, error)

	// CommitSliceFromTimeRange returns a slice of Commits that fall in the range
	// [begin, end), i.e  inclusive of begin and exclusive of end.
	CommitSliceFromTimeRange(ctx context.Context, begin, end time.Time) ([]provider.Commit, error)

	// CommitSliceFromCommitNumberRange returns a slice of Commits that fall in the range
	// [begin, end], i.e  inclusive of both begin and end.
	CommitSliceFromCommitNumberRange(ctx context.Context, begin, end types.CommitNumber) ([]provider.Commit, error)

	// GitHashFromCommitNumber returns the git hash of the given commit number.
	GitHashFromCommitNumber(ctx context.Context, commitNumber types.CommitNumber) (string, error)

	// PreviousGitHashFromCommitNumber returns the previous git hash of the given commit number.
	PreviousGitHashFromCommitNumber(ctx context.Context, commitNumber types.CommitNumber) (string, error)

	// PreviousCommitNumberFromCommitNumber returns the previous commit number of the given commit number.
	PreviousCommitNumberFromCommitNumber(ctx context.Context, commitNumber types.CommitNumber) (types.CommitNumber, error)

	// CommitNumbersWhenFileChangesInCommitNumberRange returns a slice of commit
	// numbers when the given file has changed between [begin, end], i.e. the given
	// range is exclusive of the begin commit and inclusive of the end commit.
	CommitNumbersWhenFileChangesInCommitNumberRange(ctx context.Context, begin, end types.CommitNumber, filename string) ([]types.CommitNumber, error)

	// LogEntry returns the full log entry of a commit (minus the diff) as a string.
	LogEntry(ctx context.Context, commit types.CommitNumber) (string, error)

	// RepoSuppliedCommitNumber returns true if the CommitNumber is actually
	// specified by information in the git commit messages.
	RepoSuppliedCommitNumber() bool
}

Git is the interface for the minimal functionality Perf needs to interface to a git repo.

type Impl

type Impl struct {
	// contains filtered or unexported fields
}

Impl implements Git, the minimal functionality Perf needs to interface to a git repo.

It stores a copy of the needed commit info in an SQL database for quicker access, and runs a background Go routine that updates the database periodically.

Please see perf/sql/migrations for the database schema used.

func New

func New(ctx context.Context, local bool, db pool.Pool, instanceConfig *config.InstanceConfig) (*Impl, error)

New creates a new *Git from the given instance configuration.

The instance created does not poll by default, callers need to call StartBackgroundPolling().

func (*Impl) CommitFromCommitNumber

func (g *Impl) CommitFromCommitNumber(ctx context.Context, commitNumber types.CommitNumber) (provider.Commit, error)

CommitFromCommitNumber implements Git.

func (*Impl) CommitNumberFromGitHash

func (g *Impl) CommitNumberFromGitHash(ctx context.Context, githash string) (types.CommitNumber, error)

CommitNumberFromGitHash implements Git.

func (*Impl) CommitNumberFromTime

func (g *Impl) CommitNumberFromTime(ctx context.Context, t time.Time) (types.CommitNumber, error)

CommitNumberFromTime implements Git.

func (*Impl) CommitNumbersWhenFileChangesInCommitNumberRange

func (g *Impl) CommitNumbersWhenFileChangesInCommitNumberRange(ctx context.Context, begin, end types.CommitNumber, filename string) ([]types.CommitNumber, error)

CommitNumbersWhenFileChangesInCommitNumberRange implements Git.

func (*Impl) CommitSliceFromCommitNumberRange

func (g *Impl) CommitSliceFromCommitNumberRange(ctx context.Context, begin, end types.CommitNumber) ([]provider.Commit, error)

CommitSliceFromCommitNumberRange implements Git.

func (*Impl) CommitSliceFromCommitNumberSlice

func (g *Impl) CommitSliceFromCommitNumberSlice(ctx context.Context, commitNumberSlice []types.CommitNumber) ([]provider.Commit, error)

CommitSliceFromCommitNumberSlice implements Git.

func (*Impl) CommitSliceFromTimeRange

func (g *Impl) CommitSliceFromTimeRange(ctx context.Context, begin, end time.Time) ([]provider.Commit, error)

CommitSliceFromTimeRange implements Git.

func (*Impl) GetCommitNumber

func (g *Impl) GetCommitNumber(ctx context.Context, githash string, commitNumber types.CommitNumber) (types.CommitNumber, error)

GetCommitNumber implements Git.

func (*Impl) GitHashFromCommitNumber

func (g *Impl) GitHashFromCommitNumber(ctx context.Context, commitNumber types.CommitNumber) (string, error)

GitHashFromCommitNumber implements Git.

func (*Impl) LogEntry

func (g *Impl) LogEntry(ctx context.Context, commit types.CommitNumber) (string, error)

LogEntry implements Git.

func (*Impl) PreviousCommitNumberFromCommitNumber

func (g *Impl) PreviousCommitNumberFromCommitNumber(ctx context.Context, commitNumber types.CommitNumber) (types.CommitNumber, error)

PreviousCommitNumberFromCommitNumber implements Git.

func (*Impl) PreviousGitHashFromCommitNumber

func (g *Impl) PreviousGitHashFromCommitNumber(ctx context.Context, commitNumber types.CommitNumber) (string, error)

PreviousGitHashFromCommitNumber implements Git.

func (*Impl) RepoSuppliedCommitNumber

func (g *Impl) RepoSuppliedCommitNumber() bool

RepoSuppliedCommitNumber implements Git.

func (*Impl) StartBackgroundPolling

func (g *Impl) StartBackgroundPolling(ctx context.Context, duration time.Duration)

StartBackgroundPolling implements Git.

func (*Impl) Update

func (g *Impl) Update(ctx context.Context) error

Update implements Git.

Directories

Path Synopsis
Package gittest has utilities for testing perf/go/git.
Package gittest has utilities for testing perf/go/git.
Package provider contains types and interfaces for interacting with Git repos.
Package provider contains types and interfaces for interacting with Git repos.
Package providers builds different kinds of provider.Provider.
Package providers builds different kinds of provider.Provider.
git_checkout
Package git_checkout implements provider.Provider by shelling out to run git commands.
Package git_checkout implements provider.Provider by shelling out to run git commands.
gitiles
Package gitiles imlements provider.Provider using the Gitiles API.
Package gitiles imlements provider.Provider using the Gitiles API.

Jump to

Keyboard shortcuts

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