From: Omar Polo Subject: gotwebd: templateify gotweb_render_tag To: gameoftrees@openbsd.org Date: Sat, 07 Jan 2023 22:03:58 +0100 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, "
\n" - "
Tag
\n" - "
\n" /* #tags_title_wrapper */ - "
\n" - "
\n" - "
\n" - "
Commit:
\n" - "
%s" - " (%s)
\n" - "
Tagger:
\n" - "
%s
\n" - "
Date:
\n" - "
%s
\n" - "
Message:
\n" - "
%s
\n" - "
\n" /* #tag_header */ - "
\n" - "
\n%s
" - "
" /* #tag_header_wrapper */ - "
", /* #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
{{ 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; +!} +
+
Tag
+
+
+
+
+
Commit:
+
+ {{ rt->commit_id }} + {{ " " }} + ({{ tag_name }}) +
+
Tagger:
+
{{ rt->tagger }}
+
Date:
+
+ {{ render gotweb_render_age(tp, rt->tagger_time, TM_LONG)}} +
+
Message:
+
{{ rt->commit_msg }}
+
+
+
+ {{ "\n" }} + {{ rt->tag_commit }} +
+
+
+{{ end }} + {{ define gotweb_render_rss(struct template *tp) }} {! struct request *c = tp->tp_arg;