Download raw body.
gotwebd: templateify gotweb_render_summary
On 23-01-12 01:00PM, Omar Polo wrote: > 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? 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, "<div id='summary_wrapper'>\n") == -1) > - goto done; > - > - if (srv->show_repo_description) { > - r = fcgi_printf(c, > - "<div id='description_title'>Description:</div>\n" > - "<div id='description'>%s</div>\n", > - t->repo_dir->description ? t->repo_dir->description : ""); > - if (r == -1) > - goto done; > - } > - > - if (srv->show_repo_owner) { > - r = fcgi_printf(c, > - "<div id='repo_owner_title'>Owner:</div>\n" > - "<div id='repo_owner'>%s</div>\n", > - t->repo_dir->owner ? t->repo_dir->owner : ""); > - if (r == -1) > - goto done; > - } > - > - if (srv->show_repo_age) { > - r = fcgi_printf(c, > - "<div id='last_change_title'>Last Change:</div>\n" > - "<div id='last_change'>%s</div>\n", > - t->repo_dir->age); > - if (r == -1) > - goto done; > - } > - > - if (srv->show_repo_cloneurl) { > - r = fcgi_printf(c, > - "<div id='cloneurl_title'>Clone URL:</div>\n" > - "<div id='cloneurl'>%s</div>\n", > - t->repo_dir->url ? t->repo_dir->url : ""); > - if (r == -1) > - goto done; > - } > - > - r = fcgi_printf(c, "</div>\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; > +!} > +<div id="summary_wrapper"> > + {{ if srv->show_repo_description }} > + <div id="description_title">Description:</div> > + <div id="description">{{ t->repo_dir->description }}</div> > + {{ end }} > + {{ if srv->show_repo_owner }} > + <div id="repo_owner_title">Owner:</div> > + <div id="repo_owner">{{ t->repo_dir->owner }}</div> > + {{ end }} > + {{ if srv->show_repo_age }} > + <div id="last_change_title">Last Change:</div> > + <div id="last_change">{{ t->repo_dir->age }}</div> > + {{ end }} > + {{ if srv->show_repo_cloneurl }} > + <div id="cloneurl_title">Clone URL:</div> > + <div id="cloneurl">{{ t->repo_dir->url }}</div> > + {{ end }} > +</div> > +{{ 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; > -- Mark Jamsek <fnc.bsdbox.org> GPG: F2FF 13DE 6A06 C471 CA80 E6E2 2930 DC66 86EE CF68
gotwebd: templateify gotweb_render_summary