summaryrefslogtreecommitdiff
path: root/patch.go
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2014-04-26 20:51:21 +0200
committerCarlos Martín Nieto <[email protected]>2014-04-26 20:51:21 +0200
commit5809f031087e5665549de3355034b193f7c13853 (patch)
treef6b673a2893649b95ea7d157db0e4b43ce9e0e19 /patch.go
parent4df7eb516c7c73f82a62a8bdb2ac33f2b73ab981 (diff)
parent63fd1f9b032c92b330948cd66dfa0b677d982d03 (diff)
Merge commit 'refs/pull/72/head' of github.com:libgit2/git2go
Conflicts: git.go wrapper.c
Diffstat (limited to 'patch.go')
-rw-r--r--patch.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/patch.go b/patch.go
new file mode 100644
index 0000000..0665501
--- /dev/null
+++ b/patch.go
@@ -0,0 +1,48 @@
+package git
+
+/*
+#include <git2.h>
+*/
+import "C"
+import (
+ "runtime"
+)
+
+type Patch struct {
+ ptr *C.git_patch
+}
+
+func newPatchFromC(ptr *C.git_patch) *Patch {
+ if ptr == nil {
+ return nil
+ }
+
+ patch := &Patch{
+ ptr: ptr,
+ }
+
+ runtime.SetFinalizer(patch, (*Patch).Free)
+ return patch
+}
+
+func (patch *Patch) Free() error {
+ if patch.ptr == nil {
+ return ErrInvalid
+ }
+ runtime.SetFinalizer(patch, nil)
+ C.git_patch_free(patch.ptr)
+ patch.ptr = nil
+ return nil
+}
+
+func (patch *Patch) String() (string, error) {
+ if patch.ptr == nil {
+ return "", ErrInvalid
+ }
+ var buf C.git_buf
+ ecode := C.git_patch_to_buf(&buf, patch.ptr)
+ if ecode < 0 {
+ return "", MakeGitError(ecode)
+ }
+ return C.GoString(buf.ptr), nil
+}