@matheusbsbs / matheus-bagliano / commits / 58a8756a98
Fork 0

Make --dirstat=0 output directories that contribute < 0.1% of changes

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>

Johan Herland committed Apr 29, 2011 at 11:36 UTC 58a8756a98fbd08add1c25ac61ffa4f4f8a6e776
2 files changed +4 -4
diff.c
+2 -2
@@ -1502,8 +1502,8 @@ static long gather_dirstat(struct diff_options *opt, struct dirstat_dir *dir,
1502 * under this directory (sources == 1).
1503 */
1504 if (baselen && sources != 1) {
1505 - int permille = this_dir * 1000 / changed;
1506 - if (permille) {
1505 + if (this_dir) {
1506 + int permille = this_dir * 1000 / changed;
1507 int percent = permille / 10;
1508 if (percent >= dir->percent) {
1509 fprintf(opt->file, "%s%4d.%01d%% %.*s\n", line_prefix,
t/t4047-diff-dirstat.sh
+2 -2
@@ -351,7 +351,6 @@ test_expect_success 'vanilla -X' '
351 test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
352 '
353
354 -# rearranged/text falls below 0% threshold (1 / (240 * 9 + 48 + 1) ~= 0.045 %)
354 cat <<EOF >expect_diff_dirstat
355 2.1% changed/
356 10.8% dst/copy/changed/
@@ -360,6 +359,7 @@ cat <<EOF >expect_diff_dirstat
359 10.8% dst/move/changed/
360 10.8% dst/move/rearranged/
361 10.8% dst/move/unchanged/
362 + 0.0% rearranged/
363 10.8% src/move/changed/
364 10.8% src/move/rearranged/
365 10.8% src/move/unchanged/
@@ -402,7 +402,6 @@ test_expect_success '-X0' '
402 test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
403 '
404
405 -# rearranged/text falls below 0% threshold (1 / (240 * 9 + 48 + 1) ~= 0.045 %)
405 cat <<EOF >expect_diff_dirstat
406 2.1% changed/
407 10.8% dst/copy/changed/
@@ -414,6 +413,7 @@ cat <<EOF >expect_diff_dirstat
413 10.8% dst/move/unchanged/
414 32.5% dst/move/
415 65.1% dst/
416 + 0.0% rearranged/
417 10.8% src/move/changed/
418 10.8% src/move/rearranged/
419 10.8% src/move/unchanged/