When --shortstat is used in conjunction with --dirstat=changes, git diff will
output the dirstat information twice: first as calculated by the 'lines'
algorithm, then as calculated by the 'changes' algorithm:

    $ git diff --dirstat=changes,10 --shortstat v2.2.0..v2.2.1
     23 files changed, 453 insertions(+), 54 deletions(-)
      33.5% Documentation/RelNotes/
      26.2% t/
      46.6% Documentation/RelNotes/
      16.6% t/

The same duplication happens for --shortstat together with --dirstat=files, but
not for --shortstat together with --dirstat=lines.

Limit output to only include one dirstat part, calculated as specified
by the --dirstat parameter. Also, add test for this.

Signed-off-by: Mårten Kongstad <marten.kongs...@gmail.com>
---
v3: change how tests count (part of) the dirstat number of lines: instead of
'grep -c', use 'grep >filename && test_line_count'. Thanks to Torsten
Bögershausen and SZEDER Gábor for pointing out how to improve the tests.

 diff.c                  |  2 +-
 t/t4047-diff-dirstat.sh | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/diff.c b/diff.c
index d1bd534..abc32c8 100644
--- a/diff.c
+++ b/diff.c
@@ -4541,7 +4541,7 @@ void diff_flush(struct diff_options *options)
                        show_stats(&diffstat, options);
                if (output_format & DIFF_FORMAT_SHORTSTAT)
                        show_shortstats(&diffstat, options);
-               if (output_format & DIFF_FORMAT_DIRSTAT)
+               if (output_format & DIFF_FORMAT_DIRSTAT && dirstat_by_line)
                        show_dirstat_by_line(&diffstat, options);
                free_diffstat_info(&diffstat);
                separator++;
diff --git a/t/t4047-diff-dirstat.sh b/t/t4047-diff-dirstat.sh
index ed7e093..065d74f 100755
--- a/t/t4047-diff-dirstat.sh
+++ b/t/t4047-diff-dirstat.sh
@@ -973,4 +973,15 @@ test_expect_success 'diff.dirstat=future_param,0,lines 
should warn, but still wo
        test_i18ngrep -q "diff\\.dirstat" actual_error
 '
 
+test_expect_success '--shortstat --dirstat should output only one dirstat' '
+       git diff --shortstat --dirstat=changes HEAD^..HEAD | grep " 
dst/copy/changed/$" >actual_diff_shortstat_dirstat_changes &&
+       test_line_count = 1 actual_diff_shortstat_dirstat_changes &&
+
+       git diff --shortstat --dirstat=lines HEAD^..HEAD | grep " 
dst/copy/changed/$" >actual_diff_shortstat_dirstat_lines &&
+       test_line_count = 1 actual_diff_shortstat_dirstat_lines &&
+
+       git diff --shortstat --dirstat=files HEAD^..HEAD | grep " 
dst/copy/changed/$" >actual_diff_shortstat_dirstat_files &&
+       test_line_count = 1 actual_diff_shortstat_dirstat_files
+'
+
 test_done
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to