Skip to content

Commit 610cff1

Browse files
author
Edward Thomson
committed
Merge branch 'pr/3809'
2 parents 2468bf0 + dc5cfdb commit 610cff1

File tree

12 files changed

+58
-13
lines changed

12 files changed

+58
-13
lines changed

src/diff_stats.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -300,15 +300,24 @@ int git_diff_stats_to_buf(
300300
}
301301

302302
if (format & GIT_DIFF_STATS_FULL || format & GIT_DIFF_STATS_SHORT) {
303-
error = git_buf_printf(
304-
out, " %" PRIuZ " file%s changed, %" PRIuZ
305-
" insertion%s(+), %" PRIuZ " deletion%s(-)\n",
306-
stats->files_changed, stats->files_changed != 1 ? "s" : "",
307-
stats->insertions, stats->insertions != 1 ? "s" : "",
308-
stats->deletions, stats->deletions != 1 ? "s" : "");
309-
310-
if (error < 0)
311-
return error;
303+
git_buf_printf(
304+
out, " %" PRIuZ " file%s changed",
305+
stats->files_changed, stats->files_changed != 1 ? "s" : "");
306+
307+
if (stats->insertions || stats->deletions == 0)
308+
git_buf_printf(
309+
out, ", %" PRIuZ " insertion%s(+)",
310+
stats->insertions, stats->insertions != 1 ? "s" : "");
311+
312+
if (stats->deletions || stats->insertions == 0)
313+
git_buf_printf(
314+
out, ", %" PRIuZ " deletion%s(-)",
315+
stats->deletions, stats->deletions != 1 ? "s" : "");
316+
317+
git_buf_putc(out, '\n');
318+
319+
if (git_buf_oom(out))
320+
return -1;
312321
}
313322

314323
if (format & GIT_DIFF_STATS_INCLUDE_SUMMARY) {
@@ -334,4 +343,3 @@ void git_diff_stats_free(git_diff_stats *stats)
334343
git__free(stats->filestats);
335344
git__free(stats);
336345
}
337-

tests/diff/format_email.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void test_diff_format_email__with_message(void)
113113
"Also test if new paragraphs are included correctly.\n" \
114114
"---\n" \
115115
" file3.txt | 1 +\n" \
116-
" 1 file changed, 1 insertion(+), 0 deletions(-)\n" \
116+
" 1 file changed, 1 insertion(+)\n" \
117117
"\n" \
118118
"diff --git a/file3.txt b/file3.txt\n" \
119119
"index 9a2d780..7309653 100644\n" \
@@ -156,7 +156,7 @@ void test_diff_format_email__multiple(void)
156156
"---\n" \
157157
" file2.txt | 5 +++++\n" \
158158
" file3.txt | 5 +++++\n" \
159-
" 2 files changed, 10 insertions(+), 0 deletions(-)\n" \
159+
" 2 files changed, 10 insertions(+)\n" \
160160
" create mode 100644 file2.txt\n" \
161161
" create mode 100644 file3.txt\n" \
162162
"\n" \

tests/diff/stats.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,42 @@ void test_diff_stats__shortstat(void)
114114
git_buf_free(&buf);
115115
}
116116

117+
void test_diff_stats__shortstat_noinsertions(void)
118+
{
119+
git_buf buf = GIT_BUF_INIT;
120+
const char *stat =
121+
" 1 file changed, 2 deletions(-)\n";
122+
123+
diff_stats_from_commit_oid(
124+
&_stats, "06b7b69a62cbd1e53c6c4e0c3f16473dcfdb4af6", false);
125+
126+
cl_assert_equal_sz(1, git_diff_stats_files_changed(_stats));
127+
cl_assert_equal_sz(0, git_diff_stats_insertions(_stats));
128+
cl_assert_equal_sz(2, git_diff_stats_deletions(_stats));
129+
130+
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_SHORT, 0));
131+
cl_assert_equal_s(stat, git_buf_cstr(&buf));
132+
git_buf_free(&buf);
133+
}
134+
135+
void test_diff_stats__shortstat_nodeletions(void)
136+
{
137+
git_buf buf = GIT_BUF_INIT;
138+
const char *stat =
139+
" 1 file changed, 3 insertions(+)\n";
140+
141+
diff_stats_from_commit_oid(
142+
&_stats, "5219b9784f9a92d7bd7cb567a6d6a21bfb86697e", false);
143+
144+
cl_assert_equal_sz(1, git_diff_stats_files_changed(_stats));
145+
cl_assert_equal_sz(3, git_diff_stats_insertions(_stats));
146+
cl_assert_equal_sz(0, git_diff_stats_deletions(_stats));
147+
148+
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_SHORT, 0));
149+
cl_assert_equal_s(stat, git_buf_cstr(&buf));
150+
git_buf_free(&buf);
151+
}
152+
117153
void test_diff_stats__rename(void)
118154
{
119155
git_buf buf = GIT_BUF_INIT;
0 Bytes
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.

0 commit comments

Comments
 (0)