Skip to content

Commit b370468

Browse files
committed
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 <[email protected]>
1 parent 07ec215 commit b370468

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

Documentation/git-range-diff.txt

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SYNOPSIS
99
--------
1010
[verse]
1111
'git range-diff' [--color=[<when>]] [--no-color] [<diff-options>]
12-
[--dual-color] [--creation-factor=<factor>]
12+
[--no-dual-color] [--creation-factor=<factor>]
1313
( <range1> <range2> | <rev1>...<rev2> | <base> <rev1> <rev2> )
1414

1515
DESCRIPTION
@@ -31,11 +31,14 @@ all of their ancestors have been shown.
3131

3232
OPTIONS
3333
-------
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).
3942

4043
--creation-factor=<percent>::
4144
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
118121
show`'s output, and the third line colors the old commit red, the new
119122
one green and the rest like `git show`'s commit header.
120123

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.
125128

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.
130134

131135

132136
Algorithm

builtin/range-diff.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
2020
{
2121
int creation_factor = 60;
2222
struct diff_options diffopt = { NULL };
23-
int dual_color = 0;
23+
int simple_color = -1;
2424
struct option options[] = {
2525
OPT_INTEGER(0, "creation-factor", &creation_factor,
2626
N_("Percentage by which creation is weighted")),
27-
OPT_BOOL(0, "dual-color", &dual_color,
27+
OPT_BOOL(0, "no-dual-color", &simple_color,
2828
N_("color both diff and diff-between-diffs")),
2929
OPT_END()
3030
};
@@ -55,8 +55,10 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
5555
argc = j;
5656
diff_setup_done(&diffopt);
5757

58-
if (dual_color) {
59-
diffopt.use_color = 1;
58+
if (simple_color < 1) {
59+
if (!simple_color)
60+
/* force color when --dual-color was used */
61+
diffopt.use_color = 1;
6062
diffopt.flags.dual_color_diffed_diffs = 1;
6163
}
6264

contrib/completion/git-completion.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1981,7 +1981,7 @@ _git_range_diff ()
19811981
case "$cur" in
19821982
--*)
19831983
__gitcomp "
1984-
--creation-factor= --dual-color
1984+
--creation-factor= --no-dual-color
19851985
$__git_diff_common_options
19861986
"
19871987
return

0 commit comments

Comments
 (0)