Skip to content

Commit a7be92a

Browse files
dschogitster
authored andcommitted
range-diff: use dim/bold cues to improve dual color mode
It *is* a confusing thing to look at a diff of diffs. All too easy is it to mix up whether the -/+ markers refer to the "inner" or the "outer" diff, i.e. whether a `+` indicates that a line was added by either the old or the new diff (or both), or whether the new diff does something different than the old diff. To make things easier to process for normal developers, we introduced the dual color mode which colors the lines according to the commit diff, i.e. lines that are added by a commit (whether old, new, or both) are colored in green. In non-dual color mode, the lines would be colored according to the outer diff: if the old commit added a line, it would be colored red (because that line addition is only present in the first commit range that was specified on the command-line, i.e. the "old" commit, but not in the second commit range, i.e. the "new" commit). However, this dual color mode is still not making things clear enough, as we are looking at two levels of diffs, and we still only pick a color according to *one* of them (the outer diff marker is colored differently, of course, but in particular with deep indentation, it is easy to lose track of that outer diff marker's background color). Therefore, let's add another dimension to the mix. Still use green/red/normal according to the commit diffs, but now also dim the lines that were only in the old commit, and use bold face for the lines that are only in the new commit. That way, it is much easier not to lose track of, say, when we are looking at a line that was added in the previous iteration of a patch series but the new iteration adds a slightly different version: the obsolete change will be dimmed, the current version of the patch will be bold. At least this developer has a much easier time reading the range-diffs that way. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2752679 commit a7be92a

File tree

5 files changed

+52
-13
lines changed

5 files changed

+52
-13
lines changed

Diff for: Documentation/config.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -1193,8 +1193,10 @@ color.diff.<slot>::
11931193
(highlighting whitespace errors), `oldMoved` (deleted lines),
11941194
`newMoved` (added lines), `oldMovedDimmed`, `oldMovedAlternative`,
11951195
`oldMovedAlternativeDimmed`, `newMovedDimmed`, `newMovedAlternative`
1196-
and `newMovedAlternativeDimmed` (See the '<mode>'
1197-
setting of '--color-moved' in linkgit:git-diff[1] for details).
1196+
`newMovedAlternativeDimmed` (See the '<mode>'
1197+
setting of '--color-moved' in linkgit:git-diff[1] for details),
1198+
`contextDimmed`, `oldDimmed`, `newDimmed`, `contextBold`,
1199+
`oldBold`, and `newBold` (see linkgit:git-range-diff[1] for details).
11981200

11991201
color.decorate.<slot>::
12001202
Use customized color for 'git log --decorate' output. `<slot>` is one

Diff for: Documentation/git-range-diff.txt

+13-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,19 @@ OPTIONS
3535
When the commit diffs differ, `git range-diff` recreates the
3636
original diffs' coloring, and adds outer -/+ diff markers with
3737
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).
38+
when there was a change in what exact lines were added.
39+
+
40+
Additionally, the commit diff lines that are only present in the first commit
41+
range are shown "dimmed" (this can be overridden using the `color.diff.<slot>`
42+
config setting where `<slot>` is one of `contextDimmed`, `oldDimmed` and
43+
`newDimmed`), and the commit diff lines that are only present in the second
44+
commit range are shown in bold (which can be overridden using the config
45+
settings `color.diff.<slot>` with `<slot>` being one of `contextBold`,
46+
`oldBold` or `newBold`).
47+
+
48+
This is known to `range-diff` as "dual coloring". Use `--no-dual-color`
49+
to revert to color all lines according to the outer diff markers
50+
(and completely ignore the inner diff when it comes to color).
4251

4352
--creation-factor=<percent>::
4453
Set the creation/deletion cost fudge factor to `<percent>`.

Diff for: color.h

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ struct strbuf;
3636
#define GIT_COLOR_BOLD_BLUE "\033[1;34m"
3737
#define GIT_COLOR_BOLD_MAGENTA "\033[1;35m"
3838
#define GIT_COLOR_BOLD_CYAN "\033[1;36m"
39+
#define GIT_COLOR_FAINT_RED "\033[2;31m"
40+
#define GIT_COLOR_FAINT_GREEN "\033[2;32m"
41+
#define GIT_COLOR_FAINT_YELLOW "\033[2;33m"
42+
#define GIT_COLOR_FAINT_BLUE "\033[2;34m"
43+
#define GIT_COLOR_FAINT_MAGENTA "\033[2;35m"
44+
#define GIT_COLOR_FAINT_CYAN "\033[2;36m"
3945
#define GIT_COLOR_BG_RED "\033[41m"
4046
#define GIT_COLOR_BG_GREEN "\033[42m"
4147
#define GIT_COLOR_BG_YELLOW "\033[43m"

Diff for: diff.c

+22-6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ static char diff_colors[][COLOR_MAXLEN] = {
7070
GIT_COLOR_BOLD_YELLOW, /* NEW_MOVED ALTERNATIVE */
7171
GIT_COLOR_FAINT, /* NEW_MOVED_DIM */
7272
GIT_COLOR_FAINT_ITALIC, /* NEW_MOVED_ALTERNATIVE_DIM */
73+
GIT_COLOR_FAINT, /* CONTEXT_DIM */
74+
GIT_COLOR_FAINT_RED, /* OLD_DIM */
75+
GIT_COLOR_FAINT_GREEN, /* NEW_DIM */
76+
GIT_COLOR_BOLD, /* CONTEXT_BOLD */
77+
GIT_COLOR_BOLD_RED, /* OLD_BOLD */
78+
GIT_COLOR_BOLD_GREEN, /* NEW_BOLD */
7379
};
7480

7581
static const char *color_diff_slots[] = {
@@ -89,6 +95,12 @@ static const char *color_diff_slots[] = {
8995
[DIFF_FILE_NEW_MOVED_ALT] = "newMovedAlternative",
9096
[DIFF_FILE_NEW_MOVED_DIM] = "newMovedDimmed",
9197
[DIFF_FILE_NEW_MOVED_ALT_DIM] = "newMovedAlternativeDimmed",
98+
[DIFF_CONTEXT_DIM] = "contextDimmed",
99+
[DIFF_FILE_OLD_DIM] = "oldDimmed",
100+
[DIFF_FILE_NEW_DIM] = "newDimmed",
101+
[DIFF_CONTEXT_BOLD] = "contextBold",
102+
[DIFF_FILE_OLD_BOLD] = "oldBold",
103+
[DIFF_FILE_NEW_BOLD] = "newBold",
92104
};
93105

94106
static NORETURN void die_want_option(const char *option_name)
@@ -1294,11 +1306,13 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
12941306

12951307
set_sign = set;
12961308
if (c == '-')
1297-
set = diff_get_color_opt(o, DIFF_FILE_OLD);
1309+
set = diff_get_color_opt(o, DIFF_FILE_OLD_BOLD);
12981310
else if (c == '@')
12991311
set = diff_get_color_opt(o, DIFF_FRAGINFO);
1300-
else if (c != '+')
1301-
set = diff_get_color_opt(o, DIFF_CONTEXT);
1312+
else if (c == '+')
1313+
set = diff_get_color_opt(o, DIFF_FILE_NEW_BOLD);
1314+
else
1315+
set = diff_get_color_opt(o, DIFF_CONTEXT_BOLD);
13021316
flags &= ~DIFF_SYMBOL_CONTENT_WS_MASK;
13031317
}
13041318
emit_line_ws_markup(o, set, reset, line, len, set_sign, '+',
@@ -1336,11 +1350,13 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
13361350

13371351
set_sign = set;
13381352
if (c == '+')
1339-
set = diff_get_color_opt(o, DIFF_FILE_NEW);
1353+
set = diff_get_color_opt(o, DIFF_FILE_NEW_DIM);
13401354
else if (c == '@')
13411355
set = diff_get_color_opt(o, DIFF_FRAGINFO);
1342-
else if (c != '-')
1343-
set = diff_get_color_opt(o, DIFF_CONTEXT);
1356+
else if (c == '-')
1357+
set = diff_get_color_opt(o, DIFF_FILE_OLD_DIM);
1358+
else
1359+
set = diff_get_color_opt(o, DIFF_CONTEXT_DIM);
13441360
}
13451361
emit_line_ws_markup(o, set, reset, line, len, set_sign, '-',
13461362
flags & DIFF_SYMBOL_CONTENT_WS_MASK, 0);

Diff for: diff.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,13 @@ enum color_diff {
248248
DIFF_FILE_NEW_MOVED = 13,
249249
DIFF_FILE_NEW_MOVED_ALT = 14,
250250
DIFF_FILE_NEW_MOVED_DIM = 15,
251-
DIFF_FILE_NEW_MOVED_ALT_DIM = 16
251+
DIFF_FILE_NEW_MOVED_ALT_DIM = 16,
252+
DIFF_CONTEXT_DIM = 17,
253+
DIFF_FILE_OLD_DIM = 18,
254+
DIFF_FILE_NEW_DIM = 19,
255+
DIFF_CONTEXT_BOLD = 20,
256+
DIFF_FILE_OLD_BOLD = 21,
257+
DIFF_FILE_NEW_BOLD = 22,
252258
};
253259
const char *diff_get_color(int diff_use_color, enum color_diff ix);
254260
#define diff_get_color_opt(o, ix) \

0 commit comments

Comments
 (0)