From: Omar Polo Subject: gotwebd: templateify gotweb_render_summary To: gameoftrees@openbsd.org Date: Thu, 12 Jan 2023 13:00:49 +0100 builds on top of the previous patch, the one about bubbling up got_get_repo_tags. It bubbles up (again) some data-gathering from gotweb_render_summary into process_request and converts the rest of the function into a template. My instance is running with both these patches applied. With this, only blame (and the error page) remains to be converted. Then, we'll be able to simplify gotweb_process_request too a bit, and to return proper error codes on failure. ok? diff /home/op/w/got commit - 8ae7d7781d10f2b2870070820a029577fd0b2a67 path + /home/op/w/got blob - a5a97c6e5785b315b3954c84805bfe1df0543a44 file + gotwebd/gotweb.c --- gotwebd/gotweb.c +++ gotwebd/gotweb.c @@ -94,7 +94,6 @@ static const struct got_error *gotweb_render_summary(s static const struct got_error *gotweb_get_clone_url(char **, struct server *, const char *, int); static const struct got_error *gotweb_render_blame(struct request *); -static const struct got_error *gotweb_render_summary(struct request *); static void gotweb_free_querystring(struct querystring *); static void gotweb_free_repo_dir(struct repo_dir *); @@ -109,10 +108,13 @@ gotweb_process_request(struct request *c) struct server *srv = NULL; struct querystring *qs = NULL; struct repo_dir *repo_dir = NULL; + struct got_reflist_head refs; FILE *fp = NULL; uint8_t err[] = "gotwebd experienced an error: "; int r, html = 0, fd = -1; + TAILQ_INIT(&refs); + /* init the transport */ error = gotweb_init_transport(&c->t); if (error) { @@ -288,11 +290,23 @@ render: } break; case SUMMARY: - error = gotweb_render_summary(c); + error = got_ref_list(&refs, c->t->repo, "refs/heads", + got_ref_cmp_by_name, NULL); if (error) { - log_warnx("%s: %s", __func__, error->msg); + log_warnx("%s: got_ref_list: %s", __func__, + error->msg); goto err; } + qs->action = TAGS; + error = got_get_repo_tags(c, D_MAXSLCOMMDISP); + if (error) { + log_warnx("%s: got_get_repo_tags: %s", __func__, + error->msg); + goto err; + } + qs->action = SUMMARY; + if (gotweb_render_summary(c->tp, &refs) == -1) + goto done; break; case TAG: error = got_get_repo_tags(c, 1); @@ -364,6 +378,8 @@ done: close(fd); if (html && srv != NULL) gotweb_render_footer(c->tp); + + got_ref_list_free(&refs); } struct server * @@ -1011,84 +1027,6 @@ static const struct got_error * return error; } -static const struct got_error * -gotweb_render_summary(struct request *c) -{ - const struct got_error *error = NULL; - struct got_reflist_head refs; - struct transport *t = c->t; - struct querystring *qs = t->qs; - struct got_repository *repo = t->repo; - struct server *srv = c->srv; - int r; - - TAILQ_INIT(&refs); - - error = got_ref_list(&refs, repo, "refs/heads", - got_ref_cmp_by_name, NULL); - if (error) - goto done; - - if (fcgi_printf(c, "
\n") == -1) - goto done; - - if (srv->show_repo_description) { - r = fcgi_printf(c, - "
Description:
\n" - "
%s
\n", - t->repo_dir->description ? t->repo_dir->description : ""); - if (r == -1) - goto done; - } - - if (srv->show_repo_owner) { - r = fcgi_printf(c, - "
Owner:
\n" - "
%s
\n", - t->repo_dir->owner ? t->repo_dir->owner : ""); - if (r == -1) - goto done; - } - - if (srv->show_repo_age) { - r = fcgi_printf(c, - "
Last Change:
\n" - "
%s
\n", - t->repo_dir->age); - if (r == -1) - goto done; - } - - if (srv->show_repo_cloneurl) { - r = fcgi_printf(c, - "
Clone URL:
\n" - "
%s
\n", - t->repo_dir->url ? t->repo_dir->url : ""); - if (r == -1) - goto done; - } - - r = fcgi_printf(c, "
\n"); /* #summary_wrapper */ - if (r == -1) - goto done; - - if (gotweb_render_briefs(c->tp) == -1) - goto done; - - qs->action = TAGS; - error = got_get_repo_tags(c, D_MAXSLCOMMDISP); - if (error) - goto done; - - if (gotweb_render_tags(c->tp) == -1) - goto done; - - gotweb_render_branches(c->tp, &refs); -done: - got_ref_list_free(&refs); - return error; -} - const struct got_error * gotweb_escape_html(char **escaped_html, const char *orig_html) { blob - 23e9968ddbd0cb2c3610a66a962d4d36e4732208 file + gotwebd/gotwebd.h --- gotwebd/gotwebd.h +++ gotwebd/gotwebd.h @@ -474,6 +474,7 @@ int gotweb_render_rss(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_summary(struct template *, struct got_reflist_head *); int gotweb_render_rss(struct template *); /* parse.y */ blob - f915e92c66d33c3821c4e30fb4e0860aaa53d2bc file + gotwebd/pages.tmpl --- gotwebd/pages.tmpl +++ gotwebd/pages.tmpl @@ -840,6 +840,36 @@ gotweb_render_age(struct template *tp, time_t time, in {! free(age); !} {{ end }} +{{ define gotweb_render_summary(struct template *tp, + struct got_reflist_head *refs) }} +{! + struct request *c = tp->tp_arg; + struct server *srv = c->srv; + struct transport *t = c->t; +!} +
+ {{ if srv->show_repo_description }} +
Description:
+
{{ t->repo_dir->description }}
+ {{ end }} + {{ if srv->show_repo_owner }} +
Owner:
+
{{ t->repo_dir->owner }}
+ {{ end }} + {{ if srv->show_repo_age }} +
Last Change:
+
{{ t->repo_dir->age }}
+ {{ end }} + {{ if srv->show_repo_cloneurl }} +
Clone URL:
+
{{ t->repo_dir->url }}
+ {{ end }} +
+{{ render gotweb_render_briefs(tp) }} +{{ render gotweb_render_tags(tp) }} +{{ render gotweb_render_branches(tp, refs) }} +{{ end }} + {{ define gotweb_render_rss(struct template *tp) }} {! struct request *c = tp->tp_arg;