List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH 2/2] ui-log: Simplify decoration code
@ 2016-02-26 20:58 tim.nordell
  2016-02-28 12:46 ` john
  2016-05-12 15:19 ` Jason
  0 siblings, 2 replies; 3+ messages in thread
From: tim.nordell @ 2016-02-26 20:58 UTC (permalink / raw)


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 at logicpd.com>

diff --git a/ui-log.c b/ui-log.c
index 62881ce..fc215d6 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);
-			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);
-			cgit_tag_link(buf, NULL, "tag-deco", buf);
-		}
-		else if (starts_with(deco->name, "refs/remotes/")) {
-			if (!ctx.repo->enable_remote_branches)
-				goto next;
-			strncpy(buf, deco->name + 13, sizeof(buf) - 1);
-			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);
-			cgit_commit_link(buf, NULL, "deco", ctx.qry.head,
-					 oid_to_hex(&commit->object.oid),
-					 ctx.qry.vpath);
+		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);
+				break;
+			case DECORATION_REF_TAG:
+				cgit_tag_link(buf, NULL, "tag-deco", buf);
+				break;
+			case DECORATION_REF_REMOTE:
+				if (!ctx.repo->enable_remote_branches)
+					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);
+				break;
+			default:
+				cgit_commit_link(buf, NULL, "deco", ctx.qry.head,
+						oid_to_hex(&commit->object.oid),
+						ctx.qry.vpath);
+				break;
 		}
-next:
 		deco = deco->next;
 	}
 	html("</span>");
-- 
2.4.9



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] ui-log: Simplify decoration code
  2016-02-26 20:58 [PATCH 2/2] ui-log: Simplify decoration code tim.nordell
@ 2016-02-28 12:46 ` john
  2016-05-12 15:19 ` Jason
  1 sibling, 0 replies; 3+ messages in thread
From: john @ 2016-02-28 12:46 UTC (permalink / raw)


On Fri, Feb 26, 2016 at 02:58:41PM -0600, Tim Nordell wrote:
> 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 at logicpd.com>

Minor style issue that all the "case" arms should be shifted to the
left, but we're already inconsistent on that, so:

Reviewed-by: John Keeping <john at keeping.me.uk>

> diff --git a/ui-log.c b/ui-log.c
> index 62881ce..fc215d6 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);
> -			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);
> -			cgit_tag_link(buf, NULL, "tag-deco", buf);
> -		}
> -		else if (starts_with(deco->name, "refs/remotes/")) {
> -			if (!ctx.repo->enable_remote_branches)
> -				goto next;
> -			strncpy(buf, deco->name + 13, sizeof(buf) - 1);
> -			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);
> -			cgit_commit_link(buf, NULL, "deco", ctx.qry.head,
> -					 oid_to_hex(&commit->object.oid),
> -					 ctx.qry.vpath);
> +		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);
> +				break;
> +			case DECORATION_REF_TAG:
> +				cgit_tag_link(buf, NULL, "tag-deco", buf);
> +				break;
> +			case DECORATION_REF_REMOTE:
> +				if (!ctx.repo->enable_remote_branches)
> +					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);
> +				break;
> +			default:
> +				cgit_commit_link(buf, NULL, "deco", ctx.qry.head,
> +						oid_to_hex(&commit->object.oid),
> +						ctx.qry.vpath);
> +				break;
>  		}
> -next:
>  		deco = deco->next;
>  	}
>  	html("</span>");
> -- 
> 2.4.9
> 
> _______________________________________________
> CGit mailing list
> CGit at lists.zx2c4.com
> http://lists.zx2c4.com/mailman/listinfo/cgit


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] ui-log: Simplify decoration code
  2016-02-26 20:58 [PATCH 2/2] ui-log: Simplify decoration code tim.nordell
  2016-02-28 12:46 ` john
@ 2016-05-12 15:19 ` Jason
  1 sibling, 0 replies; 3+ messages in thread
From: Jason @ 2016-05-12 15:19 UTC (permalink / raw)


Merged, thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20160512/8410e40c/attachment.html>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-05-12 15:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-26 20:58 [PATCH 2/2] ui-log: Simplify decoration code tim.nordell
2016-02-28 12:46 ` john
2016-05-12 15:19 ` Jason

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).