Skip to content

Commit b6c4058

Browse files
committed
Merge branch 'sb/diff-color-move'
"git diff" has been taught to optionally paint new lines that are the same as deleted lines elsewhere differently from genuinely new lines. * sb/diff-color-move: (25 commits) diff: document the new --color-moved setting diff.c: add dimming to moved line detection diff.c: color moved lines differently, plain mode diff.c: color moved lines differently diff.c: buffer all output if asked to diff.c: emit_diff_symbol learns about DIFF_SYMBOL_SUMMARY diff.c: emit_diff_symbol learns about DIFF_SYMBOL_STAT_SEP diff.c: convert word diffing to use emit_diff_symbol diff.c: convert show_stats to use emit_diff_symbol diff.c: convert emit_binary_diff_body to use emit_diff_symbol submodule.c: migrate diff output to use emit_diff_symbol diff.c: emit_diff_symbol learns DIFF_SYMBOL_REWRITE_DIFF diff.c: emit_diff_symbol learns about DIFF_SYMBOL_BINARY_FILES diff.c: emit_diff_symbol learns DIFF_SYMBOL_HEADER diff.c: emit_diff_symbol learns DIFF_SYMBOL_FILEPAIR_{PLUS, MINUS} diff.c: emit_diff_symbol learns DIFF_SYMBOL_CONTEXT_INCOMPLETE diff.c: emit_diff_symbol learns DIFF_SYMBOL_WORDS[_PORCELAIN] diff.c: migrate emit_line_checked to use emit_diff_symbol diff.c: emit_diff_symbol learns DIFF_SYMBOL_NO_LF_EOF diff.c: emit_diff_symbol learns DIFF_SYMBOL_CONTEXT_FRAGINFO ...
2 parents 3dc57eb + 61e89ea commit b6c4058

File tree

9 files changed

+1618
-316
lines changed

9 files changed

+1618
-316
lines changed

Documentation/config.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,14 +1077,25 @@ This does not affect linkgit:git-format-patch[1] or the
10771077
'git-diff-{asterisk}' plumbing commands. Can be overridden on the
10781078
command line with the `--color[=<when>]` option.
10791079

1080+
diff.colorMoved::
1081+
If set to either a valid `<mode>` or a true value, moved lines
1082+
in a diff are colored differently, for details of valid modes
1083+
see '--color-moved' in linkgit:git-diff[1]. If simply set to
1084+
true the default color mode will be used. When set to false,
1085+
moved lines are not colored.
1086+
10801087
color.diff.<slot>::
10811088
Use customized color for diff colorization. `<slot>` specifies
10821089
which part of the patch to use the specified color, and is one
10831090
of `context` (context text - `plain` is a historical synonym),
10841091
`meta` (metainformation), `frag`
10851092
(hunk header), 'func' (function in hunk header), `old` (removed lines),
1086-
`new` (added lines), `commit` (commit headers), or `whitespace`
1087-
(highlighting whitespace errors).
1093+
`new` (added lines), `commit` (commit headers), `whitespace`
1094+
(highlighting whitespace errors), `oldMoved` (deleted lines),
1095+
`newMoved` (added lines), `oldMovedDimmed`, `oldMovedAlternative`,
1096+
`oldMovedAlternativeDimmed`, `newMovedDimmed`, `newMovedAlternative`
1097+
and `newMovedAlternativeDimmed` (See the '<mode>'
1098+
setting of '--color-moved' in linkgit:git-diff[1] for details).
10881099

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

Documentation/diff-options.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,42 @@ ifdef::git-diff[]
231231
endif::git-diff[]
232232
It is the same as `--color=never`.
233233

234+
--color-moved[=<mode>]::
235+
Moved lines of code are colored differently.
236+
ifdef::git-diff[]
237+
It can be changed by the `diff.colorMoved` configuration setting.
238+
endif::git-diff[]
239+
The <mode> defaults to 'no' if the option is not given
240+
and to 'zebra' if the option with no mode is given.
241+
The mode must be one of:
242+
+
243+
--
244+
no::
245+
Moved lines are not highlighted.
246+
default::
247+
Is a synonym for `zebra`. This may change to a more sensible mode
248+
in the future.
249+
plain::
250+
Any line that is added in one location and was removed
251+
in another location will be colored with 'color.diff.newMoved'.
252+
Similarly 'color.diff.oldMoved' will be used for removed lines
253+
that are added somewhere else in the diff. This mode picks up any
254+
moved line, but it is not very useful in a review to determine
255+
if a block of code was moved without permutation.
256+
zebra::
257+
Blocks of moved code are detected greedily. The detected blocks are
258+
painted using either the 'color.diff.{old,new}Moved' color or
259+
'color.diff.{old,new}MovedAlternative'. The change between
260+
the two colors indicates that a new block was detected. If there
261+
are fewer than 3 adjacent moved lines, they are not marked up
262+
as moved, but the regular colors 'color.diff.{old,new}' will be
263+
used.
264+
dimmed_zebra::
265+
Similar to 'zebra', but additional dimming of uninteresting parts
266+
of moved code is performed. The bordering lines of two adjacent
267+
blocks are considered interesting, the rest is uninteresting.
268+
--
269+
234270
--word-diff[=<mode>]::
235271
Show a word diff, using the <mode> to delimit changed words.
236272
By default, words are delimited by whitespace; see

cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,6 +1955,8 @@ void shift_tree_by(const struct object_id *, const struct object_id *, struct ob
19551955
#define WS_TRAILING_SPACE (WS_BLANK_AT_EOL|WS_BLANK_AT_EOF)
19561956
#define WS_DEFAULT_RULE (WS_TRAILING_SPACE|WS_SPACE_BEFORE_TAB|8)
19571957
#define WS_TAB_WIDTH_MASK 077
1958+
/* All WS_* -- when extended, adapt diff.c emit_symbol */
1959+
#define WS_RULE_MASK 07777
19581960
extern unsigned whitespace_rule_cfg;
19591961
extern unsigned whitespace_rule(const char *);
19601962
extern unsigned parse_whitespace_rule(const char *);

color.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ struct strbuf;
4242
#define GIT_COLOR_BG_BLUE "\033[44m"
4343
#define GIT_COLOR_BG_MAGENTA "\033[45m"
4444
#define GIT_COLOR_BG_CYAN "\033[46m"
45+
#define GIT_COLOR_FAINT "\033[2m"
46+
#define GIT_COLOR_FAINT_ITALIC "\033[2;3m"
4547

4648
/* A special value meaning "no color selected" */
4749
#define GIT_COLOR_NIL "NIL"

0 commit comments

Comments
 (0)