about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTim Nordell <tim.nordell@logicpd.com>2016-02-26 14:58:41 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2016-05-12 17:19:20 +0200
commit59d8fa1a62e7c19911fdf7ee9ceb0fdf8fa3331c (patch)
treea7215ee7bed77029a7940e3fb28b037d7b7c890f
parentui-log: Do not always emit decoration span (diff)
downloadcgit-pink-59d8fa1a62e7c19911fdf7ee9ceb0fdf8fa3331c.tar.gz
cgit-pink-59d8fa1a62e7c19911fdf7ee9ceb0fdf8fa3331c.zip
ui-log: Simplify decoration code
The decoration code inside of git returns the decoration type, so
utilize this to create the decoration spans.  Additionally, use
prettify_refname(...) to get the shorter name for the ref.

Signed-off-by: Tim Nordell <tim.nordell@logicpd.com>
-rw-r--r--ui-log.c46
1 files changed, 22 insertions, 24 deletions
diff --git a/ui-log.c b/ui-log.c
index 641a5b6..d6d94f6 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -65,36 +65,34 @@ void show_commit_decorations(struct commit *commit)
 		return;
 	html("<span class='decoration'>");
 	while (deco) {
-		if (starts_with(deco->name, "refs/heads/")) {
-			strncpy(buf, deco->name + 11, sizeof(buf) - 1);
+		strncpy(buf, prettify_refname(deco->name), sizeof(buf) - 1);
+		switch(deco->type) {
+		case DECORATION_NONE:
+			/* If the git-core doesn't recognize it,
+			 * don't display anything. */
+			break;
+		case DECORATION_REF_LOCAL:
 			cgit_log_link(buf, NULL, "branch-deco", buf, NULL,
-				      ctx.qry.vpath, 0, NULL, NULL,
-				      ctx.qry.showmsg, 0);
-		}
-		else if (starts_with(deco->name, "tag: refs/tags/")) {
-			strncpy(buf, deco->name + 15, sizeof(buf) - 1);
-			cgit_tag_link(buf, NULL, "tag-deco", buf);
-		}
-		else if (starts_with(deco->name, "refs/tags/")) {
-			strncpy(buf, deco->name + 10, sizeof(buf) - 1);
+				ctx.qry.vpath, 0, NULL, NULL,
+				ctx.qry.showmsg, 0);
+			break;
+		case DECORATION_REF_TAG:
 			cgit_tag_link(buf, NULL, "tag-deco", buf);
-		}
-		else if (starts_with(deco->name, "refs/remotes/")) {
+			break;
+		case DECORATION_REF_REMOTE:
 			if (!ctx.repo->enable_remote_branches)
-				goto next;
-			strncpy(buf, deco->name + 13, sizeof(buf) - 1);
+				break;
 			cgit_log_link(buf, NULL, "remote-deco", NULL,
-				      oid_to_hex(&commit->object.oid),
-				      ctx.qry.vpath, 0, NULL, NULL,
-				      ctx.qry.showmsg, 0);
-		}
-		else {
-			strncpy(buf, deco->name, sizeof(buf) - 1);
+				oid_to_hex(&commit->object.oid),
+				ctx.qry.vpath, 0, NULL, NULL,
+				ctx.qry.showmsg, 0);
+			break;
+		default:
 			cgit_commit_link(buf, NULL, "deco", ctx.qry.head,
-					 oid_to_hex(&commit->object.oid),
-					 ctx.qry.vpath);
+					oid_to_hex(&commit->object.oid),
+					ctx.qry.vpath);
+			break;
 		}
-next:
 		deco = deco->next;
 	}
 	html("</span>");
t; is merged and appears in a release. 2019-02-18Use hi -o anchor in upJune McEnroe 2019-02-18Don't match nested parentheses in Tag for CJune McEnroe Fixes mistaken highlight of: pngWrite(file, (uint8_t []) { 0, 0, 0 }, 3); 2019-02-18Match whitespace between * [] {}June McEnroe 2019-02-18Fix function-like #define regexJune McEnroe A define like #define FOO (1) is not function-like. 2019-02-18Match Tag in RustJune McEnroe 2019-02-18Match sh functions as TagJune McEnroe 2019-02-18Match Sh and Ss as Tag in mdocJune McEnroe 2019-02-18Match statics and typedefs as TagJune McEnroe 2019-02-18Clean up htmlHeaderJune McEnroe 2019-02-18Remove hi line numberingJune McEnroe Tags are much better for referring to specific parts of a file and line numbering is better done by a post-processing tool such as cat -n or producing a two-column HTML <table>. 2019-02-18Add Tag class to hiJune McEnroe 2019-02-17Generate HTML with hi -n -f html -o anchorJune McEnroe Running hi twice to insert stuff between the head and the content is a bit of a hack but oh well. 2019-02-17Add hi -f html -o anchor for line number linksJune McEnroe 2019-02-17Simplify temp trap in upJune McEnroe 2019-02-17Add line numbers to hiJune McEnroe Renames previous -n option to -m to stay consistent with cat -n. Prefixing lines with line numbers affects where the first tab indent ends up relative to the text above it. Not sure if it's worth fixing somehow. 2019-02-17Always split spans after newlinesJune McEnroe Simplifies ANSI and IRC output code, and prepares for line numbered output. 2019-02-15Color format specifiers light cyan in vimJune McEnroe 2019-02-15Highlight Interp as yellowJune McEnroe 2019-02-15Highlight strings in sh command substitutionsJune McEnroe 2019-02-15Add nmap gpJune McEnroe 2019-02-14Avoid newline when copying URL to pasteboardJune McEnroe 2019-02-13Add forgotten "sixth" book of H2G2June McEnroe