Skip to content

Commit

Permalink
Add ability to load parent commits
Browse files Browse the repository at this point in the history
  • Loading branch information
rgburke committed Mar 6, 2018
1 parent 753b8de commit 2690417
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cmd/grv/repo_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type RepoData interface {
CommitByIndex(ref Ref, index uint) (*Commit, error)
Commit(oid *Oid) (*Commit, error)
CommitByOid(oidStr string) (*Commit, error)
CommitParents(oid *Oid) ([]*Commit, error)
AddCommitFilter(Ref, *CommitFilter) error
RemoveCommitFilter(Ref) error
DiffCommit(commit *Commit) (*Diff, error)
Expand Down Expand Up @@ -1276,6 +1277,29 @@ func (repoData *RepositoryData) CommitByOid(oidStr string) (*Commit, error) {
return repoData.repoDataLoader.CommitByOid(oidStr)
}

// CommitParents loads the parents of a commit
func (repoData *RepositoryData) CommitParents(oid *Oid) (parentCommits []*Commit, err error) {
commit, err := repoData.repoDataLoader.Commit(oid)
if err != nil {
return
}

parentCount := commit.commit.ParentCount()
var parentCommit *Commit

for i := uint(0); i < parentCount; i++ {
parentOid := &Oid{commit.commit.ParentId(i)}
parentCommit, err = repoData.Commit(parentOid)
if err != nil {
return
}

parentCommits = append(parentCommits, parentCommit)
}

return
}

// AddCommitFilter adds the filter to the specified ref
func (repoData *RepositoryData) AddCommitFilter(ref Ref, commitFilter *CommitFilter) error {
return repoData.refCommitSets.addCommitFilter(ref, commitFilter)
Expand Down

0 comments on commit 2690417

Please sign in to comment.