Download raw body.
gotwebd: templateify gotweb_render_branches
On Wed, Jan 11, 2023 at 02:04:53PM +0100, Omar Polo wrote:
> as usual, no functional change intended. my instance is running with
> this applied.
>
> The allocation of the reflist is moved to from gotweb_render_branches
> to gotweb_render_summary (its only caller.)
>
> We're almost done! With this only gotweb_render_summary and blame
> remains to convert still.
ok
>
> diff /home/op/w/got
> commit - 5fa52d6cdcc6de872ce3c7f6639cc638fd83eeea
> path + /home/op/w/got
> blob - 539e06b6f8271d8b51ac64fbfe665a5ad7a4a1ae
> file + gotwebd/gotweb.c
> --- gotwebd/gotweb.c
> +++ gotwebd/gotweb.c
> @@ -96,7 +96,6 @@ static const struct got_error *gotweb_render_branches(
> static const struct got_error *gotweb_render_blame(struct request *);
> static const struct got_error *gotweb_render_summary(struct request *);
> static const struct got_error *gotweb_render_tags(struct request *);
> -static const struct got_error *gotweb_render_branches(struct request *);
>
> static void gotweb_free_querystring(struct querystring *);
> static void gotweb_free_repo_dir(struct repo_dir *);
> @@ -1012,16 +1011,13 @@ gotweb_render_branches(struct request *c)
> }
>
> static const struct got_error *
> -gotweb_render_branches(struct request *c)
> +gotweb_render_summary(struct request *c)
> {
> const struct got_error *error = NULL;
> struct got_reflist_head refs;
> - struct got_reflist_entry *re;
> struct transport *t = c->t;
> - struct querystring *qs = t->qs;
> struct got_repository *repo = t->repo;
> - char *escaped_refname = NULL;
> - char *age = NULL;
> + struct server *srv = c->srv;
> int r;
>
> TAILQ_INIT(&refs);
> @@ -1031,123 +1027,6 @@ gotweb_render_branches(struct request *c)
> if (error)
> goto done;
>
> - r = fcgi_printf(c, "<div id='branches_title_wrapper'>\n"
> - "<div id='branches_title'>Branches</div>\n"
> - "</div>\n" /* #branches_title_wrapper */
> - "<div id='branches_content'>\n");
> - if (r == -1)
> - goto done;
> -
> - TAILQ_FOREACH(re, &refs, entry) {
> - const char *refname = NULL;
> -
> - if (got_ref_is_symbolic(re->ref))
> - continue;
> -
> - refname = got_ref_get_name(re->ref);
> - if (refname == NULL) {
> - error = got_error_from_errno("strdup");
> - goto done;
> - }
> - if (strncmp(refname, "refs/heads/", 11) != 0)
> - continue;
> -
> - error = got_get_repo_age(&age, c, refname, TM_DIFF);
> - if (error)
> - goto done;
> -
> - if (strncmp(refname, "refs/heads/", 11) == 0)
> - refname += 11;
> - error = gotweb_escape_html(&escaped_refname, refname);
> - if (error)
> - goto done;
> -
> - r = fcgi_printf(c, "<div class='branches_wrapper'>\n"
> - "<div class='branches_age'>%s</div>\n"
> - "<div class='branches_space'> </div>\n"
> - "<div class='branch'>", age);
> - if (r == -1)
> - goto done;
> -
> - r = gotweb_link(c, &(struct gotweb_url){
> - .action = SUMMARY,
> - .index_page = -1,
> - .page = -1,
> - .path = qs->path,
> - .headref = refname,
> - }, "%s", escaped_refname);
> - if (r == -1)
> - goto done;
> -
> - if (fcgi_printf(c, "</div>\n" /* .branch */
> - "<div class='navs_wrapper'>\n"
> - "<div class='navs'>") == -1)
> - goto done;
> -
> - r = gotweb_link(c, &(struct gotweb_url){
> - .action = SUMMARY,
> - .index_page = -1,
> - .page = -1,
> - .path = qs->path,
> - .headref = refname,
> - }, "summary");
> - 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 = qs->path,
> - .headref = refname,
> - }, "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 = qs->path,
> - .headref = refname,
> - }, "commits");
> - if (r == -1)
> - goto done;
> -
> - r = fcgi_printf(c, "</div>\n" /* .navs */
> - "</div>\n" /* .navs_wrapper */
> - "<div class='dotted_line'></div>\n"
> - "</div>\n"); /* .branches_wrapper */
> - if (r == -1)
> - goto done;
> -
> - free(age);
> - age = NULL;
> - free(escaped_refname);
> - escaped_refname = NULL;
> - }
> - fcgi_printf(c, "</div>\n"); /* #branches_content */
> -done:
> - free(age);
> - free(escaped_refname);
> - got_ref_list_free(&refs);
> - return error;
> -}
> -
> -static const struct got_error *
> -gotweb_render_summary(struct request *c)
> -{
> - const struct got_error *error = NULL;
> - struct transport *t = c->t;
> - struct server *srv = c->srv;
> - int r;
> -
> if (fcgi_printf(c, "<div id='summary_wrapper'>\n") == -1)
> goto done;
>
> @@ -1200,10 +1079,9 @@ gotweb_render_summary(struct request *c)
> goto done;
> }
>
> - error = gotweb_render_branches(c);
> - if (error)
> - log_warnx("%s: %s", __func__, error->msg);
> + gotweb_render_branches(c->tp, &refs);
> done:
> + got_ref_list_free(&refs);
> return error;
> }
>
> blob - e19e34593996941a09c53036aa3d995fb6867118
> file + gotwebd/gotwebd.h
> --- gotwebd/gotwebd.h
> +++ gotwebd/gotwebd.h
> @@ -118,6 +118,7 @@ struct got_tree_entry;
> /* Forward declaration */
> struct got_blob_object;
> struct got_tree_entry;
> +struct got_reflist_head;
>
> enum imsg_type {
> IMSG_CFG_SRV = IMSG_PROC_MAX,
> @@ -472,6 +473,7 @@ int gotweb_render_rss(struct template *);
> int gotweb_render_tags_tmpl(struct template *);
> int gotweb_render_tag(struct template *);
> int gotweb_render_diff(struct template *, FILE *);
> +int gotweb_render_branches(struct template *, struct got_reflist_head *);
> int gotweb_render_rss(struct template *);
>
> /* parse.y */
> blob - 3501ce16a0c13174e3e6a1d4fc06358a7b345061
> file + gotwebd/pages.tmpl
> --- gotwebd/pages.tmpl
> +++ gotwebd/pages.tmpl
> @@ -29,7 +29,9 @@
> #include <sha1.h>
> #include <imsg.h>
>
> +#include "got_error.h"
> #include "got_object.h"
> +#include "got_reference.h"
>
> #include "proc.h"
>
> @@ -41,6 +43,7 @@ static inline int rss_tag_item(struct template *, stru
>
> static inline int diff_line(struct template *, char *);
> static inline int tag_item(struct template *, struct repo_tag *);
> +static inline int branch(struct template *, struct got_reflist_entry *);
> static inline int rss_tag_item(struct template *, struct repo_tag *);
> static inline int rss_author(struct template *, char *);
>
> @@ -770,6 +773,73 @@ gotweb_render_age(struct template *tp, time_t time, in
> <div class="diff_line {{ color }}">{{ line }}</div>
> {{ end }}
>
> +{{ define gotweb_render_branches(struct template *tp,
> + struct got_reflist_head *refs) }}
> +{!
> + struct got_reflist_entry *re;
> +!}
> +<div id="branches_title_wrapper">
> + <div id="branches_title">Branches</div>
> +</div>
> +<div id="branches_content">
> + {{ tailq-foreach re refs entry }}
> + {{ if !got_ref_is_symbolic(re->ref) }}
> + {{ render branch(tp, re) }}
> + {{ end }}
> + {{ end }}
> +</div>
> +{{ end }}
> +
> +{{ define branch(struct template *tp, struct got_reflist_entry *re) }}
> +{!
> + const struct got_error *err;
> + struct request *c = tp->tp_arg;
> + struct querystring *qs = c->t->qs;
> + const char *refname;
> + char *age = NULL;
> + struct gotweb_url url = {
> + .action = SUMMARY,
> + .index_page = -1,
> + .page = -1,
> + .path = qs->path,
> + };
> +
> + refname = got_ref_get_name(re->ref);
> +
> + err = got_get_repo_age(&age, c, refname, TM_DIFF);
> + if (err) {
> + log_warnx("%s: %s", __func__, err->msg);
> + return -1;
> + }
> +
> + if (strncmp(refname, "refs/heads/", 11) == 0)
> + refname += 11;
> +
> + url.headref = refname;
> +!}
> +<div class="branches_wrapper">
> + <div class="branches_age">{{ age }}</div>
> + <div class="branches_space"> </div>
> + <div class="branch">
> + <a href="{{ render gotweb_render_url(c, &url) }}">{{ refname }}</a>
> + </div>
> + <div class="navs_wrapper">
> + <div class="navs">
> + <a href="{{ render gotweb_render_url(c, &url) }}">summary</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>
> +</div>
> +{{ finally }}
> +{! free(age); !}
> +{{ end }}
> +
> {{ define gotweb_render_rss(struct template *tp) }}
> {!
> struct request *c = tp->tp_arg;
>
--
Tracey Emery
gotwebd: templateify gotweb_render_branches