commit 00abe30b6011e389018622a47995f9390b166182 from: Omar Polo via: Thomas Adam date: Sat Jan 14 16:45:29 2023 UTC gotwebd: templateify gotweb_render_branches no functional change intended. Bubble up the allocation of the reflist from gotweb_render_branches to gotweb_render_summary (its only caller) and rewrite it as a template. ok tracey@ commit - 92a569072371e5e179a2b20bf0b80990f42f4038 commit + 00abe30b6011e389018622a47995f9390b166182 blob - 0aaee33b34d4307c8d7df683a17c20a159cc2b57 blob + ecb30578057b82335c755ebafb9d9c1fdd24cf97 --- gotwebd/gotweb.c +++ gotwebd/gotweb.c @@ -97,7 +97,6 @@ static const struct got_error *gotweb_get_clone_url(ch 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 *); @@ -1013,16 +1012,13 @@ done: } 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 got_repository *repo = t->repo; + struct server *srv = c->srv; int r; TAILQ_INIT(&refs); @@ -1031,124 +1027,7 @@ gotweb_render_branches(struct request *c) got_ref_cmp_by_name, NULL); if (error) goto done; - - r = fcgi_printf(c, "
\n" - "
Branches
\n" - "
\n" /* #branches_title_wrapper */ - "
\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, "
\n" - "
%s
\n" - "
 
\n" - "
", 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, "
\n" /* .branch */ - "\n" /* .navs_wrapper */ - "
\n" - "
\n"); /* .branches_wrapper */ - if (r == -1) - goto done; - - free(age); - age = NULL; - free(escaped_refname); - escaped_refname = NULL; - } - fcgi_printf(c, "
\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, "
\n") == -1) goto done; @@ -1201,10 +1080,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 - 65e48fe2675590393e47fbe9907d11d81c91340c blob + 01a426c9ded760150f5157900a24d3874a0f178d --- gotwebd/gotwebd.h +++ gotwebd/gotwebd.h @@ -120,6 +120,7 @@ /* Forward declaration */ struct got_blob_object; struct got_tree_entry; +struct got_reflist_head; enum imsg_type { IMSG_CFG_SRV = IMSG_PROC_MAX, @@ -474,6 +475,7 @@ int gotweb_render_tree(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 - 8d491248536264e58b0f129b544f0fbff2c4066f blob + 1ee4d93d857e50deb09f255fd23369630dd7c910 --- gotwebd/pages.tmpl +++ gotwebd/pages.tmpl @@ -28,8 +28,9 @@ #include #include -#include "got_compat.h" +#include "got_error.h" #include "got_object.h" +#include "got_reference.h" #include "proc.h" @@ -41,6 +42,7 @@ static int gotweb_render_tree_item(struct template *, 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 +772,73 @@ gotweb_render_age(struct template *tp, time_t time, in
{{ line }}
{{ end }} +{{ define gotweb_render_branches(struct template *tp, + struct got_reflist_head *refs) }} +{! + struct got_reflist_entry *re; +!} +
+
Branches
+
+
+ {{ tailq-foreach re refs entry }} + {{ if !got_ref_is_symbolic(re->ref) }} + {{ render branch(tp, re) }} + {{ end }} + {{ end }} +
+{{ 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; +!} +
+
{{ age }}
+
 
+ + +
+
+{{ finally }} +{! free(age); !} +{{ end }} + {{ define gotweb_render_rss(struct template *tp) }} {! struct request *c = tp->tp_arg;