From 981538924c7607980dd8328564cad6c0aedd6154 Mon Sep 17 00:00:00 2001 From: Travis Lane Date: Thu, 7 Apr 2016 21:51:00 -0700 Subject: [PATCH] diff: Add DiffStats String This implements git_diff_stats_to_buf which provides the output for git diff --stats. --- diff.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/diff.go b/diff.go index 9a7ac78..8ae0512 100644 --- a/diff.go +++ b/diff.go @@ -217,6 +217,33 @@ func (stats *DiffStats) FilesChanged() int { return int(C.git_diff_stats_files_changed(stats.ptr)) } +type DiffStatsFormat int + +const ( + DiffStatsNone DiffStatsFormat = C.GIT_DIFF_STATS_NONE + DiffStatsFull DiffStatsFormat = C.GIT_DIFF_STATS_FULL + DiffStatsShort DiffStatsFormat = C.GIT_DIFF_STATS_SHORT + DiffStatsNumber DiffStatsFormat = C.GIT_DIFF_STATS_NUMBER + DiffStatsIncludeSummary DiffStatsFormat = C.GIT_DIFF_STATS_INCLUDE_SUMMARY +) + +func (stats *DiffStats) String(format DiffStatsFormat, + width uint) (string, error) { + buf := C.git_buf{} + defer C.git_buf_free(&buf) + + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + ret := C.git_diff_stats_to_buf(&buf, + stats.ptr, C.git_diff_stats_format_t(format), C.size_t(width)) + if ret < 0 { + return "", MakeGitError(ret) + } + + return C.GoString(buf.ptr), nil +} + func (diff *Diff) Stats() (*DiffStats, error) { stats := new(DiffStats)