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>
This commit is contained in:

committed by
Junio C Hamano

parent
cbd64afbb3
commit
ce43697379
28
diff.c
28
diff.c
@ -17,15 +17,6 @@ static int diff_detect_rename_default = 0;
|
|||||||
static int diff_rename_limit_default = -1;
|
static int diff_rename_limit_default = -1;
|
||||||
static int diff_use_color_default = 0;
|
static int diff_use_color_default = 0;
|
||||||
|
|
||||||
enum color_diff {
|
|
||||||
DIFF_RESET = 0,
|
|
||||||
DIFF_PLAIN = 1,
|
|
||||||
DIFF_METAINFO = 2,
|
|
||||||
DIFF_FRAGINFO = 3,
|
|
||||||
DIFF_FILE_OLD = 4,
|
|
||||||
DIFF_FILE_NEW = 5,
|
|
||||||
};
|
|
||||||
|
|
||||||
/* "\033[1;38;5;2xx;48;5;2xxm\0" is 23 bytes */
|
/* "\033[1;38;5;2xx;48;5;2xxm\0" is 23 bytes */
|
||||||
static char diff_colors[][24] = {
|
static char diff_colors[][24] = {
|
||||||
"\033[m", /* reset */
|
"\033[m", /* reset */
|
||||||
@ -33,7 +24,8 @@ static char diff_colors[][24] = {
|
|||||||
"\033[1m", /* bold */
|
"\033[1m", /* bold */
|
||||||
"\033[36m", /* cyan */
|
"\033[36m", /* cyan */
|
||||||
"\033[31m", /* red */
|
"\033[31m", /* red */
|
||||||
"\033[32m" /* green */
|
"\033[32m", /* green */
|
||||||
|
"\033[33m" /* yellow */
|
||||||
};
|
};
|
||||||
|
|
||||||
static int parse_diff_color_slot(const char *var, int ofs)
|
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)
|
|||||||
return DIFF_FILE_OLD;
|
return DIFF_FILE_OLD;
|
||||||
if (!strcasecmp(var+ofs, "new"))
|
if (!strcasecmp(var+ofs, "new"))
|
||||||
return DIFF_FILE_NEW;
|
return DIFF_FILE_NEW;
|
||||||
|
if (!strcasecmp(var+ofs, "commit"))
|
||||||
|
return DIFF_COMMIT;
|
||||||
die("bad config variable '%s'", var);
|
die("bad config variable '%s'", var);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,7 +364,7 @@ struct emit_callback {
|
|||||||
const char **label_path;
|
const char **label_path;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline const char *get_color(int diff_use_color, enum color_diff ix)
|
const char *diff_get_color(int diff_use_color, enum color_diff ix)
|
||||||
{
|
{
|
||||||
if (diff_use_color)
|
if (diff_use_color)
|
||||||
return diff_colors[ix];
|
return diff_colors[ix];
|
||||||
@ -381,8 +375,8 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct emit_callback *ecbdata = priv;
|
struct emit_callback *ecbdata = priv;
|
||||||
const char *set = get_color(ecbdata->color_diff, DIFF_METAINFO);
|
const char *set = diff_get_color(ecbdata->color_diff, DIFF_METAINFO);
|
||||||
const char *reset = get_color(ecbdata->color_diff, DIFF_RESET);
|
const char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);
|
||||||
|
|
||||||
if (ecbdata->label_path[0]) {
|
if (ecbdata->label_path[0]) {
|
||||||
printf("%s--- %s%s\n", set, ecbdata->label_path[0], reset);
|
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)
|
|||||||
;
|
;
|
||||||
if (2 <= i && i < len && line[i] == ' ') {
|
if (2 <= i && i < len && line[i] == ' ') {
|
||||||
ecbdata->nparents = i - 1;
|
ecbdata->nparents = i - 1;
|
||||||
set = get_color(ecbdata->color_diff, DIFF_FRAGINFO);
|
set = diff_get_color(ecbdata->color_diff, DIFF_FRAGINFO);
|
||||||
}
|
}
|
||||||
else if (len < ecbdata->nparents)
|
else if (len < ecbdata->nparents)
|
||||||
set = reset;
|
set = reset;
|
||||||
@ -410,7 +404,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
|
|||||||
else if (line[i] == '+')
|
else if (line[i] == '+')
|
||||||
color = DIFF_FILE_NEW;
|
color = DIFF_FILE_NEW;
|
||||||
}
|
}
|
||||||
set = get_color(ecbdata->color_diff, color);
|
set = diff_get_color(ecbdata->color_diff, color);
|
||||||
}
|
}
|
||||||
if (len > 0 && line[len-1] == '\n')
|
if (len > 0 && line[len-1] == '\n')
|
||||||
len--;
|
len--;
|
||||||
@ -767,8 +761,8 @@ static void builtin_diff(const char *name_a,
|
|||||||
mmfile_t mf1, mf2;
|
mmfile_t mf1, mf2;
|
||||||
const char *lbl[2];
|
const char *lbl[2];
|
||||||
char *a_one, *b_two;
|
char *a_one, *b_two;
|
||||||
const char *set = get_color(o->color_diff, DIFF_METAINFO);
|
const char *set = diff_get_color(o->color_diff, DIFF_METAINFO);
|
||||||
const char *reset = get_color(o->color_diff, DIFF_RESET);
|
const char *reset = diff_get_color(o->color_diff, DIFF_RESET);
|
||||||
|
|
||||||
a_one = quote_two("a/", name_a);
|
a_one = quote_two("a/", name_a);
|
||||||
b_two = quote_two("b/", name_b);
|
b_two = quote_two("b/", name_b);
|
||||||
|
11
diff.h
11
diff.h
@ -69,6 +69,17 @@ struct diff_options {
|
|||||||
add_remove_fn_t add_remove;
|
add_remove_fn_t add_remove;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum color_diff {
|
||||||
|
DIFF_RESET = 0,
|
||||||
|
DIFF_PLAIN = 1,
|
||||||
|
DIFF_METAINFO = 2,
|
||||||
|
DIFF_FRAGINFO = 3,
|
||||||
|
DIFF_FILE_OLD = 4,
|
||||||
|
DIFF_FILE_NEW = 5,
|
||||||
|
DIFF_COMMIT = 6,
|
||||||
|
};
|
||||||
|
const char *diff_get_color(int diff_use_color, enum color_diff ix);
|
||||||
|
|
||||||
extern const char mime_boundary_leader[];
|
extern const char mime_boundary_leader[];
|
||||||
|
|
||||||
extern void diff_tree_setup_paths(const char **paths, struct diff_options *);
|
extern void diff_tree_setup_paths(const char **paths, struct diff_options *);
|
||||||
|
@ -129,7 +129,8 @@ void show_log(struct rev_info *opt, const char *sep)
|
|||||||
opt->diffopt.stat_sep = buffer;
|
opt->diffopt.stat_sep = buffer;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("%s%s",
|
printf("%s%s%s",
|
||||||
|
diff_get_color(opt->diffopt.color_diff, DIFF_COMMIT),
|
||||||
opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ",
|
opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ",
|
||||||
diff_unique_abbrev(commit->object.sha1, abbrev_commit));
|
diff_unique_abbrev(commit->object.sha1, abbrev_commit));
|
||||||
if (opt->parents)
|
if (opt->parents)
|
||||||
@ -139,6 +140,8 @@ void show_log(struct rev_info *opt, const char *sep)
|
|||||||
diff_unique_abbrev(parent->object.sha1,
|
diff_unique_abbrev(parent->object.sha1,
|
||||||
abbrev_commit));
|
abbrev_commit));
|
||||||
putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n');
|
putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n');
|
||||||
|
printf("%s",
|
||||||
|
diff_get_color(opt->diffopt.color_diff, DIFF_RESET));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user