diff-merges: introduce log.diffMerges config variable

New log.diffMerges configuration variable sets the format that --diff-merges=on will be using. The default is "separate". t4013: add the following tests for log.diffMerges config: * Test that wrong values are denied. * Test that the value of log.diffMerges properly affects both --diff-merges=on and -m. t9902: fix completion tests for log.d* to match log.diffMerges. Added documentation for log.diffMerges. Signed-off-by: Sergey Organov <sorganov@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Sergey Organov committed Apr 13, 2021 at 14:41 UTC 17c13e60fd799336b28d320dcba06fe1ef06e01d
6 files changed +46
Documentation/config/log.txt
+5
@@ -24,6 +24,11 @@ log.excludeDecoration::
24 the config option can be overridden by the `--decorate-refs`
25 option.
26
27 +log.diffMerges::
28 + Set default diff format to be used for merge commits. See
29 + `--diff-merges` in linkgit:git-log[1] for details.
30 + Defaults to `separate`.
31 +
32 log.follow::
33 If `true`, `git log` will act as if the `--follow` option was used when
34 a single <path> is given. This has the same limitations as `--follow`,
builtin/log.c
+2
@@ -481,6 +481,8 @@ static int git_log_config(const char *var, const char *value, void *cb)
481 decoration_style = 0; /* maybe warn? */
482 return 0;
483 }
484 + if (!strcmp(var, "log.diffmerges"))
485 + return diff_merges_config(value);
486 if (!strcmp(var, "log.showroot")) {
487 default_show_root = git_config_bool(var, value);
488 return 0;
diff-merges.c
+11
@@ -90,6 +90,17 @@ static void set_diff_merges(struct rev_info *revs, const char *optarg)
90 * Public functions. They are in the order they are called.
91 */
92
93 +int diff_merges_config(const char *value)
94 +{
95 + diff_merges_setup_func_t func = func_by_opt(value);
96 +
97 + if (!func)
98 + return -1;
99 +
100 + set_to_default = func;
101 + return 0;
102 +}
103 +
104 int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
105 {
106 int argcount = 1;
diff-merges.h
+2
@@ -9,6 +9,8 @@
9
10 struct rev_info;
11
12 +int diff_merges_config(const char *value);
13 +
14 int diff_merges_parse_opts(struct rev_info *revs, const char **argv);
15
16 void diff_merges_suppress(struct rev_info *revs);
t/t4013-diff-various.sh
+23
@@ -460,6 +460,29 @@ test_expect_success 'log --diff-merges=on matches --diff-merges=separate' '
460 test_cmp expected actual
461 '
462
463 +test_expect_success 'deny wrong log.diffMerges config' '
464 + test_config log.diffMerges wrong-value &&
465 + test_expect_code 128 git log
466 +'
467 +
468 +test_expect_success 'git config log.diffMerges first-parent' '
469 + git log -p --diff-merges=first-parent master >result &&
470 + process_diffs result >expected &&
471 + test_config log.diffMerges first-parent &&
472 + git log -p --diff-merges=on master >result &&
473 + process_diffs result >actual &&
474 + test_cmp expected actual
475 +'
476 +
477 +test_expect_success 'git config log.diffMerges first-parent vs -m' '
478 + git log -p --diff-merges=first-parent master >result &&
479 + process_diffs result >expected &&
480 + test_config log.diffMerges first-parent &&
481 + git log -p -m master >result &&
482 + process_diffs result >actual &&
483 + test_cmp expected actual
484 +'
485 +
486 test_expect_success 'log -S requires an argument' '
487 test_must_fail git log -S
488 '
t/t9902-completion.sh
+3
@@ -2306,6 +2306,7 @@ test_expect_success 'git config - variable name' '
2306 test_completion "git config log.d" <<-\EOF
2307 log.date Z
2308 log.decorate Z
2309 + log.diffMerges Z
2310 EOF
2311 '
2312
@@ -2327,6 +2328,7 @@ test_expect_success 'git -c - variable name' '
2328 test_completion "git -c log.d" <<-\EOF
2329 log.date=Z
2330 log.decorate=Z
2331 + log.diffMerges=Z
2332 EOF
2333 '
2334
@@ -2348,6 +2350,7 @@ test_expect_success 'git clone --config= - variable name' '
2350 test_completion "git clone --config=log.d" <<-\EOF
2351 log.date=Z
2352 log.decorate=Z
2353 + log.diffMerges=Z
2354 EOF
2355 '
2356