diff options
| author | lhchavez <[email protected]> | 2021-09-05 20:06:56 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-09-05 20:06:56 -0700 |
| commit | c8ce59d4eb3fc736fa380e7a2747c96659552e5d (patch) | |
| tree | 922d6ba292a5bee722b5e5b696f19c5968088910 /graph.go | |
| parent | 922f2f74874258e601a5b49bc90d33e8480e2227 (diff) | |
Add support for Repository.ReachableFromAny() (#826)
This change exposes the binding for `git_graph_reachable_from_any()`.
Diffstat (limited to 'graph.go')
| -rw-r--r-- | graph.go | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -40,3 +40,30 @@ func (repo *Repository) AheadBehind(local, upstream *Oid) (ahead, behind int, er return int(aheadT), int(behindT), nil } + +// ReachableFromAny returns whether a commit is reachable from any of a list of +// commits by following parent edges. +func (repo *Repository) ReachableFromAny(commit *Oid, descendants []*Oid) (bool, error) { + if len(descendants) == 0 { + return false, nil + } + + coids := make([]C.git_oid, len(descendants)) + for i := 0; i < len(descendants); i++ { + coids[i] = *descendants[i].toC() + } + + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + ret := C.git_graph_reachable_from_any(repo.ptr, commit.toC(), &coids[0], C.size_t(len(descendants))) + runtime.KeepAlive(repo) + runtime.KeepAlive(commit) + runtime.KeepAlive(coids) + runtime.KeepAlive(descendants) + if ret < 0 { + return false, MakeGitError(ret) + } + + return (ret > 0), nil +} |
