gitinfo

package
v0.0.0-...-03d6fc4 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2019 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

gitinfo enables querying info from a Git repository.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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, dir string) ([]*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) 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) GetBranches

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

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

func (*GitInfo) GetFile

func (g *GitInfo) GetFile(ctx context.Context, fileName, commit string) (string, error)

GetFile returns the contents of the given file at the given commit.

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)

InitalCommit returns the hash of the initial commit.

func (*GitInfo) IsAncestor

func (g *GitInfo) IsAncestor(ctx context.Context, a, b string) bool

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) LastSkpCommit

func (g *GitInfo) LastSkpCommit(ctx context.Context) (time.Time, error)

LastSkpCommit returns the time of the last change to the SKP_VERSION file.

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) NumCommits

func (g *GitInfo) NumCommits() int

NumCommits returns the number of commits in the repo.

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) ResolveCommit

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

ResolveCommit see vcsinfo.VCS interface.

func (*GitInfo) RevList

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

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

func (*GitInfo) SetSecondaryRepo

func (g *GitInfo) SetSecondaryRepo(secVCS vcsinfo.VCS, extractor depot_tools.DEPSExtractor)

SetSecondaryRepo allows to add a secondary repository and extractor to this instance. It is not included in the constructor since it is currently only used by the Gold ingesters.

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) SkpCommits

func (g *GitInfo) SkpCommits(ctx context.Context, tile *tiling.Tile) ([]int, error)

SkpCommits returns the indices for all the commits that contain SKP updates.

func (*GitInfo) TileAddressFromHash

func (g *GitInfo) TileAddressFromHash(hash string, start time.Time) (num, offset int, err error)

TileAddressFromHash takes a commit hash and time, then returns the Level 0 tile number that contains the hash, and its position in the tile commit array. This assumes that tiles are built for commits since after the given time.

func (*GitInfo) Timestamp

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

Timestamp returns the timestamp for the given hash.

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 RepoMap

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

RepoMap is a struct used for managing multiple Git repositories.

func NewRepoMap

func NewRepoMap(workdir string) *RepoMap

NewRepoMap creates and returns a RepoMap which operates within the given workdir.

func (*RepoMap) Repo

func (m *RepoMap) Repo(ctx context.Context, r string) (*GitInfo, error)

Repo retrieves a pointer to a GitInfo for the requested repo URL. If the repo does not yet exist in the repoMap, it is cloned and added before it is returned.

func (*RepoMap) RepoForCommit

func (m *RepoMap) RepoForCommit(ctx context.Context, hash string) (string, error)

RepoForCommit attempts to determine which repository the given commit hash belongs to and returns the associated repo URL if found. This is fragile, because it's possible, though very unlikely, that there may be collisions of commit hashes between repositories.

func (*RepoMap) Repos

func (m *RepoMap) Repos() []string

Repos returns the list of repos contained in the RepoMap.

func (*RepoMap) Update

func (m *RepoMap) Update(ctx context.Context) error

Update causes all of the repos in the RepoMap to be updated.

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