summaryrefslogtreecommitdiff
path: root/diff.go
diff options
context:
space:
mode:
Diffstat (limited to 'diff.go')
-rw-r--r--diff.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/diff.go b/diff.go
index 999f067..63fa867 100644
--- a/diff.go
+++ b/diff.go
@@ -190,6 +190,46 @@ func (diff *Diff) FindSimilar(opts *DiffFindOptions) error {
return nil
}
+type DiffStats struct {
+ ptr *C.git_diff_stats
+}
+
+func (stats *DiffStats) Free() error {
+ if stats.ptr == nil {
+ return ErrInvalid
+ }
+ runtime.SetFinalizer(stats, nil)
+ C.git_diff_stats_free(stats.ptr)
+ stats.ptr = nil
+ return nil
+}
+
+func (stats *DiffStats) Insertions() int {
+ return int(C.git_diff_stats_insertions(stats.ptr))
+}
+
+func (stats *DiffStats) Deletions() int {
+ return int(C.git_diff_stats_deletions(stats.ptr))
+}
+
+func (stats *DiffStats) FilesChanged() int {
+ return int(C.git_diff_stats_files_changed(stats.ptr))
+}
+
+func (diff *Diff) Stats() (*DiffStats, error) {
+ stats := new(DiffStats)
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ if ecode := C.git_diff_get_stats(&stats.ptr, diff.ptr); ecode < 0 {
+ return nil, MakeGitError(ecode)
+ }
+ runtime.SetFinalizer(stats, (*DiffStats).Free)
+
+ return stats, nil
+}
+
type diffForEachData struct {
FileCallback DiffForEachFileCallback
HunkCallback DiffForEachHunkCallback
@@ -371,6 +411,8 @@ func DefaultDiffOptions() (DiffOptions, error) {
InterhunkLines: uint32(opts.interhunk_lines),
IdAbbrev: uint16(opts.id_abbrev),
MaxSize: int(opts.max_size),
+ OldPrefix: "a",
+ NewPrefix: "b",
}, nil
}
@@ -479,6 +521,8 @@ func diffOptionsToC(opts *DiffOptions) (copts *C.git_diff_options, notifyData *d
interhunk_lines: C.uint32_t(opts.InterhunkLines),
id_abbrev: C.uint16_t(opts.IdAbbrev),
max_size: C.git_off_t(opts.MaxSize),
+ old_prefix: C.CString(opts.OldPrefix),
+ new_prefix: C.CString(opts.NewPrefix),
}
if opts.NotifyCallback != nil {
@@ -493,6 +537,8 @@ func freeDiffOptions(copts *C.git_diff_options) {
if copts != nil {
cpathspec := copts.pathspec
freeStrarray(&cpathspec)
+ C.free(unsafe.Pointer(copts.old_prefix))
+ C.free(unsafe.Pointer(copts.new_prefix))
}
}