Add config variable for specifying default --dirstat behavior
The new diff.dirstat config variable takes the same arguments as '--dirstat=<args>', and specifies the default arguments for --dirstat. The config is obviously overridden by --dirstat arguments passed on the command line. When not specified, the --dirstat defaults are 'changes,noncumulative,3'. The patch also adds several tests verifying the interaction between the diff.dirstat config variable, and the --dirstat command line option. Improved-by: Junio C Hamano <gitster@pobox.com> 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
2d17495196d0dceb0ff492aa97bfff33ef1baa18
4 files changed
+119
-1
Documentation/diff-config.txt
+36
@@ -8,6 +8,42 @@ diff.autorefreshindex::
8
affects only 'git diff' Porcelain, and not lower level
9
'diff' commands such as 'git diff-files'.
10
11
+diff.dirstat::
12
+ A comma separated list of `--dirstat` parameters specifying the
13
+ default behavior of the `--dirstat` option to linkgit:git-diff[1]`
14
+ and friends. The defaults can be overridden on the command line
15
+ (using `--dirstat=<param1,param2,...>`). The fallback defaults
16
+ (when not changed by `diff.dirstat`) are `changes,noncumulative,3`.
17
+ The following parameters are available:
18
++
19
+--
20
+`changes`;;
21
+ Compute the dirstat numbers by counting the lines that have been
22
+ removed from the source, or added to the destination. This ignores
23
+ the amount of pure code movements within a file. In other words,
24
+ rearranging lines in a file is not counted as much as other changes.
25
+ This is the default behavior when no parameter is given.
26
+`files`;;
27
+ Compute the dirstat numbers by counting the number of files changed.
28
+ Each changed file counts equally in the dirstat analysis. This is
29
+ the computationally cheapest `--dirstat` behavior, since it does
30
+ not have to look at the file contents at all.
31
+`cumulative`;;
32
+ Count changes in a child directory for the parent directory as well.
33
+ Note that when using `cumulative`, the sum of the percentages
34
+ reported may exceed 100%. The default (non-cumulative) behavior can
35
+ be specified with the `noncumulative` parameter.
36
+<limit>;;
37
+ An integer parameter specifies a cut-off percent (3% by default).
38
+ Directories contributing less than this percentage of the changes
39
+ are not shown in the output.
40
+--
41
++
42
+Example: The following will count changed files, while ignoring
43
+directories with less than 10% of the total amount of changed files,
44
+and accumulating child directory counts in the parent directories:
45
+`files,10,cumulative`.
46
+
47
diff.external::
48
If this config variable is set, diff generation is not
49
performed using the internal diff machinery, but using the
Documentation/diff-options.txt
+2
@@ -70,6 +70,8 @@ endif::git-format-patch[]
70
Output the distribution of relative amount of changes for each
71
sub-directory. The behavior of `--dirstat` can be customized by
72
passing it a comma separated list of parameters.
73
+ The defaults are controlled by the `diff.dirstat` configuration
74
+ variable (see linkgit:git-config[1]).
75
The following parameters are available:
76
+
77
--
diff.c
+9
-1
@@ -31,6 +31,7 @@ static const char *external_diff_cmd_cfg;
31
int diff_auto_refresh_index = 1;
32
static int diff_mnemonic_prefix;
33
static int diff_no_prefix;
34
+static int diff_dirstat_percent_default = 3;
35
static struct diff_options default_diff_options;
36
37
static char diff_colors[][COLOR_MAXLEN] = {
@@ -180,6 +181,13 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
181
return 0;
182
}
183
184
+ if (!strcmp(var, "diff.dirstat")) {
185
+ default_diff_options.dirstat_percent = diff_dirstat_percent_default;
186
+ (void) parse_dirstat_params(&default_diff_options, value);
187
+ diff_dirstat_percent_default = default_diff_options.dirstat_percent;
188
+ return 0;
189
+ }
190
+
191
if (!prefixcmp(var, "submodule."))
192
return parse_submodule_config_option(var, value);
193
@@ -2926,7 +2934,7 @@ void diff_setup(struct diff_options *options)
2934
options->line_termination = '\n';
2935
options->break_opt = -1;
2936
options->rename_limit = -1;
2929
- options->dirstat_percent = 3;
2937
+ options->dirstat_percent = diff_dirstat_percent_default;
2938
options->context = 3;
2939
2940
options->change = diff_change;
t/t4047-diff-dirstat.sh
+72
@@ -386,6 +386,15 @@ test_expect_success 'later options override earlier options:' '
386
test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
387
'
388
389
+test_expect_success 'non-defaults in config overridden by explicit defaults on command line' '
390
+ git -c diff.dirstat=files,cumulative,50 diff --dirstat=changes,noncumulative,3 HEAD^..HEAD >actual_diff_dirstat &&
391
+ test_cmp expect_diff_dirstat actual_diff_dirstat &&
392
+ git -c diff.dirstat=files,cumulative,50 diff --dirstat=changes,noncumulative,3 -M HEAD^..HEAD >actual_diff_dirstat_M &&
393
+ test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
394
+ git -c diff.dirstat=files,cumulative,50 diff --dirstat=changes,noncumulative,3 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
395
+ test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
396
+'
397
+
398
cat <<EOF >expect_diff_dirstat
399
2.1% changed/
400
10.8% dst/copy/changed/
@@ -437,6 +446,15 @@ test_expect_success '-X0' '
446
test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
447
'
448
449
+test_expect_success 'diff.dirstat=0' '
450
+ git -c diff.dirstat=0 diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
451
+ test_cmp expect_diff_dirstat actual_diff_dirstat &&
452
+ git -c diff.dirstat=0 diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
453
+ test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
454
+ git -c diff.dirstat=0 diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
455
+ test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
456
+'
457
+
458
cat <<EOF >expect_diff_dirstat
459
2.1% changed/
460
10.8% dst/copy/changed/
@@ -507,6 +525,24 @@ test_expect_success '-X0,cumulative' '
525
test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
526
'
527
528
+test_expect_success 'diff.dirstat=0,cumulative' '
529
+ git -c diff.dirstat=0,cumulative diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
530
+ test_cmp expect_diff_dirstat actual_diff_dirstat &&
531
+ git -c diff.dirstat=0,cumulative diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
532
+ test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
533
+ git -c diff.dirstat=0,cumulative diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
534
+ test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
535
+'
536
+
537
+test_expect_success 'diff.dirstat=0 & --dirstat=cumulative' '
538
+ git -c diff.dirstat=0 diff --dirstat=cumulative HEAD^..HEAD >actual_diff_dirstat &&
539
+ test_cmp expect_diff_dirstat actual_diff_dirstat &&
540
+ git -c diff.dirstat=0 diff --dirstat=cumulative -M HEAD^..HEAD >actual_diff_dirstat_M &&
541
+ test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
542
+ git -c diff.dirstat=0 diff --dirstat=cumulative -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
543
+ test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
544
+'
545
+
546
cat <<EOF >expect_diff_dirstat
547
9.0% changed/
548
9.0% dst/copy/changed/
@@ -558,6 +594,15 @@ test_expect_success '--dirstat=files' '
594
test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
595
'
596
597
+test_expect_success 'diff.dirstat=files' '
598
+ git -c diff.dirstat=files diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
599
+ test_cmp expect_diff_dirstat actual_diff_dirstat &&
600
+ git -c diff.dirstat=files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
601
+ test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
602
+ git -c diff.dirstat=files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
603
+ test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
604
+'
605
+
606
cat <<EOF >expect_diff_dirstat
607
27.2% dst/copy/
608
27.2% dst/move/
@@ -601,6 +646,15 @@ test_expect_success '--dirstat=files,10' '
646
test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
647
'
648
649
+test_expect_success 'diff.dirstat=10,files' '
650
+ git -c diff.dirstat=10,files diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
651
+ test_cmp expect_diff_dirstat actual_diff_dirstat &&
652
+ git -c diff.dirstat=10,files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
653
+ test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
654
+ git -c diff.dirstat=10,files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
655
+ test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
656
+'
657
+
658
cat <<EOF >expect_diff_dirstat
659
9.0% changed/
660
9.0% dst/copy/changed/
@@ -662,6 +716,15 @@ test_expect_success '--dirstat=files,cumulative' '
716
test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
717
'
718
719
+test_expect_success 'diff.dirstat=cumulative,files' '
720
+ git -c diff.dirstat=cumulative,files diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
721
+ test_cmp expect_diff_dirstat actual_diff_dirstat &&
722
+ git -c diff.dirstat=cumulative,files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
723
+ test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
724
+ git -c diff.dirstat=cumulative,files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
725
+ test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
726
+'
727
+
728
cat <<EOF >expect_diff_dirstat
729
27.2% dst/copy/
730
27.2% dst/move/
@@ -703,4 +766,13 @@ test_expect_success '--dirstat=files,cumulative,10' '
766
test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
767
'
768
769
+test_expect_success 'diff.dirstat=10,cumulative,files' '
770
+ git -c diff.dirstat=10,cumulative,files diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
771
+ test_cmp expect_diff_dirstat actual_diff_dirstat &&
772
+ git -c diff.dirstat=10,cumulative,files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
773
+ test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
774
+ git -c diff.dirstat=10,cumulative,files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
775
+ test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
776
+'
777
+
778
test_done