gitinfo

package
v0.0.0-...-b0b99f2 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: 16 Imported by: 1

Documentation

Overview

Package gitinfo enables querying info from Git repository using git and a local checkout.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBranchCommits

func GetBranchCommits(ctx context.Context, co git.Checkout, branch string) ([]*vcsinfo.IndexCommit, error)

GetBranchCommits gets all the commits in the given branch and directory in topological order and only with the first parent (omitting commits from branches that are merged in). The earliest commits are returned first. Note: Primarily used for testing and will probably be removed in the future.

Types

type GitBranch

type GitBranch struct {
	Name string `json:"name"`
	Head string `json:"head"`
}

GitBranch represents a Git branch.

func GetBranches

func GetBranches(ctx context.Context, co git.Checkout) ([]*GitBranch, error)

GetBranches returns the list of branch heads in a Git repository. In order to separate local working branches from published branches, only remote branches in 'origin' are returned.

type GitInfo

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

GitInfo allows querying a Git repo.

func Clone

func Clone(ctx context.Context, repoUrl, dir string, allBranches bool) (*GitInfo, error)

Clone creates a new GitInfo by running "git clone" in the given directory.

func CloneOrUpdate

func CloneOrUpdate(ctx context.Context, repoUrl, dir string, allBranches bool) (*GitInfo, error)

CloneOrUpdate creates a new GitInfo by running "git clone" or "git pull" depending on whether the repo already exists.

func NewGitInfo

func NewGitInfo(ctx context.Context, dir string, pull, allBranches bool) (*GitInfo, error)

NewGitInfo creates a new GitInfo for the Git repository found in directory dir. If pull is true then a git pull is done on the repo before querying it for history.

func (*GitInfo) ByIndex

func (g *GitInfo) ByIndex(ctx context.Context, N int) (*vcsinfo.LongCommit, error)

ByIndex returns a LongCommit describing the commit at position N, as ordered in the current branch.

Does not make sense if readCommitsFromGitAllBranches has been called.

func (*GitInfo) Checkout

func (g *GitInfo) Checkout(ctx context.Context, ref string) error

func (*GitInfo) Details

func (g *GitInfo) Details(ctx context.Context, hash string, includeBranchInfo bool) (*vcsinfo.LongCommit, error)

Details returns more information than ShortCommit about a given commit. See the vcsinfo.VCS interface for details.

func (*GitInfo) DetailsMulti

func (g *GitInfo) DetailsMulti(ctx context.Context, hashes []string, includeBranchInfo bool) ([]*vcsinfo.LongCommit, error)

See the vcsinfo.VCS interface for details.

func (*GitInfo) Dir

func (g *GitInfo) Dir() string

Dir returns the checkout dir of the GitInfo..

func (*GitInfo) From

func (g *GitInfo) From(start time.Time) []string

From returns all commits from 'start' to HEAD.

func (*GitInfo) FullHash

func (g *GitInfo) FullHash(ctx context.Context, ref string) (string, error)

FullHash gives the full commit hash for the given ref.

func (*GitInfo) GetBranch

func (g *GitInfo) GetBranch() string

GetBranch implements the vcsinfo.VCS interface.

func (*GitInfo) GetBranches

func (g *GitInfo) GetBranches(ctx context.Context) ([]*GitBranch, error)

GetBranches returns a slice of strings naming the branches in the repo.

func (*GitInfo) IndexOf

func (g *GitInfo) IndexOf(ctx context.Context, hash string) (int, error)

IndexOf returns the index of given hash as counted from the first commit in this branch by 'rev-list'. The index is 0 based.

func (*GitInfo) InitialCommit

func (g *GitInfo) InitialCommit(ctx context.Context) (string, error)

InitialCommit returns the hash of the initial commit.

func (*GitInfo) LastN

func (g *GitInfo) LastN(ctx context.Context, N int) []string

LastN returns the last N commits.

func (*GitInfo) LastNIndex

func (g *GitInfo) LastNIndex(N int) []*vcsinfo.IndexCommit

LastNIndex returns the last N commits.

func (*GitInfo) Log

func (g *GitInfo) Log(ctx context.Context, begin, end string) (string, error)

Log returns a --name-only short log for every commit in (begin, end].

If end is "" then it returns just the short log for the single commit at begin.

Example response:

commit b7988a21fdf23cc4ace6145a06ea824aa85db099
Author: Joe Gregorio <jcgregorio@google.com>
Date:   Tue Aug 5 16:19:48 2014 -0400

    A description of the commit.

perf/go/skiaperf/perf.go
perf/go/types/types.go
perf/res/js/logic.js

func (*GitInfo) LogArgs

func (g *GitInfo) LogArgs(ctx context.Context, args ...string) (string, error)

LogArgs is the same as Log() but appends all the 'args' to the Log request to allow finer control of the log output. I.e. you could call:

LogArgs("--since=2015-10-24", "--format=format:%ct", "infra/bots/assets/skp/VERSION")

func (*GitInfo) LogFine

func (g *GitInfo) LogFine(ctx context.Context, begin, end string, args ...string) (string, error)

func (*GitInfo) Range

func (g *GitInfo) Range(begin, end time.Time) []*vcsinfo.IndexCommit

Range returns all commits from the half open interval ['begin', 'end'), i.e. includes 'begin' and excludes 'end'.

func (*GitInfo) Reset

func (g *GitInfo) Reset(ctx context.Context, ref string) error

func (*GitInfo) RevList

func (g *GitInfo) RevList(ctx context.Context, args ...string) ([]string, error)

RevList returns the results of "git rev-list".

func (*GitInfo) ShortList

func (g *GitInfo) ShortList(ctx context.Context, begin, end string) (*ShortCommits, error)

ShortList returns a slice of ShortCommit for every commit in (begin, end].

func (*GitInfo) Timestamp

func (g *GitInfo) Timestamp(hash string) time.Time

Timestamp returns the timestamp for the given hash.

func (*GitInfo) TimestampAtIndex

func (g *GitInfo) TimestampAtIndex(N int) (time.Time, error)

This is a temporary performance enhancement for Perf. It will be removed once Perf moves to gitstore.

func (*GitInfo) Update

func (g *GitInfo) Update(ctx context.Context, pull, allBranches bool) error

Update refreshes the history that GitInfo stores for the repo. If pull is true then git pull is performed before refreshing.

type ShortCommits

type ShortCommits struct {
	Commits []*vcsinfo.ShortCommit
}

ShortCommits stores a slice of ShortCommit struct.

Jump to

Keyboard shortcuts

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