mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-03 11:20:59 +00:00
make git_diff_stats_to_buf not show 0 insertions or 0 deletions
This commit is contained in:
parent
f0ee795ccb
commit
dc5cfdbab9
@ -299,15 +299,24 @@ int git_diff_stats_to_buf(
|
||||
}
|
||||
|
||||
if (format & GIT_DIFF_STATS_FULL || format & GIT_DIFF_STATS_SHORT) {
|
||||
error = git_buf_printf(
|
||||
out, " %" PRIuZ " file%s changed, %" PRIuZ
|
||||
" insertion%s(+), %" PRIuZ " deletion%s(-)\n",
|
||||
stats->files_changed, stats->files_changed != 1 ? "s" : "",
|
||||
stats->insertions, stats->insertions != 1 ? "s" : "",
|
||||
stats->deletions, stats->deletions != 1 ? "s" : "");
|
||||
git_buf_printf(
|
||||
out, " %" PRIuZ " file%s changed",
|
||||
stats->files_changed, stats->files_changed != 1 ? "s" : "");
|
||||
|
||||
if (error < 0)
|
||||
return error;
|
||||
if (stats->insertions || stats->deletions == 0)
|
||||
git_buf_printf(
|
||||
out, ", %" PRIuZ " insertion%s(+)",
|
||||
stats->insertions, stats->insertions != 1 ? "s" : "");
|
||||
|
||||
if (stats->deletions || stats->insertions == 0)
|
||||
git_buf_printf(
|
||||
out, ", %" PRIuZ " deletion%s(-)",
|
||||
stats->deletions, stats->deletions != 1 ? "s" : "");
|
||||
|
||||
git_buf_putc(out, '\n');
|
||||
|
||||
if (git_buf_oom(out))
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (format & GIT_DIFF_STATS_INCLUDE_SUMMARY) {
|
||||
@ -333,4 +342,3 @@ void git_diff_stats_free(git_diff_stats *stats)
|
||||
git__free(stats->filestats);
|
||||
git__free(stats);
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ void test_diff_format_email__with_message(void)
|
||||
"Also test if new paragraphs are included correctly.\n" \
|
||||
"---\n" \
|
||||
" file3.txt | 1 +\n" \
|
||||
" 1 file changed, 1 insertion(+), 0 deletions(-)\n" \
|
||||
" 1 file changed, 1 insertion(+)\n" \
|
||||
"\n" \
|
||||
"diff --git a/file3.txt b/file3.txt\n" \
|
||||
"index 9a2d780..7309653 100644\n" \
|
||||
@ -155,7 +155,7 @@ void test_diff_format_email__multiple(void)
|
||||
"---\n" \
|
||||
" file2.txt | 5 +++++\n" \
|
||||
" file3.txt | 5 +++++\n" \
|
||||
" 2 files changed, 10 insertions(+), 0 deletions(-)\n" \
|
||||
" 2 files changed, 10 insertions(+)\n" \
|
||||
" create mode 100644 file2.txt\n" \
|
||||
" create mode 100644 file3.txt\n" \
|
||||
"\n" \
|
||||
|
@ -113,6 +113,42 @@ void test_diff_stats__shortstat(void)
|
||||
git_buf_free(&buf);
|
||||
}
|
||||
|
||||
void test_diff_stats__shortstat_noinsertions(void)
|
||||
{
|
||||
git_buf buf = GIT_BUF_INIT;
|
||||
const char *stat =
|
||||
" 1 file changed, 2 deletions(-)\n";
|
||||
|
||||
diff_stats_from_commit_oid(
|
||||
&_stats, "06b7b69a62cbd1e53c6c4e0c3f16473dcfdb4af6", false);
|
||||
|
||||
cl_assert_equal_sz(1, git_diff_stats_files_changed(_stats));
|
||||
cl_assert_equal_sz(0, git_diff_stats_insertions(_stats));
|
||||
cl_assert_equal_sz(2, git_diff_stats_deletions(_stats));
|
||||
|
||||
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_SHORT, 0));
|
||||
cl_assert_equal_s(stat, git_buf_cstr(&buf));
|
||||
git_buf_free(&buf);
|
||||
}
|
||||
|
||||
void test_diff_stats__shortstat_nodeletions(void)
|
||||
{
|
||||
git_buf buf = GIT_BUF_INIT;
|
||||
const char *stat =
|
||||
" 1 file changed, 3 insertions(+)\n";
|
||||
|
||||
diff_stats_from_commit_oid(
|
||||
&_stats, "5219b9784f9a92d7bd7cb567a6d6a21bfb86697e", false);
|
||||
|
||||
cl_assert_equal_sz(1, git_diff_stats_files_changed(_stats));
|
||||
cl_assert_equal_sz(3, git_diff_stats_insertions(_stats));
|
||||
cl_assert_equal_sz(0, git_diff_stats_deletions(_stats));
|
||||
|
||||
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_SHORT, 0));
|
||||
cl_assert_equal_s(stat, git_buf_cstr(&buf));
|
||||
git_buf_free(&buf);
|
||||
}
|
||||
|
||||
void test_diff_stats__rename(void)
|
||||
{
|
||||
git_buf buf = GIT_BUF_INIT;
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user