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

[PATCH 2/4] log-tree.c: Use struct name_decoration's type for classifying decoration

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

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
Previous: Nazri RamliyNext: Nazri Ramliy
Message 7 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.