git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nazri Ramliy <ayiehere@gmail.com>
To: gitster@pobox.com, git@vger.kernel.org
Cc: Nazri Ramliy <ayiehere@gmail.com>
Subject: [PATCH] Allow customizable commit decorations colors
Date: Wed, 23 Jun 2010 08:43:02 +0800	[thread overview]
Message-ID: <1277253782-3330-1-git-send-email-ayiehere@gmail.com> (raw)
In-Reply-To: <7vhbkvg1bd.fsf@alter.siamese.dyndns.org>

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

  reply	other threads:[~2010-06-23  0:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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       ` Nazri Ramliy [this message]
2010-06-24  0:21         ` [PATCH] Allow customizable commit decorations colors 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1277253782-3330-1-git-send-email-ayiehere@gmail.com \
    --to=ayiehere@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).