Download raw body.
templateify gotweb_render_tags
As the other diff, this shouldn't introduce any change and should be pretty strightforward. Unlike other 'templatefications' however I couldn't just bubble up the call to got_get_repo_tags to gotweb_process_request since gotweb_render_tags is called by a few places; that's why I kept gotweb_render_tags and introduced gotweb_render_tags_tmpl to do the hard work. ok? P.S.: the diff to templateify the diff page is still pending :) diff /home/op/w/got commit - 1a99e0b4097b26cac736de07239a3be7589a48f7 path + /home/op/w/got blob - a8fdd952ec48f1a229440e115de67205cf20f049 file + gotwebd/gotweb.c --- gotwebd/gotweb.c +++ gotwebd/gotweb.c @@ -1331,13 +1331,9 @@ gotweb_render_tags(struct request *c) 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, "<div id='tags_title_wrapper'>\n" - "<div id='tags_title'>Tags</div>\n" - "</div>\n" /* #tags_title_wrapper */ - "<div id='tags_content'>\n"); - if (r == -1) + if (gotweb_render_tags_tmpl(c->tp) == -1) goto done; - if (t->tag_count == 0) { - r = fcgi_printf(c, "<div id='err_content'>%s\n</div>\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, "<div class='tag_age'>%s</div>\n" - "<div class='tag'>%s</div>\n" - "<div class='tag_log'>", 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, "</div>\n" /* .tag_log */ - "<div class='navs_wrapper'>\n" - "<div class='navs'>") == -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, - }, "tag"); - if (r == -1) - goto done; - - if (fcgi_printf(c, " | ") == -1) - goto done; - - r = gotweb_link(c, &(struct gotweb_url){ - .action = BRIEFS, - .index_page = -1, - .page = -1, - .path = repo_dir->name, - .commit = rt->commit_id, - }, "commit briefs"); - if (r == -1) - goto done; - - if (fcgi_printf(c, " | ") == -1) - goto done; - - r = gotweb_link(c, &(struct gotweb_url){ - .action = COMMITS, - .index_page = -1, - .page = -1, - .path = repo_dir->name, - .commit = rt->commit_id, - }, "commits"); - if (r == -1) - goto done; - - r = fcgi_printf(c, - "</div>\n" /* .navs */ - "</div>\n" /* .navs_wrapper */ - "<div class='dotted_line'></div>\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, "</div>\n"); /* #tags_content */ done: - free(age); - free(tagname); - free(msg); return error; } blob - e633c57fe7cd48fed7a5ed3beb070b4acddc97c9 file + gotwebd/gotwebd.h --- gotwebd/gotwebd.h +++ gotwebd/gotwebd.h @@ -469,6 +469,7 @@ int gotweb_render_rss(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 file + gotwebd/pages.tmpl --- gotwebd/pages.tmpl +++ gotwebd/pages.tmpl @@ -39,6 +39,7 @@ static inline int rss_tag_item(struct template *, stru 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 *); @@ -568,6 +569,86 @@ gotweb_render_age(struct template *tp, time_t time, in !} {{ 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; +!} +<div id="tags_title_wrapper"> + <div id="tags_title">Tags</div> +</div> +<div id="tags_content"> + {{ if t->tag_count == 0 }} + <div id="err_content"> + This repository contains no tags + </div> + {{ 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 }} +</div> +{{ 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(rt->tag_commit, '\n'); + if (nl) + *nl = '\0'; + } +!} +<div class="tag_age"> + {{ render gotweb_render_age(tp, rt->tagger_time, TM_DIFF) }} +</div> +<div class="tag">{{ tag_name }}</div> +<div class="tag_log"> + <a href="{{ render gotweb_render_url(c, &url) }}"> + {{ msg }} + </a> +</div> +<div class="navs_wrapper"> + <div class="navs"> + <a href="{{ render gotweb_render_url(c, &url) }}">tag</a> + {{ " | " }} + {! url.action = BRIEFS; !} + <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a> + {{ " | " }} + {! url.action = COMMITS; !} + <a href="{{ render gotweb_render_url(c, &url) }}">commits</a> + </div> +</div> +<div class="dotted_line"></div> +{{ end }} + {{ define gotweb_render_rss(struct template *tp) }} {! struct request *c = tp->tp_arg;
templateify gotweb_render_tags