Skip to content

Commit 2690417

Browse files
committed
Add ability to load parent commits
1 parent 753b8de commit 2690417

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

cmd/grv/repo_data.go

+24
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type RepoData interface {
6767
CommitByIndex(ref Ref, index uint) (*Commit, error)
6868
Commit(oid *Oid) (*Commit, error)
6969
CommitByOid(oidStr string) (*Commit, error)
70+
CommitParents(oid *Oid) ([]*Commit, error)
7071
AddCommitFilter(Ref, *CommitFilter) error
7172
RemoveCommitFilter(Ref) error
7273
DiffCommit(commit *Commit) (*Diff, error)
@@ -1276,6 +1277,29 @@ func (repoData *RepositoryData) CommitByOid(oidStr string) (*Commit, error) {
12761277
return repoData.repoDataLoader.CommitByOid(oidStr)
12771278
}
12781279

1280+
// CommitParents loads the parents of a commit
1281+
func (repoData *RepositoryData) CommitParents(oid *Oid) (parentCommits []*Commit, err error) {
1282+
commit, err := repoData.repoDataLoader.Commit(oid)
1283+
if err != nil {
1284+
return
1285+
}
1286+
1287+
parentCount := commit.commit.ParentCount()
1288+
var parentCommit *Commit
1289+
1290+
for i := uint(0); i < parentCount; i++ {
1291+
parentOid := &Oid{commit.commit.ParentId(i)}
1292+
parentCommit, err = repoData.Commit(parentOid)
1293+
if err != nil {
1294+
return
1295+
}
1296+
1297+
parentCommits = append(parentCommits, parentCommit)
1298+
}
1299+
1300+
return
1301+
}
1302+
12791303
// AddCommitFilter adds the filter to the specified ref
12801304
func (repoData *RepositoryData) AddCommitFilter(ref Ref, commitFilter *CommitFilter) error {
12811305
return repoData.refCommitSets.addCommitFilter(ref, commitFilter)

0 commit comments

Comments
 (0)