[PATCH v3 11/21] Render commit decorations correctly

Richard Maw richard.maw at gmail.com
Mon Aug 1 23:35:43 CEST 2016


They must be displayed without the namespace prefix,
and refs from outside the namespace must not be shown.

Unfortunately decorations from tags within the namespace aren't always provided
while tags from outside it are, but at least it's not displaying broken links.

The decoration classification is not namespace aware,
so they need to be re-classified for HEAD and branches to be rendered.

Signed-off-by: Richard Maw <richard.maw at gmail.com>
---
 ui-log.c | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/ui-log.c b/ui-log.c
index 71ef3d4..fda2523 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -64,9 +64,32 @@ void show_commit_decorations(struct commit *commit)
 	if (!deco)
 		return;
 	html("<span class='decoration'>");
-	while (deco) {
-		strncpy(buf, prettify_refname(deco->name), sizeof(buf) - 1);
-		switch(deco->type) {
+	for (; deco; deco = deco->next) {
+		const char *name = strip_namespace(deco->name);
+		enum decoration_type type = deco->type;
+
+		/* Skip decorations for refs not in our namespace,
+		   since it's not possible to pre-filter decorations. */
+		if (!name)
+			continue;
+
+		/* DECORATION_NONE is given for namespced refs,
+		   so we have to re-classify sometimes. */
+		if (name != deco->name && type == DECORATION_NONE) {
+			if (starts_with(name, "refs/heads/"))
+				type = DECORATION_REF_LOCAL;
+			else if (starts_with(name, "refs/remotes/"))
+				type = DECORATION_REF_REMOTE;
+			else if (starts_with(name, "refs/tags/"))
+				type = DECORATION_REF_TAG;
+			else if (!strcmp(name, "refs/stash"))
+				type = DECORATION_REF_STASH;
+			else if (!strcmp(name, "HEAD"))
+				type = DECORATION_REF_HEAD;
+		}
+
+		strncpy(buf, prettify_refname(name), sizeof(buf) - 1);
+		switch(type) {
 		case DECORATION_NONE:
 			/* If the git-core doesn't recognize it,
 			 * don't display anything. */
@@ -93,7 +116,6 @@ void show_commit_decorations(struct commit *commit)
 					ctx.qry.vpath);
 			break;
 		}
-		deco = deco->next;
 	}
 	html("</span>");
 }
-- 
2.9.0



More information about the CGit mailing list