range-diff: make --dual-color the default mode

After using this command extensively for the last two months, this developer came to the conclusion that even if the dual color mode still leaves a lot of room for confusion about what was actually changed, the non-dual color mode is substantially worse in that regard. Therefore, we really want to make the dual color mode the default. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Aug 13, 2018 at 04:33 UTC 275267937bdbb8611e8872d64adebe7587c6fa5a
3 files changed +25 -19
Documentation/git-range-diff.txt
+18 -14
@@ -9,7 +9,7 @@ SYNOPSIS
9 --------
10 [verse]
11 'git range-diff' [--color=[<when>]] [--no-color] [<diff-options>]
12 - [--dual-color] [--creation-factor=<factor>]
12 + [--no-dual-color] [--creation-factor=<factor>]
13 ( <range1> <range2> | <rev1>...<rev2> | <base> <rev1> <rev2> )
14
15 DESCRIPTION
@@ -31,11 +31,14 @@ all of their ancestors have been shown.
31
32 OPTIONS
33 -------
34 ---dual-color::
35 - When the commit diffs differ, recreate the original diffs'
36 - coloring, and add outer -/+ diff markers with the *background*
37 - being red/green to make it easier to see e.g. when there was a
38 - change in what exact lines were added.
34 +--no-dual-color::
35 + When the commit diffs differ, `git range-diff` recreates the
36 + original diffs' coloring, and adds outer -/+ diff markers with
37 + the *background* being red/green to make it easier to see e.g.
38 + when there was a change in what exact lines were added. This is
39 + known to `range-diff` as "dual coloring". Use `--no-dual-color`
40 + to revert to color all lines according to the outer diff markers
41 + (and completely ignore the inner diff when it comes to color).
42
43 --creation-factor=<percent>::
44 Set the creation/deletion cost fudge factor to `<percent>`.
@@ -118,15 +121,16 @@ line (with a perfect match) is yellow like the commit header of `git
121 show`'s output, and the third line colors the old commit red, the new
122 one green and the rest like `git show`'s commit header.
123
121 -The color-coded diff is actually a bit hard to read, though, as it
122 -colors the entire lines red or green. The line that added "What is
123 -unexpected" in the old commit, for example, is completely red, even if
124 -the intent of the old commit was to add something.
124 +A naive color-coded diff of diffs is actually a bit hard to read,
125 +though, as it colors the entire lines red or green. The line that added
126 +"What is unexpected" in the old commit, for example, is completely red,
127 +even if the intent of the old commit was to add something.
128
126 -To help with that, use the `--dual-color` mode. In this mode, the diff
127 -of diffs will retain the original diff colors, and prefix the lines with
128 --/+ markers that have their *background* red or green, to make it more
129 -obvious that they describe how the diff itself changed.
129 +To help with that, `range` uses the `--dual-color` mode by default. In
130 +this mode, the diff of diffs will retain the original diff colors, and
131 +prefix the lines with -/+ markers that have their *background* red or
132 +green, to make it more obvious that they describe how the diff itself
133 +changed.
134
135
136 Algorithm
builtin/range-diff.c
+6 -4
@@ -20,11 +20,11 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
20 {
21 int creation_factor = 60;
22 struct diff_options diffopt = { NULL };
23 - int dual_color = 0;
23 + int simple_color = -1;
24 struct option options[] = {
25 OPT_INTEGER(0, "creation-factor", &creation_factor,
26 N_("Percentage by which creation is weighted")),
27 - OPT_BOOL(0, "dual-color", &dual_color,
27 + OPT_BOOL(0, "no-dual-color", &simple_color,
28 N_("color both diff and diff-between-diffs")),
29 OPT_END()
30 };
@@ -63,8 +63,10 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
63 options + ARRAY_SIZE(options) - 1, /* OPT_END */
64 builtin_range_diff_usage, 0);
65
66 - if (dual_color) {
67 - diffopt.use_color = 1;
66 + if (simple_color < 1) {
67 + if (!simple_color)
68 + /* force color when --dual-color was used */
69 + diffopt.use_color = 1;
70 diffopt.flags.dual_color_diffed_diffs = 1;
71 }
72
contrib/completion/git-completion.bash
+1 -1
@@ -1981,7 +1981,7 @@ _git_range_diff ()
1981 case "$cur" in
1982 --*)
1983 __gitcomp "
1984 - --creation-factor= --dual-color
1984 + --creation-factor= --no-dual-color
1985 $__git_diff_common_options
1986 "
1987 return