Colorize 'commit' lines in log ui
When paging through the output of git-whatchanged, the color cues help to visually navigate within a diff. However, it is difficult to notice when a new commit starts, because the commit and log are shown in the "normal" color. This patch colorizes the 'commit' line, customizable through diff.colors.commit and defaulting to yellow. As a side effect, some of the diff color engine (slot enum, get_color) has become accessible outside of diff.c. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
Jeff King committed
Jul 23, 2006 at 05:24 UTC
ce43697379ad8ffcaf061a4709489728c1dbe911
3 files changed
+26
-18
diff.c
+11
-17
@@ -17,15 +17,6 @@ static int diff_detect_rename_default = 0;
17
static int diff_rename_limit_default = -1;
18
static int diff_use_color_default = 0;
19
20
-enum color_diff {
21
- DIFF_RESET = 0,
22
- DIFF_PLAIN = 1,
23
- DIFF_METAINFO = 2,
24
- DIFF_FRAGINFO = 3,
25
- DIFF_FILE_OLD = 4,
26
- DIFF_FILE_NEW = 5,
27
-};
28
-
20
/* "\033[1;38;5;2xx;48;5;2xxm\0" is 23 bytes */
21
static char diff_colors[][24] = {
22
"\033[m", /* reset */
@@ -33,7 +24,8 @@ static char diff_colors[][24] = {
24
"\033[1m", /* bold */
25
"\033[36m", /* cyan */
26
"\033[31m", /* red */
36
- "\033[32m" /* green */
27
+ "\033[32m", /* green */
28
+ "\033[33m" /* yellow */
29
};
30
31
static int parse_diff_color_slot(const char *var, int ofs)
@@ -48,6 +40,8 @@ static int parse_diff_color_slot(const char *var, int ofs)
40
return DIFF_FILE_OLD;
41
if (!strcasecmp(var+ofs, "new"))
42
return DIFF_FILE_NEW;
43
+ if (!strcasecmp(var+ofs, "commit"))
44
+ return DIFF_COMMIT;
45
die("bad config variable '%s'", var);
46
}
47
@@ -370,7 +364,7 @@ struct emit_callback {
364
const char **label_path;
365
};
366
373
-static inline const char *get_color(int diff_use_color, enum color_diff ix)
367
+const char *diff_get_color(int diff_use_color, enum color_diff ix)
368
{
369
if (diff_use_color)
370
return diff_colors[ix];
@@ -381,8 +375,8 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
375
{
376
int i;
377
struct emit_callback *ecbdata = priv;
384
- const char *set = get_color(ecbdata->color_diff, DIFF_METAINFO);
385
- const char *reset = get_color(ecbdata->color_diff, DIFF_RESET);
378
+ const char *set = diff_get_color(ecbdata->color_diff, DIFF_METAINFO);
379
+ const char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);
380
381
if (ecbdata->label_path[0]) {
382
printf("%s--- %s%s\n", set, ecbdata->label_path[0], reset);
@@ -397,7 +391,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
391
;
392
if (2 <= i && i < len && line[i] == ' ') {
393
ecbdata->nparents = i - 1;
400
- set = get_color(ecbdata->color_diff, DIFF_FRAGINFO);
394
+ set = diff_get_color(ecbdata->color_diff, DIFF_FRAGINFO);
395
}
396
else if (len < ecbdata->nparents)
397
set = reset;
@@ -410,7 +404,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
404
else if (line[i] == '+')
405
color = DIFF_FILE_NEW;
406
}
413
- set = get_color(ecbdata->color_diff, color);
407
+ set = diff_get_color(ecbdata->color_diff, color);
408
}
409
if (len > 0 && line[len-1] == '\n')
410
len--;
@@ -767,8 +761,8 @@ static void builtin_diff(const char *name_a,
761
mmfile_t mf1, mf2;
762
const char *lbl[2];
763
char *a_one, *b_two;
770
- const char *set = get_color(o->color_diff, DIFF_METAINFO);
771
- const char *reset = get_color(o->color_diff, DIFF_RESET);
764
+ const char *set = diff_get_color(o->color_diff, DIFF_METAINFO);
765
+ const char *reset = diff_get_color(o->color_diff, DIFF_RESET);
766
767
a_one = quote_two("a/", name_a);
768
b_two = quote_two("b/", name_b);
diff.h
+11
@@ -69,6 +69,17 @@ struct diff_options {
69
add_remove_fn_t add_remove;
70
};
71
72
+enum color_diff {
73
+ DIFF_RESET = 0,
74
+ DIFF_PLAIN = 1,
75
+ DIFF_METAINFO = 2,
76
+ DIFF_FRAGINFO = 3,
77
+ DIFF_FILE_OLD = 4,
78
+ DIFF_FILE_NEW = 5,
79
+ DIFF_COMMIT = 6,
80
+};
81
+const char *diff_get_color(int diff_use_color, enum color_diff ix);
82
+
83
extern const char mime_boundary_leader[];
84
85
extern void diff_tree_setup_paths(const char **paths, struct diff_options *);
log-tree.c
+4
-1
@@ -129,7 +129,8 @@ void show_log(struct rev_info *opt, const char *sep)
129
opt->diffopt.stat_sep = buffer;
130
}
131
} else {
132
- printf("%s%s",
132
+ printf("%s%s%s",
133
+ diff_get_color(opt->diffopt.color_diff, DIFF_COMMIT),
134
opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ",
135
diff_unique_abbrev(commit->object.sha1, abbrev_commit));
136
if (opt->parents)
@@ -139,6 +140,8 @@ void show_log(struct rev_info *opt, const char *sep)
140
diff_unique_abbrev(parent->object.sha1,
141
abbrev_commit));
142
putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n');
143
+ printf("%s",
144
+ diff_get_color(opt->diffopt.color_diff, DIFF_RESET));
145
}
146
147
/*