commit 18e466eb6a2dc223f99d645f35ebf2f2f44a9f77 from: Omar Polo via: Thomas Adam date: Sat Jan 14 16:45:29 2023 UTC gotwebd: templateify gotweb_render_summary ok jamsek commit - b3ba36c380dd6686b46f27d33ed4e8ee67d7426d commit + 18e466eb6a2dc223f99d645f35ebf2f2f44a9f77 blob - b0990fa5496b65df45995ab15153323795171ee9 blob + 89835b809483926295d4f94fdd520e86acc5b32e --- gotwebd/gotweb.c +++ gotwebd/gotweb.c @@ -95,7 +95,6 @@ static const struct got_error *gotweb_get_repo_descrip 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 *); @@ -110,9 +109,12 @@ 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); @@ -289,11 +291,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); @@ -365,6 +379,8 @@ done: close(fd); if (html && srv != NULL) gotweb_render_footer(c->tp); + + got_ref_list_free(&refs); } struct server * @@ -1009,84 +1025,6 @@ gotweb_render_blame(struct request *c) done: free(age); free(msg); - 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; } blob - c625c27f2bee1409fe6562219936a8d0e9948a55 blob + 94bb71fb582793f9bab63b019ba12be89ea61ef1 --- gotwebd/gotwebd.h +++ gotwebd/gotwebd.h @@ -476,6 +476,7 @@ int gotweb_render_tags(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 - 086325e9d628e2ff56488783ccdc6d871efc5089 blob + dc3656edae244fbc586f81ad359f6b9ca8c8085d --- gotwebd/pages.tmpl +++ gotwebd/pages.tmpl @@ -837,6 +837,36 @@ gotweb_render_age(struct template *tp, time_t time, in {{ finally }} {! 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) }}