repograph

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: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Name of the file we store inside the Git checkout to speed up the
	// initial Update().
	CACHE_FILE = "sk_gitrepo.gob"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Commit

type Commit struct {
	*vcsinfo.LongCommit
	ParentIndices []int
	// contains filtered or unexported fields
}

Commit represents a commit in a Git repo.

func (*Commit) GetParents

func (c *Commit) GetParents() []*Commit

Parents returns the parents of this commit.

func (*Commit) HasAncestor

func (c *Commit) HasAncestor(other string) bool

HasAncestor returns true iff the given commit is an ancestor of this commit.

func (*Commit) Recurse

func (c *Commit) Recurse(f func(*Commit) (bool, error)) error

Recurse runs the given function recursively over commit history, starting at the given commit. The function accepts the current Commit as a parameter. Returning false from the function indicates that recursion should stop for the current branch, however, recursion will continue for any other branches until they are similarly terminated. Returning an error causes recursion to stop without properly terminating other branchces. The error will bubble to the top and be returned. Here's an example of printing out the entire ancestry of a given commit:

commit.Recurse(func(c *Commit) (bool, error) {
	sklog.Info(c.Hash)
	return true, nil
})

type CommitSlice

type CommitSlice []*Commit

Helpers for sorting.

func (CommitSlice) Hashes

func (s CommitSlice) Hashes() []string

Hashes returns a slice of commit hashes corresponding to the commits in s.

func (CommitSlice) Len

func (s CommitSlice) Len() int

func (CommitSlice) Less

func (s CommitSlice) Less(a, b int) bool

func (CommitSlice) Swap

func (s CommitSlice) Swap(a, b int)

type Graph

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

Graph represents an entire Git repo.

func New

func New(repo *git.Repo) (*Graph, error)

New returns a Graph instance which uses the given git.Graph. Obtains cached data but does NOT update the Graph; the caller is responsible for doing so before using the Graph if up-to-date data is required.

func NewGraph

func NewGraph(ctx context.Context, repoUrl, workdir string) (*Graph, error)

NewGraph returns a Graph instance, creating a git.Repo from the repoUrl and workdir. Obtains cached data but does NOT update the Graph; the caller is responsible for doing so before using the Graph if up-to-date data is required.

func (*Graph) BranchHeads

func (r *Graph) BranchHeads() []*gitinfo.GitBranch

BranchHeads returns the set of branch heads from the repo.

func (*Graph) Branches

func (r *Graph) Branches() []string

Branches returns the list of known branches in the repo.

func (*Graph) Get

func (r *Graph) Get(ref string) *Commit

Get returns a Commit object for the given ref, if such a commit exists. This function does not understand complex ref types (eg. HEAD~3); only branch names and full commit hashes are accepted.

func (*Graph) GetCommitsNewerThan

func (r *Graph) GetCommitsNewerThan(ts time.Time) ([]*vcsinfo.LongCommit, error)

Return any commits at or after the given timestamp.

func (*Graph) GetLastNCommits

func (r *Graph) GetLastNCommits(n int) ([]*vcsinfo.LongCommit, error)

GetLastNCommits returns the last N commits in the repo.

func (*Graph) Len

func (r *Graph) Len() int

Len returns the number of commits in the repo.

func (*Graph) RecurseAllBranches

func (r *Graph) RecurseAllBranches(f func(*Commit) (bool, error)) error

RecurseAllBranches runs the given function recursively over the entire commit history, starting at each of the known branch heads. The function accepts the current Commit as a parameter. Returning false from the function indicates that recursion should stop for the current branch, however, recursion will continue for any other branches until they are similarly terminated. Returning an error causes recursion to stop without properly terminating other branchces. The error will bubble to the top and be returned. Here's an example of printing out all of the commits in the repo:

repo.RecurseAllBranches(func(c *Commit) (bool, error) {
     sklog.Info(c.Hash)
     return true, nil
})

func (*Graph) Repo

func (r *Graph) Repo() *git.Repo

Repo returns the underlying git.Repo object.

func (*Graph) Update

func (r *Graph) Update(ctx context.Context) error

Update syncs the local copy of the repo and loads new commits/branches into the Graph object.

func (*Graph) UpdateAndReturnNewCommits

func (r *Graph) UpdateAndReturnNewCommits(ctx context.Context) ([]*vcsinfo.LongCommit, error)

UpdateAndReturnNewCommits syncs the local copy of the repo and loads new commits/branches into the Graph object. Returns a slice of any new commits, in no particular order.

type Map

type Map map[string]*Graph

Map is a convenience type for dealing with multiple Graphs for different repos. The keys are repository URLs.

func NewMap

func NewMap(ctx context.Context, repos []string, workdir string) (Map, error)

NewMap returns a Map instance with Graphs for the given repo URLs. Obtains cached data but does NOT update the Map; the caller is responsible for doing so before using the Map if up-to-date data is required.

func (Map) FindCommit

func (m Map) FindCommit(commit string) (*Commit, string, *Graph, error)

FindCommit returns the Commit object, repo URL, and Graph object for the given commit hash if it exists in any of the Graphs in the Map and an error otherwise.

func (Map) RepoURLs

func (m Map) RepoURLs() []string

RepoURLs returns the list of repositories in the Map.

func (Map) Update

func (m Map) Update(ctx context.Context) error

Update updates all Graphs in the Map.

func (Map) UpdateAndReturnNewCommits

func (m Map) UpdateAndReturnNewCommits(ctx context.Context) (map[string][]*vcsinfo.LongCommit, error)

UpdateAndReturnNewCommits updates all Graphs in the Map. Returns a map of repo URLs to slices of new commits in each of the repos.

Jump to

Keyboard shortcuts

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