diff options
author | Russell Belfer <rb@github.com> | 2013-01-30 11:10:39 -0800 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-01-30 11:10:39 -0800 |
commit | f1e2735c74d03105592a282e2c32f45033db0e8d (patch) | |
tree | 6bb4ac08b1b90022c61339db67fd5949dc6fced8 /include | |
parent | d2041216578de4e6fbb466d439fac5de7f35caf3 (diff) | |
download | libgit2-f1e2735c74d03105592a282e2c32f45033db0e8d.tar.gz |
Add helper for diff line stats
This adds a `git_diff_patch_line_stats()` API that gets the total
number of adds, deletes, and context lines in a patch. This will
make it a little easier to emulate `git diff --stat` and the like.
Right now, this relies on generating the `git_diff_patch` object,
which is a pretty heavyweight way to get stat information. At
some future point, it would probably be nice to be able to get
this information without allocating the entire `git_diff_patch`,
but that's a much larger project.
Diffstat (limited to 'include')
-rw-r--r-- | include/git2/diff.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/include/git2/diff.h b/include/git2/diff.h index c052f34f8..81c41df04 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -704,6 +704,28 @@ GIT_EXTERN(size_t) git_diff_patch_num_hunks( git_diff_patch *patch); /** + * Get line counts of each type in a patch. + * + * This helps imitate a diff --numstat type of output. For that purpose, + * you only need the `total_additions` and `total_deletions` values, but we + * include the `total_context` line count in case you want the total number + * of lines of diff output that will be generated. + * + * All outputs are optional. Pass NULL if you don't need a particular count. + * + * @param total_context Count of context lines in output, can be NULL. + * @param total_additions Count of addition lines in output, can be NULL. + * @param total_deletions Count of deletion lines in output, can be NULL. + * @param patch The git_diff_patch object + * @return Number of lines in hunk or -1 if invalid hunk index + */ +GIT_EXTERN(int) git_diff_patch_line_stats( + size_t *total_context, + size_t *total_additions, + size_t *total_deletions, + const git_diff_patch *patch); + +/** * Get the information about a hunk in a patch * * Given a patch and a hunk index into the patch, this returns detailed |