diff options
| author | Travis Lane <[email protected]> | 2016-04-07 21:51:00 -0700 |
|---|---|---|
| committer | Travis Lane <[email protected]> | 2016-06-19 15:19:39 -0700 |
| commit | 981538924c7607980dd8328564cad6c0aedd6154 (patch) | |
| tree | 445be497eb185bb7a184f50255fe4ffedc0221c8 | |
| parent | 8eaae73f85dd3df78df80d2dac066eb0866444ae (diff) | |
diff: Add DiffStats String
This implements git_diff_stats_to_buf which provides the output for
git diff --stats.
| -rw-r--r-- | diff.go | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -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) |
