commit 067396e6118227d9aa15a49c7d49238c0fff8d94 from: Omar Polo date: Mon Jan 09 17:42:20 2023 UTC gotwebd: templateify gotweb_render_tags ok tracey@ commit - 60c140aebbd1069094e75d8358cb305bc305b7f8 commit + 067396e6118227d9aa15a49c7d49238c0fff8d94 blob - a8fdd952ec48f1a229440e115de67205cf20f049 blob + b0073bd432cd5dcf72ae7f82e1d97d8ae4f6a8f0 --- gotwebd/gotweb.c +++ gotwebd/gotweb.c @@ -1331,13 +1331,9 @@ static const struct got_error * gotweb_render_tags(struct request *c) { const struct got_error *error = NULL; - struct repo_tag *rt = NULL; struct server *srv = c->srv; struct transport *t = c->t; struct querystring *qs = t->qs; - struct repo_dir *repo_dir = t->repo_dir; - char *age = NULL, *tagname = NULL, *msg = NULL, *newline; - int r, commit_found = 0; if (qs->action == BRIEFS) { qs->action = TAGS; @@ -1347,126 +1343,10 @@ gotweb_render_tags(struct request *c) if (error) goto done; - r = fcgi_printf(c, "
\n" - "
Tags
\n" - "
\n" /* #tags_title_wrapper */ - "
\n"); - if (r == -1) + if (gotweb_render_tags_tmpl(c->tp) == -1) goto done; - - if (t->tag_count == 0) { - r = fcgi_printf(c, "
%s\n
\n", - "This repository contains no tags"); - if (r == -1) - goto done; - } - - TAILQ_FOREACH(rt, &t->repo_tags, entry) { - if (commit_found == 0 && qs->commit != NULL) { - if (strcmp(qs->commit, rt->commit_id) != 0) - continue; - else - commit_found = 1; - } - error = gotweb_get_time_str(&age, rt->tagger_time, TM_DIFF); - if (error) - goto done; - - tagname = rt->tag_name; - if (strncmp(tagname, "refs/tags/", 10) == 0) - tagname += 10; - error = gotweb_escape_html(&tagname, tagname); - if (error) - goto done; - - if (rt->tag_commit != NULL) { - newline = strchr(rt->tag_commit, '\n'); - if (newline) - *newline = '\0'; - error = gotweb_escape_html(&msg, rt->tag_commit); - if (error) - goto done; - } - - if (fcgi_printf(c, "
%s
\n" - "
%s
\n" - "
", age, tagname) == -1) - goto done; - - r = gotweb_link(c, &(struct gotweb_url){ - .action = TAG, - .index_page = -1, - .page = -1, - .path = repo_dir->name, - .commit = rt->commit_id, - }, "%s", msg ? msg : ""); - if (r == -1) - goto done; - - if (fcgi_printf(c, "
\n" /* .tag_log */ - "\n" /* .navs_wrapper */ - "
\n"); - if (r == -1) - goto done; - - free(age); - age = NULL; - free(tagname); - tagname = NULL; - free(msg); - msg = NULL; - } - if (t->next_id || t->prev_id) { - if (gotweb_render_navs(c->tp) == -1) - goto done; - } - fcgi_printf(c, "
\n"); /* #tags_content */ done: - free(age); - free(tagname); - free(msg); return error; } blob - e633c57fe7cd48fed7a5ed3beb070b4acddc97c9 blob + 82411f713d7bde00ef0d95f07bf0b914771735ed --- gotwebd/gotwebd.h +++ gotwebd/gotwebd.h @@ -469,6 +469,7 @@ int gotweb_render_navs(struct template *); int gotweb_render_commits(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_rss(struct template *); /* parse.y */ blob - 4990d4532fe8a87678d718337343c8101501b84d blob + 8bf0a13026da2c453ceba474ad9e4fd12b90c713 --- gotwebd/pages.tmpl +++ gotwebd/pages.tmpl @@ -39,6 +39,7 @@ static int gotweb_render_blob_line(struct template *, const char *, size_t); static int gotweb_render_tree_item(struct template *, struct got_tree_entry *); +static inline int tag_item(struct template *, struct repo_tag *); static inline int rss_tag_item(struct template *, struct repo_tag *); static inline int rss_author(struct template *, char *); @@ -565,9 +566,89 @@ gotweb_render_age(struct template *tp, time_t time, in {{ finally }} {! free(dir); +!} +{{ end }} + +{{ define gotweb_render_tags_tmpl(struct template *tp) }} +{! + struct request *c = tp->tp_arg; + struct transport *t = c->t; + struct querystring *qs = t->qs; + struct repo_tag *rt; + int commit_found; + + commit_found = qs->commit == NULL; !} +
+
Tags
+
+
+ {{ if t->tag_count == 0 }} +
+ This repository contains no tags +
+ {{ else }} + {{ tailq-foreach rt &t->repo_tags entry }} + {{ if commit_found || !strcmp(qs->commit, rt->commit_id) }} + {! commit_found = 1; !} + {{ render tag_item(tp, rt) }} + {{ end }} + {{ end }} + {{ if t->next_id || t->prev_id }} + {{ render gotweb_render_navs(tp) }} + {{ end }} + {{ end }} +
{{ end }} +{{ define tag_item(struct template *tp, struct repo_tag *rt) }} +{! + struct request *c = tp->tp_arg; + struct transport *t = c->t; + struct repo_dir *repo_dir = t->repo_dir; + char *tag_name = rt->tag_name; + char *msg = rt->tag_commit; + char *nl; + struct gotweb_url url = { + .action = TAG, + .index_page = -1, + .page = -1, + .path = repo_dir->name, + .commit = rt->commit_id, + }; + + if (strncmp(tag_name, "refs/tags/", 10) == 0) + tag_name += 10; + + if (msg) { + nl = strchr(msg, '\n'); + if (nl) + *nl = '\0'; + } +!} +
+ {{ render gotweb_render_age(tp, rt->tagger_time, TM_DIFF) }} +
+
{{ tag_name }}
+
+ + {{ msg }} + +
+ +
+{{ end }} + {{ define gotweb_render_rss(struct template *tp) }} {! struct request *c = tp->tp_arg;