summaryrefslogtreecommitdiff
path: root/diff.go
diff options
context:
space:
mode:
authorlhchavez <[email protected]>2020-02-23 13:53:17 +0000
committerlhchavez <[email protected]>2020-02-23 13:53:17 +0000
commitc20008416a64e2ae884a14332b258160a261a5df (patch)
tree58ae95d9f007937876eed1aac89b0518a034e442 /diff.go
parent79fe156d307a9c7b294aa92c741dc0c2759a1894 (diff)
parent4bca045e5aa98b0b791fb467705de0692fe3514f (diff)
Merge remote-tracking branch 'upstream/master' into git_index_add_frombuffer
Diffstat (limited to 'diff.go')
-rw-r--r--diff.go40
1 files changed, 38 insertions, 2 deletions
diff --git a/diff.go b/diff.go
index 3cc1dc2..ed2949c 100644
--- a/diff.go
+++ b/diff.go
@@ -39,6 +39,8 @@ const (
DeltaConflicted Delta = C.GIT_DELTA_CONFLICTED
)
+//go:generate stringer -type Delta -trimprefix Delta -tags static
+
type DiffLineType int
const (
@@ -54,6 +56,8 @@ const (
DiffLineBinary DiffLineType = C.GIT_DIFF_LINE_BINARY
)
+//go:generate stringer -type DiffLineType -trimprefix DiffLine -tags static
+
type DiffFile struct {
Path string
Oid *Oid
@@ -246,7 +250,7 @@ const (
func (stats *DiffStats) String(format DiffStatsFormat,
width uint) (string, error) {
buf := C.git_buf{}
- defer C.git_buf_free(&buf)
+ defer C.git_buf_dispose(&buf)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
@@ -284,7 +288,7 @@ type diffForEachData struct {
Error error
}
-type DiffForEachFileCallback func(DiffDelta, float64) (DiffForEachHunkCallback, error)
+type DiffForEachFileCallback func(delta DiffDelta, progress float64) (DiffForEachHunkCallback, error)
type DiffDetail int
@@ -405,6 +409,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 (
@@ -437,6 +471,8 @@ const (
DiffShowUnmodified DiffOptionsFlag = C.GIT_DIFF_SHOW_UNMODIFIED
DiffPatience DiffOptionsFlag = C.GIT_DIFF_PATIENCE
DiffMinimal DiffOptionsFlag = C.GIT_DIFF_MINIMAL
+ DiffShowBinary DiffOptionsFlag = C.GIT_DIFF_SHOW_BINARY
+ DiffIndentHeuristic DiffOptionsFlag = C.GIT_DIFF_INDENT_HEURISTIC
)
type DiffNotifyCallback func(diffSoFar *Diff, deltaToAdd DiffDelta, matchedPathspec string) error