From: Omar Polo Subject: templateify gotweb_render_commits To: gameoftrees@openbsd.org Date: Fri, 16 Dec 2022 18:16:03 +0100 Hello, this moves gotweb_render_commits to a template. got_get_repo_commits is moved out of the rendering function and up one level. this builds on the 'templateify gotweb_render_navs' diff i sent previously: http://marc.gameoftrees.org/mail/1671103845.4694_0.html as usual, my gotwebd instance is running with this and the previous diff applied. diff /home/op/w/got commit - 1a50a0817bda55dbe41130e06e50d537632465f6 path + /home/op/w/got blob - 85a4ee7974b69efd0c56c02dc288ecf6e719fc21 file + gotwebd/gotweb.c --- gotwebd/gotweb.c +++ gotwebd/gotweb.c @@ -91,7 +91,6 @@ static const struct got_error *gotweb_render_commits(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_commits(struct request *); static const struct got_error *gotweb_render_diff(struct request *); static const struct got_error *gotweb_render_summary(struct request *); static const struct got_error *gotweb_render_tag(struct request *); @@ -207,11 +206,13 @@ render: goto err; break; case COMMITS: - error = gotweb_render_commits(c); + error = got_get_repo_commits(c, srv->max_commits_display); if (error) { log_warnx("%s: %s", __func__, error->msg); goto err; } + if (gotweb_render_commits(c->tp) == -1) + goto err; break; case DIFF: error = gotweb_render_diff(c); @@ -949,110 +950,6 @@ gotweb_render_commits(struct request *c) } static const struct got_error * -gotweb_render_commits(struct request *c) -{ - const struct got_error *error = NULL; - struct repo_commit *rc = NULL; - struct server *srv = c->srv; - struct transport *t = c->t; - struct repo_dir *repo_dir = t->repo_dir; - char *age = NULL, *author = NULL, *msg = NULL; - int r; - - r = fcgi_printf(c, "
\n" - "
Commits
\n" - "
\n" /* .commits_title_wrapper */ - "
\n"); - if (r == -1) - goto done; - - error = got_get_repo_commits(c, srv->max_commits_display); - if (error) - goto done; - - TAILQ_FOREACH(rc, &t->repo_commits, entry) { - error = gotweb_get_time_str(&age, rc->committer_time, TM_LONG); - if (error) - goto done; - error = gotweb_escape_html(&author, rc->author); - if (error) - goto done; - error = gotweb_escape_html(&msg, rc->commit_msg); - if (error) - goto done; - - r = fcgi_printf(c, "
\n" - "
\n" - "
Commit:
\n" - "
%s
\n" - "
Author:
\n" - "
%s
\n" - "
Date:
\n" - "
%s
\n" - "
\n" /* .commits_header */ - "
\n" /* .commits_header_wrapper */ - "
\n" - "
\n%s
\n", - rc->commit_id, - author, - age, - msg); - if (r == -1) - goto done; - - if (fcgi_printf(c, "\n" /* .navs_wrapper */ - "
\n") == -1) - goto done; - - free(age); - age = NULL; - free(author); - author = NULL; - free(msg); - msg = NULL; - } - - if (t->next_id || t->prev_id) { - if (gotweb_render_navs(c->tp) == -1) - goto done; - } - fcgi_printf(c, "
\n"); /* .commits_content */ -done: - free(age); - free(author); - free(msg); - return error; -} - -static const struct got_error * gotweb_render_branches(struct request *c) { const struct got_error *error = NULL; blob - 700307a1481fa9b5b991ba6ed6090d29566a7cd0 file + gotwebd/gotwebd.h --- gotwebd/gotwebd.h +++ gotwebd/gotwebd.h @@ -458,6 +458,7 @@ int gotweb_render_navs(struct template *); int gotweb_render_repo_fragment(struct template *, struct repo_dir *); int gotweb_render_briefs(struct template *); int gotweb_render_navs(struct template *); +int gotweb_render_commits(struct template *); /* parse.y */ int parse_config(const char *, struct gotwebd *); blob - 88158c157c6d585b1e9692319e29e9bbe08f9390 file + gotwebd/pages.tmpl --- gotwebd/pages.tmpl +++ gotwebd/pages.tmpl @@ -332,3 +332,60 @@ gotweb_render_age(struct template *tp, time_t time, in t->prev_id = NULL; !} {{ end }} + +{{ define gotweb_render_commits(struct template *tp) }} +{! + struct request *c = tp->tp_arg; + struct transport *t = c->t; + struct repo_dir *repo_dir = t->repo_dir; + struct repo_commit *rc; + struct gotweb_url diff, tree; + + diff = (struct gotweb_url){ + .action = DIFF, + .index_page = -1, + .page = -1, + .path = repo_dir->name, + }; + tree = (struct gotweb_url){ + .action = TREE, + .index_page = -1, + .page = -1, + .path = repo_dir->name, + }; +!} +
+
Commits
+
+
+ {{ tailq-foreach rc &t->repo_commits entry }} + {! + diff.commit = rc->commit_id; + tree.commit = rc->commit_id; + !} +
+
+
Commit:
+
{{ rc->commit_id }}
+
Author:
+
{{ rc->author }}
+
Date:
+
+ {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }} +
+
+
+ +
+ {{ end }} + {{ if t->next_id || t->prev_id }} + {{ render gotweb_render_navs(tp) }} + {{ end }} +
+{{ end }}