Code

Make --dirstat=0 output directories that contribute < 0.1% of changes
authorJohan Herland <johan@herland.net>
Fri, 29 Apr 2011 09:36:17 +0000 (11:36 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 29 Apr 2011 18:17:36 +0000 (11:17 -0700)
The expected output from --dirstat=0, is to include any directory with
changes, even if those changes contribute a minuscule portion of the total
changes. However, currently, directories that contribute less than 0.1% are
not included, since their 'permille' value is 0, and there is an
'if (permille)' check in gather_dirstat() that causes them to be ignored.

This test is obviously intended to exclude directories that contribute no
changes whatsoever, but in this case, it hits too broadly. The correct
check is against 'this_dir' from which the permille is calculated. Only if
this value is 0 does the directory truly contribute no changes, and should
be skipped from the output.

This patches fixes this issue, and updates corresponding testcases to
expect the new behvaior.

Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff.c
t/t4047-diff-dirstat.sh

diff --git a/diff.c b/diff.c
index 3b40e597d5793d13944f9604e5197ac216eb3a3e..004a46b529d162fcac070796f8d91d69ef1f5310 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -1502,8 +1502,8 @@ static long gather_dirstat(struct diff_options *opt, struct dirstat_dir *dir,
         *    under this directory (sources == 1).
         */
        if (baselen && sources != 1) {
-               int permille = this_dir * 1000 / changed;
-               if (permille) {
+               if (this_dir) {
+                       int permille = this_dir * 1000 / changed;
                        int percent = permille / 10;
                        if (percent >= dir->percent) {
                                fprintf(opt->file, "%s%4d.%01d%% %.*s\n", line_prefix,
index ce7c4033f8e54f3ee352fa559b9b3b7a4bb71837..1c5adadf3266dab844bd7b9db97c76c9bb8b7804 100755 (executable)
@@ -351,7 +351,6 @@ test_expect_success 'vanilla -X' '
        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 '
 
-# rearranged/text falls below 0% threshold (1 / (240 * 9 + 48 + 1) ~= 0.045 %)
 cat <<EOF >expect_diff_dirstat
    2.1% changed/
   10.8% dst/copy/changed/
@@ -360,6 +359,7 @@ cat <<EOF >expect_diff_dirstat
   10.8% dst/move/changed/
   10.8% dst/move/rearranged/
   10.8% dst/move/unchanged/
+   0.0% rearranged/
   10.8% src/move/changed/
   10.8% src/move/rearranged/
   10.8% src/move/unchanged/
@@ -402,7 +402,6 @@ test_expect_success '-X0' '
        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 '
 
-# rearranged/text falls below 0% threshold (1 / (240 * 9 + 48 + 1) ~= 0.045 %)
 cat <<EOF >expect_diff_dirstat
    2.1% changed/
   10.8% dst/copy/changed/
@@ -414,6 +413,7 @@ cat <<EOF >expect_diff_dirstat
   10.8% dst/move/unchanged/
   32.5% dst/move/
   65.1% dst/
+   0.0% rearranged/
   10.8% src/move/changed/
   10.8% src/move/rearranged/
   10.8% src/move/unchanged/