diff options
| author | Aaron O'Mullan <[email protected]> | 2015-02-11 12:55:16 +0100 |
|---|---|---|
| committer | Aaron O'Mullan <[email protected]> | 2015-02-11 12:55:16 +0100 |
| commit | c10445cd67d400b1a58ccd6ad07f63b4612f8b11 (patch) | |
| tree | 4af0a0f34985aff82853febae5de7f0e22c87e72 /graph.go | |
| parent | 17963043741d7057cae1782032d022af0cd053fb (diff) | |
Add bindings for git_graph_* methods
Add graph.go
Diffstat (limited to 'graph.go')
| -rw-r--r-- | graph.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/graph.go b/graph.go new file mode 100644 index 0000000..f7cf8e9 --- /dev/null +++ b/graph.go @@ -0,0 +1,36 @@ +package git + +/* +#include <git2.h> +*/ +import "C" +import ( + "runtime" +) + +func (repo *Repository) GraphDescendantOf(commit, ancestor *Oid) (bool, error) { + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + ret := C.git_graph_descendant_of(repo.ptr, commit.toC(), ancestor.toC()) + if ret < 0 { + return false, MakeGitError(ret) + } + + return (ret > 0), nil +} + +func (repo *Repository) GraphAheadBehind(local, upstream *Oid) (ahead, behind int, err error) { + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + var aheadT C.size_t + var behindT C.size_t + + ret := C.git_graph_ahead_behind(&aheadT, &behindT, repo.ptr, local.toC(), upstream.toC()) + if ret < 0 { + return 0, 0, MakeGitError(ret) + } + + return int(aheadT), int(behindT), nil +} |
