Git fork

merge/pull: extend merge.stat configuration variable to cover --compact-summary

Existing `merge.stat` configuration variable is a Boolean that
defaults to `true` to control `git merge --[no-]stat` behaviour.

Extend it to be "Boolean or text", that takes false, true, or
"compact", with the last one triggering the --compact-summary option
introduced earlier. Any other values are taken as the same as true,
instead of signaling an error---it is not a grave enough offence to
stop their merge.

Signed-off-by: Junio C Hamano <gitster@pobox.com>

+87 -4
+12 -2
Documentation/config/merge.adoc
··· 81 81 attributes" in linkgit:gitattributes[5]. 82 82 83 83 `merge.stat`:: 84 - Whether to print the diffstat between `ORIG_HEAD` and the merge result 85 - at the end of the merge. True by default. 84 + What, if anything, to print between `ORIG_HEAD` and the merge result 85 + at the end of the merge. Possible values are: 86 + + 87 + -- 88 + `false`;; Show nothing. 89 + `true`;; Show `git diff --diffstat --summary ORIG_HEAD`. 90 + `compact`;; Show `git diff --compact-summary ORIG_HEAD`. 91 + -- 92 + + 93 + but any unrecognised value (e.g., a value added by a future version of 94 + Git) is taken as `true` instead of triggering an error. Defaults to 95 + `true`. 86 96 87 97 `merge.autoStash`:: 88 98 When set to `true`, automatically create a temporary stash entry
+29 -2
builtin/merge.c
··· 673 673 } 674 674 675 675 if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat")) { 676 - show_diffstat = git_config_bool(k, v) 677 - ? MERGE_SHOW_DIFFSTAT : 0; 676 + int val = git_parse_maybe_bool_text(v); 677 + switch (val) { 678 + case 0: 679 + show_diffstat = 0; 680 + break; 681 + case 1: 682 + show_diffstat = MERGE_SHOW_DIFFSTAT; 683 + break; 684 + default: 685 + if (!strcmp(v, "compact")) 686 + show_diffstat = MERGE_SHOW_COMPACTSUMMARY; 687 + /* 688 + * We do not need to have an explicit 689 + * 690 + * else if (!strcmp(v, "diffstat")) 691 + * show_diffstat = MERGE_SHOW_DIFFSTAT; 692 + * 693 + * here, because the catch-all uses the 694 + * diffstat style anyway. 695 + */ 696 + else 697 + /* 698 + * A setting from a future? It is not an 699 + * error grave enough to fail the command. 700 + * proceed using the default one. 701 + */ 702 + show_diffstat = MERGE_SHOW_DIFFSTAT; 703 + break; 704 + } 678 705 } else if (!strcmp(k, "merge.verifysignatures")) { 679 706 verify_signatures = git_config_bool(k, v); 680 707 } else if (!strcmp(k, "pull.twohead")) {
+46
t/t7600-merge.sh
··· 216 216 verify_head "$c1" 217 217 ' 218 218 219 + test_expect_success 'the same merge with merge.stat=diffstat' ' 220 + cat >expect <<-\EOF && 221 + Updating FROM..TO 222 + Fast-forward 223 + file | 2 +- 224 + other | 9 +++++++++ 225 + 2 files changed, 10 insertions(+), 1 deletion(-) 226 + create mode 100644 other 227 + EOF 228 + 229 + git reset --hard c0 && 230 + git -c merge.stat=diffstat merge c1 >out && 231 + sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual && 232 + test_cmp expect actual 233 + ' 234 + 219 235 test_expect_success 'the same merge with compact summary' ' 220 236 cat >expect <<-\EOF && 221 237 Updating FROM..TO ··· 227 243 228 244 git reset --hard c0 && 229 245 git merge --compact-summary c1 >out && 246 + sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual && 247 + test_cmp expect actual 248 + ' 249 + 250 + test_expect_success 'the same merge with compact summary' ' 251 + cat >expect <<-\EOF && 252 + Updating FROM..TO 253 + Fast-forward 254 + file | 2 +- 255 + other (new) | 9 +++++++++ 256 + 2 files changed, 10 insertions(+), 1 deletion(-) 257 + EOF 258 + 259 + git reset --hard c0 && 260 + git merge --compact-summary c1 >out && 261 + sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual && 262 + test_cmp expect actual 263 + ' 264 + 265 + test_expect_success 'the same merge with merge.stat=compact' ' 266 + cat >expect <<-\EOF && 267 + Updating FROM..TO 268 + Fast-forward 269 + file | 2 +- 270 + other (new) | 9 +++++++++ 271 + 2 files changed, 10 insertions(+), 1 deletion(-) 272 + EOF 273 + 274 + git reset --hard c0 && 275 + git -c merge.stat=compact merge c1 >out && 230 276 sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual && 231 277 test_cmp expect actual 232 278 '