blob: 06655018f4dbedde9164bf51d8beb4fd2ff1a0a3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
}
|