"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Omar Polo <op@omarpolo.com>
Subject:
gotwebd: templateify gotweb_render_tag
To:
gameoftrees@openbsd.org
Date:
Sat, 07 Jan 2023 22:03:58 +0100

Download raw body.

Thread
  • Omar Polo:

    gotwebd: templateify gotweb_render_tag

usual treatment for gotweb_render_tag.  Applies on top of the
gotweb_render_tags (plural) diff I sent previously.

i have this and the previous diff on my mirror.

(the diff page diff is still pending but i don't have it anymore on my
instance - temporarly.)


diff /home/op/w/got
commit - aff3b0eea2e16162a7f51801bd379ae05cd4df3b
path + /home/op/w/got
blob - b0073bd432cd5dcf72ae7f82e1d97d8ae4f6a8f0
file + gotwebd/gotweb.c
--- gotwebd/gotweb.c
+++ gotwebd/gotweb.c
@@ -96,7 +96,6 @@ static const struct got_error *gotweb_render_tag(struc
 static const struct got_error *gotweb_render_blame(struct request *);
 static const struct got_error *gotweb_render_diff(struct request *);
 static const struct got_error *gotweb_render_summary(struct request *);
-static const struct got_error *gotweb_render_tag(struct request *);
 static const struct got_error *gotweb_render_tags(struct request *);
 static const struct got_error *gotweb_render_branches(struct request *);
 
@@ -291,11 +290,18 @@ render:
 		}
 		break;
 	case TAG:
-		error = gotweb_render_tag(c);
+		error = got_get_repo_tags(c, 1);
 		if (error) {
 			log_warnx("%s: %s", __func__, error->msg);
 			goto err;
 		}
+		if (c->t->tag_count == 0) {
+			error = got_error_msg(GOT_ERR_BAD_OBJ_ID,
+			    "bad commit id");
+			goto err;
+		}
+		if (gotweb_render_tag(c->tp) == -1)
+			goto done;
 		break;
 	case TAGS:
 		error = gotweb_render_tags(c);
@@ -1257,77 +1263,6 @@ gotweb_render_tag(struct request *c)
 }
 
 static const struct got_error *
-gotweb_render_tag(struct request *c)
-{
-	const struct got_error *error = NULL;
-	struct repo_tag *rt = NULL;
-	struct transport *t = c->t;
-	char *tagname = NULL, *age = NULL, *author = NULL, *msg = NULL;
-
-	error = got_get_repo_tags(c, 1);
-	if (error)
-		goto done;
-
-	if (t->tag_count == 0) {
-		error = got_error_set_errno(GOT_ERR_BAD_OBJ_ID,
-		    "bad commit id");
-		goto done;
-	}
-
-	rt = TAILQ_LAST(&t->repo_tags, repo_tags_head);
-
-	error = gotweb_get_time_str(&age, rt->tagger_time, TM_LONG);
-	if (error)
-		goto done;
-	error = gotweb_escape_html(&author, rt->tagger);
-	if (error)
-		goto done;
-	error = gotweb_escape_html(&msg, rt->commit_msg);
-	if (error)
-		goto done;
-
-	tagname = rt->tag_name;
-	if (strncmp(tagname, "refs/", 5) == 0)
-		tagname += 5;
-	error = gotweb_escape_html(&tagname, tagname);
-	if (error)
-		goto done;
-
-	fcgi_printf(c, "<div id='tags_title_wrapper'>\n"
-	    "<div id='tags_title'>Tag</div>\n"
-	    "</div>\n"		/* #tags_title_wrapper */
-	    "<div id='tags_content'>\n"
-	    "<div id='tag_header_wrapper'>\n"
-	    "<div id='tag_header'>\n"
-	    "<div class='header_commit_title'>Commit:</div>\n"
-	    "<div class='header_commit'>%s"
-	    " <span class='refs_str'>(%s)</span></div>\n"
-	    "<div class='header_author_title'>Tagger:</div>\n"
-	    "<div class='header_author'>%s</div>\n"
-	    "<div class='header_age_title'>Date:</div>\n"
-	    "<div class='header_age'>%s</div>\n"
-	    "<div id='header_commit_msg_title'>Message:</div>\n"
-	    "<div id='header_commit_msg'>%s</div>\n"
-	    "</div>\n"		/* #tag_header */
-	    "<div class='dotted_line'></div>\n"
-	    "<div id='tag_commit'>\n%s</div>"
-	    "</div>"		/* #tag_header_wrapper */
-	    "</div>",		/* #tags_content */
-	    rt->commit_id,
-	    tagname,
-	    author,
-	    age,
-	    msg,
-	    rt->tag_commit);
-
-done:
-	free(age);
-	free(author);
-	free(msg);
-	return error;
-}
-
-static const struct got_error *
 gotweb_render_tags(struct request *c)
 {
 	const struct got_error *error = NULL;
blob - 82411f713d7bde00ef0d95f07bf0b914771735ed
file + gotwebd/gotwebd.h
--- gotwebd/gotwebd.h
+++ gotwebd/gotwebd.h
@@ -470,6 +470,7 @@ int	gotweb_render_rss(struct template *);
 int	gotweb_render_blob(struct template *, struct got_blob_object *);
 int	gotweb_render_tree(struct template *);
 int	gotweb_render_tags_tmpl(struct template *);
+int	gotweb_render_tag(struct template *);
 int	gotweb_render_rss(struct template *);
 
 /* parse.y */
blob - 8bf0a13026da2c453ceba474ad9e4fd12b90c713
file + gotwebd/pages.tmpl
--- gotwebd/pages.tmpl
+++ gotwebd/pages.tmpl
@@ -649,6 +649,49 @@ gotweb_render_age(struct template *tp, time_t time, in
 <div class="dotted_line"></div>
 {{ end }}
 
+{{ define gotweb_render_tag(struct template *tp) }}
+{!
+	struct request		*c = tp->tp_arg;
+	struct transport	*t = c->t;
+	struct repo_tag		*rt;
+	const char		*tag_name;
+
+	rt = TAILQ_LAST(&t->repo_tags, repo_tags_head);
+	tag_name = rt->tag_name;
+
+	if (strncmp(tag_name, "refs/", 5) == 0)
+		tag_name += 5;
+!}
+<div id="tags_title_wrapper">
+  <div id="tags_title">Tag</div>
+</div>
+<div id="tags_content">
+  <div id="tag_header_wrapper">
+    <div id="tag_header">
+      <div class="header_commit_title">Commit:</div>
+      <div class="header_commit">
+        {{ rt->commit_id }}
+        {{ " " }}
+        <span class="refs_str">({{ tag_name }})</span>
+      </div>
+      <div class="header_author_title">Tagger:</div>
+      <div class="header_author">{{ rt->tagger }}</div>
+      <div class="header_age_title">Date:</div>
+      <div class="header_age">
+        {{ render gotweb_render_age(tp, rt->tagger_time, TM_LONG)}}
+      </div>
+      <div id="header_commit_msg_title">Message:</div>
+      <div id="header_commit_msg">{{ rt->commit_msg }}</div>
+    </div>
+    <div class="dotted_line"></div>
+    <div id="tag_commit">
+      {{ "\n" }}
+      {{ rt->tag_commit }}
+    </div>
+  </div>
+</div>
+{{ end }}
+
 {{ define gotweb_render_rss(struct template *tp) }}
 {!
 	struct request		*c = tp->tp_arg;