diff options
Diffstat (limited to 'patch.go')
| -rw-r--r-- | patch.go | 48 |
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 +} |
