summaryrefslogtreecommitdiff
path: root/diff.go
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2019-06-18 11:33:28 +0200
committerGitHub <[email protected]>2019-06-18 11:33:28 +0200
commit4fa93499429f056b0d7c6e2634b9f17d29df96b3 (patch)
tree71e1ab4b449414f0e594e0ffa93dc69532fe51de /diff.go
parentbf1e8a4338822ad2539a3876f58b15b590eb9e1f (diff)
parentad02c37e6d57dddf25d9c72a788a447dd7d5de12 (diff)
Merge pull request #512 from codeocean/diff-to-buf
Add Diff.ToBuf wrapping git_diff_to_buf
Diffstat (limited to 'diff.go')
-rw-r--r--diff.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/diff.go b/diff.go
index 20eb9e8..b025edd 100644
--- a/diff.go
+++ b/diff.go
@@ -405,6 +405,36 @@ func (diff *Diff) Patch(deltaIndex int) (*Patch, error) {
return newPatchFromC(patchPtr), nil
}
+type DiffFormat int
+
+const (
+ DiffFormatPatch DiffFormat = C.GIT_DIFF_FORMAT_PATCH
+ DiffFormatPatchHeader DiffFormat = C.GIT_DIFF_FORMAT_PATCH_HEADER
+ DiffFormatRaw DiffFormat = C.GIT_DIFF_FORMAT_RAW
+ DiffFormatNameOnly DiffFormat = C.GIT_DIFF_FORMAT_NAME_ONLY
+ DiffFormatNameStatus DiffFormat = C.GIT_DIFF_FORMAT_NAME_STATUS
+)
+
+func (diff *Diff) ToBuf(format DiffFormat) ([]byte, error) {
+ if diff.ptr == nil {
+ return nil, ErrInvalid
+ }
+
+ diffBuf := C.git_buf{}
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ ecode := C.git_diff_to_buf(&diffBuf, diff.ptr, C.git_diff_format_t(format))
+ runtime.KeepAlive(diff)
+ if ecode < 0 {
+ return nil, MakeGitError(ecode)
+ }
+ defer C.git_buf_free(&diffBuf)
+
+ return C.GoBytes(unsafe.Pointer(diffBuf.ptr), C.int(diffBuf.size)), nil
+}
+
type DiffOptionsFlag int
const (