diff options
author | Richard Burke <rich.g.burke@gmail.com> | 2018-03-06 22:25:05 +0000 |
---|---|---|
committer | Richard Burke <rich.g.burke@gmail.com> | 2018-03-06 22:25:05 +0000 |
commit | 2690417e3878d41cc8b95e13de567295c3945045 (patch) | |
tree | c36b8aff9221d928136d94183dfae7f7caf6147c | |
parent | 753b8de5abc6b182598cd4fc1506c795206eb182 (diff) |
Add ability to load parent commitsv0.1.3
-rw-r--r-- | cmd/grv/repo_data.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/cmd/grv/repo_data.go b/cmd/grv/repo_data.go index fe9d074..5b01527 100644 --- a/cmd/grv/repo_data.go +++ b/cmd/grv/repo_data.go @@ -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) @@ -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) |