Colorize commit decorations
PATCH 1/1 Colorize commit decorations
Use different color for each type of refs (local, remote, tags, HEAD, and stash). This makes the decorations and their type stand out more and easier to distinguish in 'git log --decorate'.
Currently all the different types of decorations are shown in the same color as the commit id, which is not that easy to spot.
The color applied for each type of refs are customizable via color.log.decorate.<slot> config entry, as documented in Documentation/config.txt.
--- Documentation/config.txt | 5 +++++ builtin/log.c | 2 ++ commit.h | 1 + decorate.c | 42 ++++++++++++++++++++++++++++++++++++++++++ decorate.h | 27 +++++++++++++++++++++++++++ log-tree.c | 39 +++++++++++++++++++++++++++++++-------- 6 files changed, 108 insertions(+), 8 deletions(-)
Documentation/config.txt +5 -0
@@ -725,6 +725,11 @@ color.interactive.<slot>:: commands. The values of these variables may be specified as in color.branch.<slot>. +color.log.decorate.<slot>:: + Use customized color for 'git log --decorate' output. + `<slot>` is one of `local`, `remote`, `tag`, `stash` or `head` + for local refs, remote refs, tags, stash and HEAD, respectively. + color.pager:: A boolean to enable/disable colored output when the pager is in use (default is true).
builtin/log.c +2 -0
@@ -296,6 +296,8 @@ static int git_log_config(const char *var, const char *value, void *cb) default_show_root =git_config_bool (var, value);return 0 ; } +if (!prefixcmp (var,"color.log.decorate." )) +return parse_decorate_color_config (var,19 , value);return git_diff_ui_config (var, value, cb); }
commit.h +1 -0
@@ -28,6 +28,7 @@ extern const char *commit_type;extern struct decoration name_decoration;struct name_decoration {struct name_decoration *next; +enum decoration_type type;char name[1 ]; };
decorate.c +42 -0
48 lines not on this page · raw message
decorate.h +27 -0
@@ -12,6 +12,33 @@ struct decoration {struct object_decoration *hash; }; +enum decoration_type { +DECORATION_NONE =0 , +DECORATION_REF_LOCAL , +DECORATION_REF_REMOTE , +DECORATION_TAG , +DECORATION_STASH , +DECORATION_HEAD +}; + +enum color_decoration { +COLOR_DECORATION_RESET =0 , +COLOR_DECORATION_REF_LOCAL , +COLOR_DECORATION_REF_REMOTE , +COLOR_DECORATION_TAG , +COLOR_DECORATION_STASH , +COLOR_DECORATION_HEAD +}; + +const char *decorate_get_color (int diff_use_color,enum decoration_type ix); + +/* +* log-tree.c uses DIFF_OPT_TST for determining whether to use color +* for showing the commit sha1, use the same check for --decorate +*/ +#define decorate_get_color_opt (o, ix) \ + decorate_get_color(DIFF_OPT_TST((o), COLOR_DIFF), ix) +extern void *add_decoration (struct decoration *n,const struct object *obj,void *decoration);extern void *lookup_decoration (struct decoration *n,const struct object *obj);
log-tree.c +31 -8
@@ -10,29 +10,41 @@struct decoration name_decoration = {"object names" }; -static void add_name_decoration (const char *prefix,const char *name,struct object *obj) +static void add_name_decoration (enum decoration_type type,const char *name,struct object *obj) { -int plen =strlen (prefix);int nlen =strlen (name); -struct name_decoration *res =xmalloc (sizeof (struct name_decoration ) + plen + nlen); -memcpy (res->name, prefix, plen); -memcpy (res->name + plen, name, nlen +1 ); +struct name_decoration *res =xmalloc (sizeof (struct name_decoration ) + nlen); +memcpy (res->name, name, nlen +1 ); + res->type = type; res->next =add_decoration (&name_decoration, obj, res); }static int add_ref_decoration (const char *refname,const unsigned char *sha1,int flags,void *cb_data) {struct object *obj =parse_object (sha1); +enum decoration_type type =DECORATION_NONE ;if (!obj)return 0 ; + +if (!prefixcmp (refname,"refs/heads" )) + type =DECORATION_REF_LOCAL ; +else if (!prefixcmp (refname,"refs/remotes" )) + type =DECORATION_REF_REMOTE ; +else if (!prefixcmp (refname,"refs/tags" )) + type =DECORATION_TAG ; +else if (!prefixcmp (refname,"refs/stash" )) + type =DECORATION_STASH ; +else if (!prefixcmp (refname,"HEAD" )) + type =DECORATION_HEAD ; +if (!cb_data || *(int *)cb_data ==DECORATE_SHORT_REFS ) refname =prettify_refname (refname); -add_name_decoration ("" , refname, obj); +add_name_decoration (type, refname, obj);while (obj->type ==OBJ_TAG ) { obj = ((struct tag *)obj)->tagged;if (!obj)break ; -add_name_decoration ("tag: " , refname, obj); +add_name_decoration (DECORATION_TAG , refname, obj); }return 0 ; }
@@ -60,6 +72,10 @@ void show_decorations(struct rev_info *opt, struct commit *commit) {const char *prefix;struct name_decoration *decoration; +const char *color_commit = +diff_get_color_opt (&opt->diffopt,DIFF_COMMIT ); +const char *color_reset = +decorate_get_color_opt (&opt->diffopt,DECORATION_NONE );if (opt->show_source && commit->util)printf ("\t%s" , (char *) commit->util);
@@ -70,7 +86,14 @@ void show_decorations(struct rev_info *opt, struct commit *commit)return ; prefix =" (" ;while (decoration) { -printf ("%s%s" , prefix, decoration->name); +printf ("%s" , prefix); +fputs (decorate_get_color_opt (&opt->diffopt, decoration->type), + stdout); +if (decoration->type ==DECORATION_TAG ) +fputs ("tag: " , stdout); +printf ("%s" , decoration->name); +fputs (color_reset, stdout); +fputs (color_commit, stdout); prefix =", " ; decoration = decoration->next; }
Signature · 1 line
1.7.1.245.g7c42e.dirty
Quoted 11 lines · Nazri Ramliy
Use different color for each type of refs (local, remote, tags, HEAD, and stash). This makes the decorations and their type stand out more and easier to distinguish in 'git log --decorate'.
Currently all the different types of decorations are shown in the same color as the commit id, which is not that easy to spot.
The color applied for each type of refs are customizable via color.log.decorate.<slot> config entry, as documented in
Documentation/config.txt.
---
Sign-off?
Documentation/config.txt color.interactive.<slot>:: · line 731
Quoted 12 lines
Documentation/config.txt +4
-0@@ -725,6 +725,11 @@ color.interactive.<slot>:: commands. The values of these variables may be specified as in color.branch.<slot>. +color.log.decorate.<slot>:: + Use customized color for 'git log --decorate' output. + `<slot>` is one of `local`, `remote`, `tag`, `stash` or `head` + for local refs, remote refs, tags, stash and HEAD, respectively.
Configuration variable names are either 2-level or 3-level. There are existing examples for <slot> (e.g. color.branch.<slot>).
Quoted 9 lines
decorate.c +1
-0@@ -5,6 +5,48 @@#include "cache.h" #include "object.h" #include "decorate.h" +#include "color.h"
decorate.c line 49
Quoted 10 lines
decorate.c +9
-0+int parse_decorate_color_config (const char *var,const int ofs,const char *value) { +int slot =parse_decorate_color_slot (var + ofs); +if (slot <0 ) +return 0 ; +if (!value) +return config_error_nonbool (var); +color_parse (value, var, decoration_colors[slot]); +return 0 ; +}
I don't think any of the above belongs to "decorate.c", which is the generic mechanism to annotate commits with arbitrary data. The Porcelain feature "log --decorate" is just one user that happens to use refname as that "arbitrary data", and that is what you are coloring. The code for that is in log-tree.c, I think.
decorate.h
Quoted 2 lines
decorate.h +0
-0
So is any change to this file.
Quoted 11 lines
log-tree.c +1
-1@@ -10,29 +10,41 @@struct decoration name_decoration = {"object names" }; -static void add_name_decoration (const char *prefix,const char *name,struct object *obj) +static void add_name_decoration (enum decoration_type type,const char *name,struct object *obj) {
log-tree.c line 20
Quoted 10 lines
log-tree.c +3
-4-int plen =strlen (prefix);int nlen =strlen (name); -struct name_decoration *res =xmalloc (sizeof (struct name_decoration ) + plen + nlen); -memcpy (res->name, prefix, plen); -memcpy (res->name + plen, name, nlen +1 ); +struct name_decoration *res =xmalloc (sizeof (struct name_decoration ) + nlen); +memcpy (res->name, name, nlen +1 ); + res->type = type; res->next =add_decoration (&name_decoration, obj, res); }
When color is not in use (e.g. output is not going to the terminal), you would lose "tag: " prefix, wouldn't you?
Even when color _is_ in use, people may want to see familiar "tag: " prefix in the output---I personally do not think that is necessary, though.
Quoted 7 lines
log-tree.c +2
-0static int add_ref_decoration (const char *refname,const unsigned char *sha1,int flags,void *cb_data) {struct object *obj =parse_object (sha1); +enum decoration_type type =DECORATION_NONE ;if (!obj)return 0 ; +
log-tree.c line 38
Quoted 10 lines
log-tree.c +10
-0+if (!prefixcmp (refname,"refs/heads" )) + type =DECORATION_REF_LOCAL ; +else if (!prefixcmp (refname,"refs/remotes" )) + type =DECORATION_REF_REMOTE ; +else if (!prefixcmp (refname,"refs/tags" )) + type =DECORATION_TAG ; +else if (!prefixcmp (refname,"refs/stash" )) + type =DECORATION_STASH ; +else if (!prefixcmp (refname,"HEAD" )) + type =DECORATION_HEAD ;
I suspect that users would expect DECORATION_HEAD to be used to highlight the object at the tip of the current branch, but I also suspect this code would not do so.
PATCH 1/4 commit.h: add 'type' to struct name_decoration
This allows for semantically better handling of decoration type.
---
I have splitted the patch into four logical commits:
1. commit.h: add 'type' to struct name_decoration
2. log-tree.c: Use struct name_decoration's type for classifying decoration
3. log --decorate: Colorize commit decorations
4. Allow customizable coloring of commit decorations
This should make it easier for you (or anyone else) to spot any problem with my approach in colorizing --decorate stuff.
This is the first commit, and the rest will follow suit.
My reply to your comments are as follows:
Quoted 2 lines · Junio C Hamano
Configuration variable names are either 2-level or 3-level. There are existing examples for <slot> (e.g. color.branch.<slot>).
Fixed. Now the slots are no longer tied to log, and they are named like this:
color.decorate.reflocal
color.decorate.refremote
color.decorate.reftag
color.decorate.refstash
color.decorate.refhead
This should allow for handling different type of decorations in the future.
Quoted 10 lines
I don't think any of the above belongs to "
decorate.c", which is the generic mechanism to annotate commits with arbitrary data. The Porcelain feature "log --decorate" is just one user that happens to use refname as that "arbitrary data", and that is what you are coloring. The code for that is inlog-tree.c, I think.decorate.h
Quoted 2 lines
decorate.h +0
-0So is any change to this file.
Fixed. decorate.[ch] is no longer affected by this series.
Quoted 2 lines
When color is not in use (e.g. output is not going to the terminal), you would lose "tag: " prefix, wouldn't you?
No. The "tag: " prefix is not lost. It will be shown by show_decorations() if the type of the decoration matches DECORATION_REF_TAG.
Quoted 8 lines
decorate.h
Quoted 4 lines
decorate.h +4
-0+else if (!prefixcmp (refname,"refs/stash" )) + type =DECORATION_STASH ; +else if (!prefixcmp (refname,"HEAD" )) + type =DECORATION_HEAD ;I suspect that users would expect
DECORATION_HEADto be used to highlight the object at the tip of the current branch, but I also suspect this code would not do so.
No the code would not do so. It would only colorize the literal printed 'HEAD' string. The current --decorate shows only 'HEAD' for symbolic refs (is this the right term for it?) and nothing else (it seems that way to me, I might be wrong here).
nazri
commit.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
commit.h +1 -0
@@ -28,6 +28,7 @@ extern const char *commit_type;extern struct decoration name_decoration;struct name_decoration {struct name_decoration *next; +int type;char name[1 ]; };
Signature · 1 line
1.7.1.245.g7c42e.dirty
Re: [PATCH 1/4] commit.h: add 'type' to struct name_decoration
Quoted 5 lines · Nazri Ramliy
Now the slots are no longer tied to log, and they are named like this:
color.decorate.reflocal
color.decorate.refremote
Wouldn't "(local) branch" and "remote (tracking) branch" be more natural way to call these things?
Quoted 3 lines
color.decorate.reftag
color.decorate.refstash
color.decorate.refhead
And these would just be "tag", "stash" and "head".
PATCH 1/1 Allow customizable commit decorations colors
---
Quoted 4 lines · Junio C Hamano
Quoted 2 lines · Nazri Ramliy
color.decorate.reflocal
color.decorate.refremote
Quoted 8 lines
Wouldn't "(local) branch" and "remote (tracking) branch" be more natural way to call these things?
Quoted 3 lines
color.decorate.reftag
color.decorate.refstash
color.decorate.refheadAnd these would just be "tag", "stash" and "head".
Makes sense. The names above are not user friendly. The new names are:
color.decorate.branch
color.decorate.remoteBranch
color.decorate.tag
color.decorate.stash
color.decorate.HEAD
Documentation/config.txt explains how 'branch' and 'remoteBranch' are for local branches and remote tracking branches, respectively. Also the config entries are shown as if the case matters while in fact it does not. But I think it helps readability and at the same time it disambiguates 'head' vs. 'HEAD'.
This is to be applied on top of 67a4b5864f9423ccfe8090365029dae918504830:
"log --decorate: Colorize commit decorations" in pu.
Let me know if you want me to send the whole series again (4 patches).
Documentation/config.txt | 5 +++++ builtin/log.c | 3 +++ log-tree.c | 34 ++++++++++++++++++++++++++++++++++ log-tree.h | 1 + 4 files changed, 43 insertions(+), 0 deletions(-)
Documentation/config.txt +5 -0
@@ -683,6 +683,11 @@ color.diff.<slot>:: (highlighting whitespace errors). The values of these variables may be specified as in color.branch.<slot>. +color.decorate.<slot>:: + Use customized color for 'git log --decorate' output. `<slot>` is one + of `branch`, `remoteBranch`, `tag`, `stash` or `HEAD` for local + branches, remote tracking branches, tags, stash and HEAD, respectively. + color.grep:: When set to `always`, always highlight matches. When `false` (or `never`), never. When set to `true` or `auto`, use color only
builtin/log.c +3 -0
@@ -296,6 +296,9 @@ static int git_log_config(const char *var, const char *value, void *cb) default_show_root =git_config_bool (var, value);return 0 ; } +if (!prefixcmp (var,"color.decorate." )) +return parse_decorate_color_config (var,15 , value); +return git_diff_ui_config (var, value, cb); }
log-tree.c +34 -0
@@ -36,6 +36,40 @@ static const char *decorate_get_color(int decorate_use_color, enum decoration_tyreturn "" ; } +static int parse_decorate_color_slot (const char *slot) { +/* +* We're comparing with 'ignore-case' on +* (because config.c sets them all tolower), +* but let's match the letters in the literal +* string values here with how they are +* documented in Documentation/config.txt, for +* consistency. +* +* We love being consistent, don't we? +*/ +if (!strcasecmp (slot,"branch" )) +return DECORATION_REF_LOCAL ; +if (!strcasecmp (slot,"remoteBranch" )) +return DECORATION_REF_REMOTE ; +if (!strcasecmp (slot,"tag" )) +return DECORATION_REF_TAG ; +if (!strcasecmp (slot,"stash" )) +return DECORATION_REF_STASH ; +if (!strcasecmp (slot,"HEAD" )) +return DECORATION_REF_HEAD ; +return -1 ; +} + +int parse_decorate_color_config (const char *var,const int ofs,const char *value) { +int slot =parse_decorate_color_slot (var + ofs); +if (slot <0 ) +return 0 ; +if (!value) +return config_error_nonbool (var); +color_parse (value, var, decoration_colors[slot]); +return 0 ; +} +/* * log-tree.c uses DIFF_OPT_TST for determining whether to use color * for showing the commit sha1, use the same check for --decorate
log-tree.h +1 -0
@@ -7,6 +7,7 @@ struct log_info {struct commit *commit, *parent; }; +int parse_decorate_color_config (const char *var,const int ofs,const char *value);void init_log_tree_opt (struct rev_info *);int log_tree_diff_flush (struct rev_info *);int log_tree_commit (struct rev_info *,struct commit *);
Signature · 1 line
1.7.1.245.g7c42e.dirty
PATCH 1/1 Allow customizable commit decorations colors
---
Apologies for not catching this earlier.
My earlier version of this patch "Allow customizable commit decorations colors" (message id: [email protected]) has a bad style for the opening braces in the functions parse_decorate_color_slot() and parse_decorate_color_config() - the opening braces for these two functions were at the same line as the function head.
This patch fixes these style violations (replaces4938f6c98e4a6c4484bf652bdb887f0b8d8be822 in pu).
nazri.
Documentation/config.txt | 5 +++++ builtin/log.c | 3 +++ log-tree.c | 36 ++++++++++++++++++++++++++++++++++++ log-tree.h | 1 + 4 files changed, 45 insertions(+), 0 deletions(-)
Documentation/config.txt +5 -0
@@ -683,6 +683,11 @@ color.diff.<slot>:: (highlighting whitespace errors). The values of these variables may be specified as in color.branch.<slot>. +color.decorate.<slot>:: + Use customized color for 'git log --decorate' output. `<slot>` is one + of `branch`, `remoteBranch`, `tag`, `stash` or `HEAD` for local + branches, remote tracking branches, tags, stash and HEAD, respectively. + color.grep:: When set to `always`, always highlight matches. When `false` (or `never`), never. When set to `true` or `auto`, use color only
builtin/log.c +3 -0
@@ -296,6 +296,9 @@ static int git_log_config(const char *var, const char *value, void *cb) default_show_root =git_config_bool (var, value);return 0 ; } +if (!prefixcmp (var,"color.decorate." )) +return parse_decorate_color_config (var,15 , value); +return git_diff_ui_config (var, value, cb); }
log-tree.c +36 -0
@@ -36,6 +36,42 @@ static const char *decorate_get_color(int decorate_use_color, enum decoration_tyreturn "" ; } +static int parse_decorate_color_slot (const char *slot) +{ +/* +* We're comparing with 'ignore-case' on +* (because config.c sets them all tolower), +* but let's match the letters in the literal +* string values here with how they are +* documented in Documentation/config.txt, for +* consistency. +* +* We love being consistent, don't we? +*/ +if (!strcasecmp (slot,"branch" )) +return DECORATION_REF_LOCAL ; +if (!strcasecmp (slot,"remoteBranch" )) +return DECORATION_REF_REMOTE ; +if (!strcasecmp (slot,"tag" )) +return DECORATION_REF_TAG ; +if (!strcasecmp (slot,"stash" )) +return DECORATION_REF_STASH ; +if (!strcasecmp (slot,"HEAD" )) +return DECORATION_REF_HEAD ; +return -1 ; +} + +int parse_decorate_color_config (const char *var,const int ofs,const char *value) +{ +int slot =parse_decorate_color_slot (var + ofs); +if (slot <0 ) +return 0 ; +if (!value) +return config_error_nonbool (var); +color_parse (value, var, decoration_colors[slot]); +return 0 ; +} +/* * log-tree.c uses DIFF_OPT_TST for determining whether to use color * for showing the commit sha1, use the same check for --decorate
log-tree.h +1 -0
@@ -7,6 +7,7 @@ struct log_info {struct commit *commit, *parent; }; +int parse_decorate_color_config (const char *var,const int ofs,const char *value);void init_log_tree_opt (struct rev_info *);int log_tree_diff_flush (struct rev_info *);int log_tree_commit (struct rev_info *,struct commit *);
Signature · 1 line
1.7.1.245.g7c42e.dirty
PATCH 2/4 log-tree.c: Use struct name_decoration's type for classifying decoration
In reply to Junio C HamanoThe "tag: " prefix is no longer prepended to the name of the decoration. It is now printed conditionally by show_decorations if the decoration type is DECORATION_REF_TAG.
--- log-tree.c | 40 ++++++++++++++++++++++++++++++++-------- 1 files changed, 32 insertions(+), 8 deletions(-)
log-tree.c +32 -8
@@ -10,29 +10,50 @@struct decoration name_decoration = {"object names" }; -static void add_name_decoration (const char *prefix,const char *name,struct object *obj) +enum decoration_type { +DECORATION_NONE =0 , +DECORATION_REF_LOCAL , +DECORATION_REF_REMOTE , +DECORATION_REF_TAG , +DECORATION_REF_STASH , +DECORATION_REF_HEAD , +}; + +static void add_name_decoration (enum decoration_type type,const char *name,struct object *obj) { -int plen =strlen (prefix);int nlen =strlen (name); -struct name_decoration *res =xmalloc (sizeof (struct name_decoration ) + plen + nlen); -memcpy (res->name, prefix, plen); -memcpy (res->name + plen, name, nlen +1 ); +struct name_decoration *res =xmalloc (sizeof (struct name_decoration ) + nlen); +memcpy (res->name, name, nlen +1 ); + res->type = type; res->next =add_decoration (&name_decoration, obj, res); }static int add_ref_decoration (const char *refname,const unsigned char *sha1,int flags,void *cb_data) {struct object *obj =parse_object (sha1); +enum decoration_type type =DECORATION_NONE ;if (!obj)return 0 ; + +if (!prefixcmp (refname,"refs/heads" )) + type =DECORATION_REF_LOCAL ; +else if (!prefixcmp (refname,"refs/remotes" )) + type =DECORATION_REF_REMOTE ; +else if (!prefixcmp (refname,"refs/tags" )) + type =DECORATION_REF_TAG ; +else if (!prefixcmp (refname,"refs/stash" )) + type =DECORATION_REF_STASH ; +else if (!prefixcmp (refname,"HEAD" )) + type =DECORATION_REF_HEAD ; +if (!cb_data || *(int *)cb_data ==DECORATE_SHORT_REFS ) refname =prettify_refname (refname); -add_name_decoration ("" , refname, obj); +add_name_decoration (type, refname, obj);while (obj->type ==OBJ_TAG ) { obj = ((struct tag *)obj)->tagged;if (!obj)break ; -add_name_decoration ("tag: " , refname, obj); +add_name_decoration (DECORATION_REF_TAG , refname, obj); }return 0 ; }
@@ -70,7 +91,10 @@ void show_decorations(struct rev_info *opt, struct commit *commit)return ; prefix =" (" ;while (decoration) { -printf ("%s%s" , prefix, decoration->name); +printf ("%s" , prefix); +if (decoration->type ==DECORATION_REF_TAG ) +printf ("tag: " ); +printf ("%s" , decoration->name); prefix =", " ; decoration = decoration->next; }
Signature · 1 line
1.7.1.245.g7c42e.dirty
PATCH 3/4 log --decorate: Colorize commit decorations
In reply to Junio C HamanoThis makes the decorations stand out more and easier to distinguish and spot because they are colored differently depending on their type.
--- log-tree.c | 34 +++++++++++++++++++++++++++++++++- 1 files changed, 33 insertions(+), 1 deletions(-)
log-tree.c +33 -1
@@ -7,6 +7,7 @@#include "reflog-walk.h" #include "refs.h" #include "string-list.h" +#include "color.h" struct decoration name_decoration = {"object names" };
@@ -19,6 +20,29 @@ enum decoration_type { DECORATION_REF_HEAD, }; +static char decoration_colors[][COLOR_MAXLEN ] = { +GIT_COLOR_RESET , +GIT_COLOR_BOLD_GREEN ,/* REF_LOCAL */ +GIT_COLOR_BOLD_RED ,/* REF_REMOTE */ +GIT_COLOR_BOLD_YELLOW ,/* REF_TAG */ +GIT_COLOR_BOLD_MAGENTA ,/* REF_STASH */ +GIT_COLOR_BOLD_CYAN ,/* REF_HEAD */ +}; + +static const char *decorate_get_color (int decorate_use_color,enum decoration_type ix) +{ +if (decorate_use_color) +return decoration_colors[ix]; +return "" ; +} + +/* +* log-tree.c uses DIFF_OPT_TST for determining whether to use color +* for showing the commit sha1, use the same check for --decorate +*/ +#define decorate_get_color_opt (o, ix) \ + decorate_get_color(DIFF_OPT_TST((o), COLOR_DIFF), ix) +static void add_name_decoration (enum decoration_type type,const char *name,struct object *obj) {int nlen =strlen (name);
@@ -81,6 +105,10 @@ void show_decorations(struct rev_info *opt, struct commit *commit) {const char *prefix;struct name_decoration *decoration; +const char *color_commit = +diff_get_color_opt (&opt->diffopt,DIFF_COMMIT ); +const char *color_reset = +decorate_get_color_opt (&opt->diffopt,DECORATION_NONE );if (opt->show_source && commit->util)printf ("\t%s" , (char *) commit->util);
@@ -92,9 +120,13 @@ void show_decorations(struct rev_info *opt, struct commit *commit) prefix =" (" ;while (decoration) {printf ("%s" , prefix); +fputs (decorate_get_color_opt (&opt->diffopt, decoration->type), + stdout);if (decoration->type ==DECORATION_REF_TAG ) -printf ("tag: " ); +fputs ("tag: " , stdout);printf ("%s" , decoration->name); +fputs (color_reset, stdout); +fputs (color_commit, stdout); prefix =", " ; decoration = decoration->next; }
Signature · 1 line
1.7.1.245.g7c42e.dirty
PATCH 4/4 Allow customizable coloring of commit decorations
In reply to Junio C Hamano--- Documentation/config.txt | 6 ++++++ builtin/log.c | 3 +++ log-tree.c | 24 ++++++++++++++++++++++++ log-tree.h | 1 + 4 files changed, 34 insertions(+), 0 deletions(-)
Documentation/config.txt +6 -0
@@ -683,6 +683,12 @@ color.diff.<slot>:: (highlighting whitespace errors). The values of these variables may be specified as in color.branch.<slot>. +color.decorate.<slot>:: + Use customized color for 'git log --decorate' output. + `<slot>` is one of `reflocal`, `refremote`, `reftag`, `refstash` or + `refhead` for local refs, remote refs, tags, stash and HEAD, + respectively. + color.grep:: When set to `always`, always highlight matches. When `false` (or `never`), never. When set to `true` or `auto`, use color only
builtin/log.c +3 -0
@@ -296,6 +296,9 @@ static int git_log_config(const char *var, const char *value, void *cb) default_show_root =git_config_bool (var, value);return 0 ; } +if (!prefixcmp (var,"color.decorate." )) +return parse_decorate_color_config (var,15 , value); +return git_diff_ui_config (var, value, cb); }
log-tree.c +24 -0
@@ -36,6 +36,30 @@ static const char *decorate_get_color(int decorate_use_color, enum decoration_tyreturn "" ; } +static int parse_decorate_color_slot (const char *slot) { +if (!strcasecmp (slot,"reflocal" )) +return DECORATION_REF_LOCAL ; +if (!strcasecmp (slot,"refremote" )) +return DECORATION_REF_REMOTE ; +if (!strcasecmp (slot,"reftag" )) +return DECORATION_REF_TAG ; +if (!strcasecmp (slot,"refstash" )) +return DECORATION_REF_STASH ; +if (!strcasecmp (slot,"refhead" )) +return DECORATION_REF_HEAD ; +return -1 ; +} + +int parse_decorate_color_config (const char *var,const int ofs,const char *value) { +int slot =parse_decorate_color_slot (var + ofs); +if (slot <0 ) +return 0 ; +if (!value) +return config_error_nonbool (var); +color_parse (value, var, decoration_colors[slot]); +return 0 ; +} +/* * log-tree.c uses DIFF_OPT_TST for determining whether to use color * for showing the commit sha1, use the same check for --decorate
log-tree.h +1 -0
@@ -7,6 +7,7 @@ struct log_info {struct commit *commit, *parent; }; +int parse_decorate_color_config (const char *var,const int ofs,const char *value);void init_log_tree_opt (struct rev_info *);int log_tree_diff_flush (struct rev_info *);int log_tree_commit (struct rev_info *,struct commit *);
Signature · 1 line
1.7.1.245.g7c42e.dirty