diff options
author | Russell Belfer <rb@github.com> | 2014-04-22 12:33:27 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2014-04-22 12:33:27 -0700 |
commit | 8d09efa24ee01e9e4b14672978bfd1bb1ca2436a (patch) | |
tree | d68210d412062a84d73a60ddb01a7a2501af0b29 /include/git2 | |
parent | 12e422a0562de2aebb05f5f414dbcde7caf85886 (diff) | |
download | libgit2-8d09efa24ee01e9e4b14672978bfd1bb1ca2436a.tar.gz |
Use git_diff_get_stats in example/diff + refactor
This takes the `--stat` and related example options in the example
diff.c program and converts them to use the `git_diff_get_stats`
API which nicely formats stats for you.
I went to add bar-graph scaling to the stats formatter and noticed
that the `git_diff_stats` structure was holding on to all of the
`git_patch` objects. Unfortunately, each of these objects keeps
the full text of the diff in memory, so this is very expensive. I
ended up modifying `git_diff_stats` to keep just the data that it
needs to keep and allowed it to release the patches. Then, I added
width scaling to the output on top of that.
In making the diff example program match 'git diff' output, I ended
up removing an newline from the sumamry output which I then had to
compensate for in the email formatting to match the expectations.
Lastly, I went through and refactored the tests to use a couple of
helper functions and reduce the overall amount of code there.
Diffstat (limited to 'include/git2')
-rw-r--r-- | include/git2/diff.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/include/git2/diff.h b/include/git2/diff.h index c8e1ad143..e5e641a2a 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -1136,12 +1136,14 @@ GIT_EXTERN(size_t) git_diff_stats_deletions( * @param out buffer to store the formatted diff statistics in. * @param stats A `git_diff_stats` generated by one of the above functions. * @param format Formatting option. + * @param width Target width for output (only affects GIT_DIFF_STATS_FULL) * @return 0 on success; non-zero on error */ GIT_EXTERN(int) git_diff_stats_to_buf( git_buf *out, const git_diff_stats *stats, - git_diff_stats_format_t format); + git_diff_stats_format_t format, + size_t width); /** * Deallocate a `git_diff_stats`. |