commit 156a11447a870d2128d6ddce97013fca0cfd4e6a from: Omar Polo date: Sat Dec 17 08:30:00 2022 UTC gotwebd: templateify gotweb_render_commits ok tracey@ commit - b4c0bd7275f121f6250964ddfdf8db160ad486df commit + 156a11447a870d2128d6ddce97013fca0cfd4e6a blob - 11f9c0394c8740b1306c0b3f5747079bbc1ad448 blob + 28042467bba28194c9543f1b05ca9cfc5cfd644e --- gotwebd/gotweb.c +++ gotwebd/gotweb.c @@ -91,7 +91,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_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); @@ -930,110 +931,6 @@ done: } 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 - ca24af3793aac515e3a3c00a8b6bcfc8e32cb5e8 blob + fc3b18bef37416ee4320885e46d8707a3291f6c2 --- gotwebd/gotwebd.h +++ gotwebd/gotwebd.h @@ -456,6 +456,7 @@ int gotweb_render_repo_table_hdr(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 blob + 6aca4b90f64838bba5e10738d6af4e2a01509ebf --- 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 }}