Skip to content

Commit 5e11bee

Browse files
nazrigitster
authored andcommitted
Allow customizable commit decorations colors
Signed-off-by: Nazri Ramliy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 67a4b58 commit 5e11bee

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

Documentation/config.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,11 @@ color.diff.<slot>::
683683
(highlighting whitespace errors). The values of these variables may be
684684
specified as in color.branch.<slot>.
685685

686+
color.decorate.<slot>::
687+
Use customized color for 'git log --decorate' output. `<slot>` is one
688+
of `branch`, `remoteBranch`, `tag`, `stash` or `HEAD` for local
689+
branches, remote tracking branches, tags, stash and HEAD, respectively.
690+
686691
color.grep::
687692
When set to `always`, always highlight matches. When `false` (or
688693
`never`), never. When set to `true` or `auto`, use color only

builtin/log.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ static int git_log_config(const char *var, const char *value, void *cb)
296296
default_show_root = git_config_bool(var, value);
297297
return 0;
298298
}
299+
if (!prefixcmp(var, "color.decorate."))
300+
return parse_decorate_color_config(var, 15, value);
301+
299302
return git_diff_ui_config(var, value, cb);
300303
}
301304

log-tree.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,42 @@ static const char *decorate_get_color(int decorate_use_color, enum decoration_ty
3636
return "";
3737
}
3838

39+
static int parse_decorate_color_slot(const char *slot)
40+
{
41+
/*
42+
* We're comparing with 'ignore-case' on
43+
* (because config.c sets them all tolower),
44+
* but let's match the letters in the literal
45+
* string values here with how they are
46+
* documented in Documentation/config.txt, for
47+
* consistency.
48+
*
49+
* We love being consistent, don't we?
50+
*/
51+
if (!strcasecmp(slot, "branch"))
52+
return DECORATION_REF_LOCAL;
53+
if (!strcasecmp(slot, "remoteBranch"))
54+
return DECORATION_REF_REMOTE;
55+
if (!strcasecmp(slot, "tag"))
56+
return DECORATION_REF_TAG;
57+
if (!strcasecmp(slot, "stash"))
58+
return DECORATION_REF_STASH;
59+
if (!strcasecmp(slot, "HEAD"))
60+
return DECORATION_REF_HEAD;
61+
return -1;
62+
}
63+
64+
int parse_decorate_color_config(const char *var, const int ofs, const char *value)
65+
{
66+
int slot = parse_decorate_color_slot(var + ofs);
67+
if (slot < 0)
68+
return 0;
69+
if (!value)
70+
return config_error_nonbool(var);
71+
color_parse(value, var, decoration_colors[slot]);
72+
return 0;
73+
}
74+
3975
/*
4076
* log-tree.c uses DIFF_OPT_TST for determining whether to use color
4177
* for showing the commit sha1, use the same check for --decorate

log-tree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ struct log_info {
77
struct commit *commit, *parent;
88
};
99

10+
int parse_decorate_color_config(const char *var, const int ofs, const char *value);
1011
void init_log_tree_opt(struct rev_info *);
1112
int log_tree_diff_flush(struct rev_info *);
1213
int log_tree_commit(struct rev_info *, struct commit *);

0 commit comments

Comments
 (0)