From c10445cd67d400b1a58ccd6ad07f63b4612f8b11 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Wed, 11 Feb 2015 12:55:16 +0100 Subject: [PATCH 1/2] Add bindings for git_graph_* methods Add graph.go --- graph.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 graph.go 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 +*/ +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 +} From dddcbb71c45932feef3c2d0fe6fbdf375b0de644 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Thu, 12 Feb 2015 18:49:54 +0100 Subject: [PATCH 2/2] Remove "Graph" prefix on method names --- graph.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graph.go b/graph.go index f7cf8e9..e5d7732 100644 --- a/graph.go +++ b/graph.go @@ -8,7 +8,7 @@ import ( "runtime" ) -func (repo *Repository) GraphDescendantOf(commit, ancestor *Oid) (bool, error) { +func (repo *Repository) DescendantOf(commit, ancestor *Oid) (bool, error) { runtime.LockOSThread() defer runtime.UnlockOSThread() @@ -20,7 +20,7 @@ func (repo *Repository) GraphDescendantOf(commit, ancestor *Oid) (bool, error) { return (ret > 0), nil } -func (repo *Repository) GraphAheadBehind(local, upstream *Oid) (ahead, behind int, err error) { +func (repo *Repository) AheadBehind(local, upstream *Oid) (ahead, behind int, err error) { runtime.LockOSThread() defer runtime.UnlockOSThread()