git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Colorize commit decorations
@ 2010-06-17 16:15 Nazri Ramliy
  2010-06-17 20:22 ` Junio C Hamano
  0 siblings, 1 reply; 9+ messages in thread
From: Nazri Ramliy @ 2010-06-17 16:15 UTC (permalink / raw)
  To: git, gitster; +Cc: 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.
---
 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(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 95cf73c..afa4f5a 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -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).
diff --git a/builtin/log.c b/builtin/log.c
index 976e16f..bbc5d02 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -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);
 }
 
diff --git a/commit.h b/commit.h
index 6ef88dc..a49cfe3 100644
--- a/commit.h
+++ b/commit.h
@@ -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];
 };
 
diff --git a/decorate.c b/decorate.c
index 2f8a63e..cbef2b4 100644
--- a/decorate.c
+++ b/decorate.c
@@ -5,6 +5,48 @@
 #include "cache.h"
 #include "object.h"
 #include "decorate.h"
+#include "color.h"
+
+static char decoration_colors[][COLOR_MAXLEN] = {
+	GIT_COLOR_RESET,	/* DECORATION_NONE */
+	GIT_COLOR_BOLD_GREEN,	/* DECORATION_REF_LOCAL */
+	GIT_COLOR_BOLD_RED,	/* DECORATION_REF_REMOTE */
+	GIT_COLOR_BOLD_YELLOW,	/* DECORATION_TAG */
+	GIT_COLOR_BOLD_MAGENTA,	/* DECORATION_STASH */
+	GIT_COLOR_BOLD_CYAN	/* DECORATION_HEAD */
+};
+
+const char *decorate_get_color(int decorate_use_color, enum decoration_type ix)
+{
+	if (decorate_use_color) {
+		return decoration_colors[ix];
+	}
+	return "";
+}
+
+static int parse_decorate_color_slot(const char *slot) {
+	if (!strcasecmp(slot, "local"))
+		return COLOR_DECORATION_REF_LOCAL;
+	if (!strcasecmp(slot, "remote"))
+		return COLOR_DECORATION_REF_REMOTE;
+	if (!strcasecmp(slot, "tag"))
+		return COLOR_DECORATION_TAG;
+	if (!strcasecmp(slot, "stash"))
+		return COLOR_DECORATION_STASH;
+	if (!strcasecmp(slot, "head"))
+		return COLOR_DECORATION_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;
+}
 
 static unsigned int hash_obj(const struct object *obj, unsigned int n)
 {
diff --git a/decorate.h b/decorate.h
index e732804..d593d32 100644
--- a/decorate.h
+++ b/decorate.h
@@ -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);
 
diff --git a/log-tree.c b/log-tree.c
index d3ae969..95ebf1a 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -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;
 	}
-- 
1.7.1.245.g7c42e.dirty

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] Colorize commit decorations
  2010-06-17 16:15 [PATCH] Colorize commit decorations Nazri Ramliy
@ 2010-06-17 20:22 ` Junio C Hamano
  2010-06-19  1:37   ` [PATCH 1/4] commit.h: add 'type' to struct name_decoration Nazri Ramliy
                     ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Junio C Hamano @ 2010-06-17 20:22 UTC (permalink / raw)
  To: Nazri Ramliy; +Cc: git

Nazri Ramliy <ayiehere@gmail.com> writes:

> 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?

> diff --git a/Documentation/config.txt b/Documentation/config.txt
> index 95cf73c..afa4f5a 100644
> --- a/Documentation/config.txt
> +++ b/Documentation/config.txt
> @@ -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>).

> diff --git a/decorate.c b/decorate.c
> index 2f8a63e..cbef2b4 100644
> --- a/decorate.c
> +++ b/decorate.c
> @@ -5,6 +5,48 @@
>  #include "cache.h"
>  #include "object.h"
>  #include "decorate.h"
> +#include "color.h"
> ...
> +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.

> diff --git a/decorate.h b/decorate.h
> index e732804..d593d32 100644

So is any change to this file.

> diff --git a/log-tree.c b/log-tree.c
> index d3ae969..95ebf1a 100644
> --- a/log-tree.c
> +++ b/log-tree.c
> @@ -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);
>  }

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.

>  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;

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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/4] commit.h: add 'type' to struct name_decoration
  2010-06-17 20:22 ` Junio C Hamano
@ 2010-06-19  1:37   ` Nazri Ramliy
  2010-06-22  4:04     ` Junio C Hamano
  2010-06-19  1:37   ` [PATCH 2/4] log-tree.c: Use struct name_decoration's type for classifying decoration Nazri Ramliy
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Nazri Ramliy @ 2010-06-19  1:37 UTC (permalink / raw)
  To: gitster, git; +Cc: Nazri Ramliy

This allows for semantically better handling of decoration type.

Signed-off-by: Nazri Ramliy <ayiehere@gmail.com>
---
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:

On Fri, Jun 18, 2010 at 4:22 AM, Junio C Hamano <gitster@pobox.com> wrote:
> 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.

> 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.
>
>> diff --git a/decorate.h b/decorate.h
>> index e732804..d593d32 100644
>
> So is any change to this file.

Fixed. decorate.[ch] is no longer affected by this series.

> 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.

>> +     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.

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(-)

diff --git a/commit.h b/commit.h
index 6ef88dc..ba818fc 100644
--- a/commit.h
+++ b/commit.h
@@ -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];
 };
 
-- 
1.7.1.245.g7c42e.dirty

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/4] log-tree.c: Use struct name_decoration's type for classifying decoration
  2010-06-17 20:22 ` Junio C Hamano
  2010-06-19  1:37   ` [PATCH 1/4] commit.h: add 'type' to struct name_decoration Nazri Ramliy
@ 2010-06-19  1:37   ` Nazri Ramliy
  2010-06-19  1:37   ` [PATCH 3/4] log --decorate: Colorize commit decorations Nazri Ramliy
  2010-06-19  1:37   ` [PATCH 4/4] Allow customizable coloring of " Nazri Ramliy
  3 siblings, 0 replies; 9+ messages in thread
From: Nazri Ramliy @ 2010-06-19  1:37 UTC (permalink / raw)
  To: gitster, git; +Cc: Nazri Ramliy

The "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.

Signed-off-by: Nazri Ramliy <ayiehere@gmail.com>
---
 log-tree.c |   40 ++++++++++++++++++++++++++++++++--------
 1 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/log-tree.c b/log-tree.c
index d3ae969..2d804ee 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -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;
 	}
-- 
1.7.1.245.g7c42e.dirty

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/4] log --decorate: Colorize commit decorations
  2010-06-17 20:22 ` Junio C Hamano
  2010-06-19  1:37   ` [PATCH 1/4] commit.h: add 'type' to struct name_decoration Nazri Ramliy
  2010-06-19  1:37   ` [PATCH 2/4] log-tree.c: Use struct name_decoration's type for classifying decoration Nazri Ramliy
@ 2010-06-19  1:37   ` Nazri Ramliy
  2010-06-19  1:37   ` [PATCH 4/4] Allow customizable coloring of " Nazri Ramliy
  3 siblings, 0 replies; 9+ messages in thread
From: Nazri Ramliy @ 2010-06-19  1:37 UTC (permalink / raw)
  To: gitster, git; +Cc: Nazri Ramliy

This makes the decorations stand out more and easier to distinguish
and spot because they are colored differently depending on their type.

Signed-off-by: Nazri Ramliy <ayiehere@gmail.com>
---
 log-tree.c |   34 +++++++++++++++++++++++++++++++++-
 1 files changed, 33 insertions(+), 1 deletions(-)

diff --git a/log-tree.c b/log-tree.c
index 2d804ee..25586cf 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -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;
 	}
-- 
1.7.1.245.g7c42e.dirty

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/4] Allow customizable coloring of commit decorations
  2010-06-17 20:22 ` Junio C Hamano
                     ` (2 preceding siblings ...)
  2010-06-19  1:37   ` [PATCH 3/4] log --decorate: Colorize commit decorations Nazri Ramliy
@ 2010-06-19  1:37   ` Nazri Ramliy
  3 siblings, 0 replies; 9+ messages in thread
From: Nazri Ramliy @ 2010-06-19  1:37 UTC (permalink / raw)
  To: gitster, git; +Cc: Nazri Ramliy

Signed-off-by: Nazri Ramliy <ayiehere@gmail.com>
---
 Documentation/config.txt |    6 ++++++
 builtin/log.c            |    3 +++
 log-tree.c               |   24 ++++++++++++++++++++++++
 log-tree.h               |    1 +
 4 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 95cf73c..b3e80c1 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -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
diff --git a/builtin/log.c b/builtin/log.c
index 976e16f..0835866 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -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);
 }
 
diff --git a/log-tree.c b/log-tree.c
index 25586cf..0265228 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -36,6 +36,30 @@ static const char *decorate_get_color(int decorate_use_color, enum decoration_ty
 	return "";
 }
 
+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
diff --git a/log-tree.h b/log-tree.h
index 3f7b400..5c4cf7c 100644
--- a/log-tree.h
+++ b/log-tree.h
@@ -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 *);
-- 
1.7.1.245.g7c42e.dirty

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] commit.h: add 'type' to struct name_decoration
  2010-06-19  1:37   ` [PATCH 1/4] commit.h: add 'type' to struct name_decoration Nazri Ramliy
@ 2010-06-22  4:04     ` Junio C Hamano
  2010-06-23  0:43       ` [PATCH] Allow customizable commit decorations colors Nazri Ramliy
  0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2010-06-22  4:04 UTC (permalink / raw)
  To: Nazri Ramliy; +Cc: git

Nazri Ramliy <ayiehere@gmail.com> writes:

> 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?

>         color.decorate.reftag
>         color.decorate.refstash
>         color.decorate.refhead

And these would just be "tag", "stash" and "head".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] Allow customizable commit decorations colors
  2010-06-22  4:04     ` Junio C Hamano
@ 2010-06-23  0:43       ` Nazri Ramliy
  2010-06-24  0:21         ` Nazri Ramliy
  0 siblings, 1 reply; 9+ messages in thread
From: Nazri Ramliy @ 2010-06-23  0:43 UTC (permalink / raw)
  To: gitster, git; +Cc: Nazri Ramliy

Signed-off-by: Nazri Ramliy <ayiehere@gmail.com>
---
On Tue, Jun 22, 2010 at 12:04 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Nazri Ramliy <ayiehere@gmail.com> writes:
>>         color.decorate.reflocal
>>         color.decorate.refremote
>
> Wouldn't "(local) branch" and "remote (tracking) branch" be more natural
> way to call these things?
>
>>         color.decorate.reftag
>>         color.decorate.refstash
>>         color.decorate.refhead
>
> And 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(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 7afd0a3..89cb487 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -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
diff --git a/builtin/log.c b/builtin/log.c
index 976e16f..0835866 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -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);
 }
 
diff --git a/log-tree.c b/log-tree.c
index 61680f4..28280e9 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -36,6 +36,40 @@ static const char *decorate_get_color(int decorate_use_color, enum decoration_ty
 	return "";
 }
 
+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
diff --git a/log-tree.h b/log-tree.h
index 3f7b400..5c4cf7c 100644
--- a/log-tree.h
+++ b/log-tree.h
@@ -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 *);
-- 
1.7.1.245.g7c42e.dirty

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH] Allow customizable commit decorations colors
  2010-06-23  0:43       ` [PATCH] Allow customizable commit decorations colors Nazri Ramliy
@ 2010-06-24  0:21         ` Nazri Ramliy
  0 siblings, 0 replies; 9+ messages in thread
From: Nazri Ramliy @ 2010-06-24  0:21 UTC (permalink / raw)
  To: gitster, git; +Cc: Nazri Ramliy

Signed-off-by: Nazri Ramliy <ayiehere@gmail.com>
---
Apologies for not catching this earlier.

My earlier version of this patch "Allow customizable commit decorations colors"
(message id: 1277253782-3330-1-git-send-email-ayiehere@gmail.com) 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 (replaces
4938f6c98e4a6c4484bf652bdb887f0b8d8be822 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(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 7afd0a3..89cb487 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -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
diff --git a/builtin/log.c b/builtin/log.c
index 976e16f..0835866 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -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);
 }
 
diff --git a/log-tree.c b/log-tree.c
index 61680f4..b46ed3b 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -36,6 +36,42 @@ static const char *decorate_get_color(int decorate_use_color, enum decoration_ty
 	return "";
 }
 
+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
diff --git a/log-tree.h b/log-tree.h
index 3f7b400..5c4cf7c 100644
--- a/log-tree.h
+++ b/log-tree.h
@@ -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 *);
-- 
1.7.1.245.g7c42e.dirty

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-06-24  0:21 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-17 16:15 [PATCH] Colorize commit decorations Nazri Ramliy
2010-06-17 20:22 ` Junio C Hamano
2010-06-19  1:37   ` [PATCH 1/4] commit.h: add 'type' to struct name_decoration Nazri Ramliy
2010-06-22  4:04     ` Junio C Hamano
2010-06-23  0:43       ` [PATCH] Allow customizable commit decorations colors Nazri Ramliy
2010-06-24  0:21         ` Nazri Ramliy
2010-06-19  1:37   ` [PATCH 2/4] log-tree.c: Use struct name_decoration's type for classifying decoration Nazri Ramliy
2010-06-19  1:37   ` [PATCH 3/4] log --decorate: Colorize commit decorations Nazri Ramliy
2010-06-19  1:37   ` [PATCH 4/4] Allow customizable coloring of " Nazri Ramliy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).