git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/4] log --decorate: Colorize commit decorations

From
Nazri Ramliy <ayiehere@gmail.com>
Date
Jun 19, 2010, 01:37 UTC
Message-ID
<1276911456-18466-3-git-send-email-ayiehere@gmail.com>
In-Reply-To
<7vtyp11k9x.fsf@alter.siamese.dyndns.org>

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
Previous: Nazri RamliyNext: Nazri Ramliy
Message 8 of 9 in “Colorize commit decorations”
  1. Colorize commit decorationsNazri Ramliy, Jun 17, 2010
  2. Junio C HamanoJun 17, 2010
  3. 1/4 commit.h: add 'type' to struct name_decorationNazri Ramliy, Jun 19, 2010
  4. Junio C HamanoJun 22, 2010
  5. Allow customizable commit decorations colorsNazri Ramliy, Jun 23, 2010
  6. Allow customizable commit decorations colorsNazri Ramliy, Jun 24, 2010
  7. 2/4 log-tree.c: Use struct name_decoration's type for classifying decorationNazri Ramliy, Jun 19, 2010
  8. 3/4 log --decorate: Colorize commit decorationsNazri Ramliy, Jun 19, 2010
  9. 4/4 Allow customizable coloring of commit decorationsNazri Ramliy, Jun 19, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.