Skip to content

Commit 58a8756

Browse files
jherlandgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5502039 commit 58a8756

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

diff.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,8 +1502,8 @@ static long gather_dirstat(struct diff_options *opt, struct dirstat_dir *dir,
15021502
* under this directory (sources == 1).
15031503
*/
15041504
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;
15071507
int percent = permille / 10;
15081508
if (percent >= dir->percent) {
15091509
fprintf(opt->file, "%s%4d.%01d%% %.*s\n", line_prefix,

t/t4047-diff-dirstat.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@ test_expect_success 'vanilla -X' '
351351
test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
352352
'
353353

354-
# rearranged/text falls below 0% threshold (1 / (240 * 9 + 48 + 1) ~= 0.045 %)
355354
cat <<EOF >expect_diff_dirstat
356355
2.1% changed/
357356
10.8% dst/copy/changed/
@@ -360,6 +359,7 @@ cat <<EOF >expect_diff_dirstat
360359
10.8% dst/move/changed/
361360
10.8% dst/move/rearranged/
362361
10.8% dst/move/unchanged/
362+
0.0% rearranged/
363363
10.8% src/move/changed/
364364
10.8% src/move/rearranged/
365365
10.8% src/move/unchanged/
@@ -402,7 +402,6 @@ test_expect_success '-X0' '
402402
test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
403403
'
404404

405-
# rearranged/text falls below 0% threshold (1 / (240 * 9 + 48 + 1) ~= 0.045 %)
406405
cat <<EOF >expect_diff_dirstat
407406
2.1% changed/
408407
10.8% dst/copy/changed/
@@ -414,6 +413,7 @@ cat <<EOF >expect_diff_dirstat
414413
10.8% dst/move/unchanged/
415414
32.5% dst/move/
416415
65.1% dst/
416+
0.0% rearranged/
417417
10.8% src/move/changed/
418418
10.8% src/move/rearranged/
419419
10.8% src/move/unchanged/

0 commit comments

Comments
 (0)