From bc80beb8432091bdf1190ad6b803060324802685 Mon Sep 17 00:00:00 2001 From: lye Date: Thu, 20 Feb 2014 00:25:30 -0600 Subject: Add partial diff/patch functionality. This commit adds barebones capacity to generate diffs from two trees and to emit those as git-style diffs (via `Patch.String`), or to enumerate the files/hunks/lines in the diff to emit the data yourself. The walk functions have been implemented in the same manner as the Odb walking methods. Note that not all of the functionality is implemented for either the `git_diff_*` nor the `git_patch_*` functions, and there are unexposed constants which would likely be useful to add. --- patch.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 patch.go (limited to 'patch.go') diff --git a/patch.go b/patch.go new file mode 100644 index 0000000..561786e --- /dev/null +++ b/patch.go @@ -0,0 +1,37 @@ +package git + +/* +#include +*/ +import "C" +import ( + "runtime" +) + +type Patch struct { + ptr *C.git_patch +} + +func newPatch(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() { + runtime.SetFinalizer(patch, nil) + C.git_patch_free(patch.ptr) +} + +func (patch *Patch) String() string { + var cptr *C.char + C.git_patch_to_str(&cptr, patch.ptr) + return C.GoString(cptr) +} -- cgit v1.2.3