Documentation ¶
Index ¶
- Constants
- Variables
- type Commit
- func (c *Commit) AddParent(p *Commit)
- func (c *Commit) AllCommits() ([]string, error)
- func (c *Commit) GetParents() []*Commit
- func (c *Commit) HasAncestor(other string) bool
- func (c *Commit) Less(other *Commit) bool
- func (c *Commit) Recurse(f func(*Commit) error) error
- func (c *Commit) RecurseFirstParent(f func(*Commit) error) error
- type CommitSlice
- type Graph
- func (r *Graph) BranchHeads() []*git.Branch
- func (r *Graph) Branches() []string
- func (r *Graph) Get(ref string) *Commit
- func (r *Graph) GetAll() map[string]*Commit
- func (r *Graph) GetCommitsNewerThan(ts time.Time) ([]*vcsinfo.LongCommit, error)
- func (r *Graph) GetLastNCommits(n int) ([]*vcsinfo.LongCommit, error)
- func (r *Graph) IsAncestor(a, b string) (bool, error)
- func (r *Graph) Len() int
- func (r *Graph) LogLinear(from, to string) ([]*Commit, error)
- func (r *Graph) RecurseAllBranches(f func(*Commit) error) error
- func (r *Graph) RecurseCommits(commits []string, f func(*Commit) error) error
- func (r *Graph) RevList(from, to string) ([]string, error)
- func (r *Graph) Update(ctx context.Context) error
- func (r *Graph) UpdateAndReturnCommitDiffs(ctx context.Context) ([]*vcsinfo.LongCommit, []*vcsinfo.LongCommit, error)
- func (r *Graph) UpdateBranchInfo() []*vcsinfo.LongCommit
- func (r *Graph) UpdateWithCallback(ctx context.Context, cb func(*Graph) error) error
- func (r *Graph) WriteGob(w io.Writer) error
- type Map
- func (m Map) FindCommit(commit string) (*Commit, string, *Graph, error)
- func (m Map) RepoURLs() []string
- func (m Map) Update(ctx context.Context) error
- func (m Map) UpdateAndReturnCommitDiffs(ctx context.Context) (map[string][]*vcsinfo.LongCommit, map[string][]*vcsinfo.LongCommit, error)
- func (m Map) UpdateWithCallback(ctx context.Context, cb func(string, *Graph) error) error
- type MemCacheRepoImpl
- func (ri *MemCacheRepoImpl) Branches(_ context.Context) ([]*git.Branch, error)
- func (ri *MemCacheRepoImpl) Details(_ context.Context, hash string) (*vcsinfo.LongCommit, error)
- func (ri *MemCacheRepoImpl) Update(_ context.Context) error
- func (ri *MemCacheRepoImpl) UpdateCallback(_ context.Context, _, _ []*vcsinfo.LongCommit, _ *Graph) error
- type RepoImpl
Constants ¶
const ( // Name of the file we store inside the Git checkout to speed up the // initial Update(). CACHE_FILE = "sk_gitrepo.gob" )
Variables ¶
var (
ErrStopRecursing = errors.New("Stop recursing")
)
Functions ¶
This section is empty.
Types ¶
type Commit ¶
type Commit struct { *vcsinfo.LongCommit // contains filtered or unexported fields }
Commit represents a commit in a Git repo.
func TopologicalSort ¶
TopologicalSort returns a slice containing the given commits in reverse topological order, ie. every commit is listed before any of its parents.
func (*Commit) AllCommits ¶
AllCommits returns the hashes of all commits reachable from this Commit, in reverse topological order.
func (*Commit) GetParents ¶
GetParents returns the parents of this commit.
func (*Commit) HasAncestor ¶
HasAncestor returns true iff the given commit is an ancestor of this commit.
func (*Commit) Less ¶
Less compares this Commit to the other Commit and returns true if it is considered "less" than the other. This is used as a helper function in sorting to ensure stability. Uses the timestamp as the primary sort function and the hash as a tie breaker. Note that, because we sort in reverse chronological order, this has the opposite meaning that it seems it should.
func (*Commit) Recurse ¶
Recurse runs the given function recursively over commit history, starting at the given commit. The function accepts the current Commit as a parameter. Returning ErrStopRecursing 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 any other error causes recursion to stop without properly terminating other branches. 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) error { sklog.Info(c.Hash) return nil })
If the passed-in function returns no errors other than ErrStopRecursing, Recurse() will never return an error.
func (*Commit) RecurseFirstParent ¶
RecurseFirstParent is like Recurse, but it only follows the first parent of each commit. Like Recurse, if the passed-in function returns no errors other than ErrStopRecursing, RecurseFirstParent() will never return an error.
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 NewFromGob ¶
NewFromGob reads a Graph from the given Reader in gob format.
func NewLocalGraph ¶
NewLocalGraph returns a Graph instance, creating a git.Repo from the repoUrl and workdir. May obtain cached data from a file in the git repo, 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 NewWithRepoImpl ¶
NewWithRepoImpl returns a Graph instance which uses the given RepoImpl. The RepoImpl should be initialized (via Update() or otherwise) before being passed to NewWithRepoImpl.
func (*Graph) BranchHeads ¶
BranchHeads returns the set of branch heads from the repo.
func (*Graph) Get ¶
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) GetAll ¶
GetAll returns a map containing all of the stored Commit objects keyed by commit hash.
func (*Graph) GetCommitsNewerThan ¶
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) IsAncestor ¶
IsAncestor returns true iff A is an ancestor of B, where A and B are either commit hashes or branch names.
func (*Graph) LogLinear ¶
LogLinear is equivalent to "git log --first-parent --ancestry-path from..to", ie. it only returns commits which are on the direct path from A to B, and only on the "main" branch. This is as opposed to "git log from..to" which returns all commits which are ancestors of 'to' but not 'from'. The 'from' commit may be the empty string, in which case all commits in the first-parent line are returned.
func (*Graph) RecurseAllBranches ¶
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 ErrStopRecursing 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 any other error causes recursion to stop without properly terminating other branches. 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) error { sklog.Info(c.Hash) return nil })
func (*Graph) RecurseCommits ¶
RecurseCommits runs the given function recursively over the given refs, which can be either commit hashes or branch names. The function accepts the current Commit as a parameter. Returning ErrStopRecursing 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 any other error causes recursion to stop without properly terminating other branches. The error will bubble to the top and be returned. Here's an example of printing out all of the commits reachable from a given set of commits:
commits := []string{...}
err := repo.RecurseCommits(commits, func(c *Commit) error { sklog.Info(c.Hash) return nil })
func (*Graph) RevList ¶
RevList is the equivalent of "git rev-list --topo-order from..to". Each argument is a commit hash or a branch name. The commits are returned in reverse topological order. Per "git rev-list" docs, the returned commit hashes consist of all commits reachable from "to" and not reachable from "from". In the typical case of linear git history, this just means the commits on the line after "from" up through "to", but with branches and merges it's possible that there are entire sub-graphs which are reachable from "to" but not "from".
func (*Graph) UpdateAndReturnCommitDiffs ¶
func (r *Graph) UpdateAndReturnCommitDiffs(ctx context.Context) ([]*vcsinfo.LongCommit, []*vcsinfo.LongCommit, error)
UpdateAndReturnCommitDiffs updates the Graph and returns the added and removed commits, in arbitrary order.
func (*Graph) UpdateBranchInfo ¶
func (r *Graph) UpdateBranchInfo() []*vcsinfo.LongCommit
UpdateBranchInfo updates the membership of all commits in all branches. A commit is considered a member of a branch if and only if it is reachable by tracing the *first parent* lineage backward from the branch head. Notably, this will result in different branch membership than would be obtained by `git branch --all --list --contains <hash>` as is used elsewhere. Modifies the Commit objects stored in the graph and returns the LongCommits associated with the modified Commits. Clients MUST NOT modify the Branches on the returned LongCommits; as a space-saving optimization, we use the same map instance for all commits which belong to the same set of branches.
func (*Graph) UpdateWithCallback ¶
UpdateWithCallback updates the Graph and runs the given function before the changes are committed. If the function returns an error, the changes are not committed. The function is allowed to call non-Update methods of the Graph.
type Map ¶
Map is a convenience type for dealing with multiple Graphs for different repos. The keys are repository URLs.
func NewLocalMap ¶
NewLocalMap returns a Map instance with Graphs for the given repo URLs. May obtain cached data from a file in the git repo, 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 ¶
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) UpdateAndReturnCommitDiffs ¶
func (m Map) UpdateAndReturnCommitDiffs(ctx context.Context) (map[string][]*vcsinfo.LongCommit, map[string][]*vcsinfo.LongCommit, error)
UpdateAndReturnCommitDiffs updates all Graphs in the Map. Returns maps of repo URLs to slices of added commits, repo URLs to slices of removed commits, or any error which was encountered. If any Graph failed to update, no changes are committed.
func (Map) UpdateWithCallback ¶
UpdateWithCallback updates the Graphs in the Map and runs the given function on each Graph before the changes are committed. If the function returns an error for any Graph, no changes are committed. The function is allowed to call non-Update methods of the Graph.
type MemCacheRepoImpl ¶
type MemCacheRepoImpl struct { Commits map[string]*vcsinfo.LongCommit BranchList []*git.Branch }
MemCacheRepoImpl is a RepoImpl which just caches commits in memory.
func NewMemCacheRepoImpl ¶
func NewMemCacheRepoImpl(commits map[string]*vcsinfo.LongCommit, branches []*git.Branch) *MemCacheRepoImpl
NewMemCacheRepoImpl returns a RepoImpl implementation which just caches commits in memory. The commits map must contain all commits needed by the given branch heads.
func (*MemCacheRepoImpl) Details ¶
func (ri *MemCacheRepoImpl) Details(_ context.Context, hash string) (*vcsinfo.LongCommit, error)
See documentation for RepoImpl interface.
func (*MemCacheRepoImpl) Update ¶
func (ri *MemCacheRepoImpl) Update(_ context.Context) error
See documentation for RepoImpl interface.
func (*MemCacheRepoImpl) UpdateCallback ¶
func (ri *MemCacheRepoImpl) UpdateCallback(_ context.Context, _, _ []*vcsinfo.LongCommit, _ *Graph) error
See documentation for RepoImpl interface.
type RepoImpl ¶
type RepoImpl interface { // Update the local view of the repo. Update(context.Context) error // Return the details for the given commit. The Graph takes ownership // of the returned LongCommit and may modify it. Details(context.Context, string) (*vcsinfo.LongCommit, error) // Return the branch heads, as of the last call to Update(). Branches(context.Context) ([]*git.Branch, error) // UpdateCallback is a function which is called after the Graph is // updated but before the changes are committed. If UpdateCallback // returns an error, the changes are not committed. This allows the // RepoImpl to perform caching, for example. The parameters are the // list of commits which were added during the current Update, the // list of commits which were removed, and the new state of the Graph. UpdateCallback(context.Context, []*vcsinfo.LongCommit, []*vcsinfo.LongCommit, *Graph) error }
RepoImpl provides methods for interacting with a git repo, agnostic of how the repo is actually accessed. It is used when updating a Graph. It should not be used concurrently.