Download raw body.
templateify gotweb_render_commits
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, "<div class='commits_title_wrapper'>\n" - "<div class='commits_title'>Commits</div>\n" - "</div>\n" /* .commits_title_wrapper */ - "<div class='commits_content'>\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, "<div class='commits_header_wrapper'>\n" - "<div class='commits_header'>\n" - "<div class='header_commit_title'>Commit:</div>\n" - "<div class='header_commit'>%s</div>\n" - "<div class='header_author_title'>Author:</div>\n" - "<div class='header_author'>%s</div>\n" - "<div class='header_age_title'>Date:</div>\n" - "<div class='header_age'>%s</div>\n" - "</div>\n" /* .commits_header */ - "</div>\n" /* .commits_header_wrapper */ - "<div class='dotted_line'></div>\n" - "<div class='commit'>\n%s</div>\n", - rc->commit_id, - author, - age, - msg); - if (r == -1) - goto done; - - if (fcgi_printf(c, "<div class='navs_wrapper'>\n" - "<div class='navs'>") == -1) - goto done; - - r = gotweb_link(c, &(struct gotweb_url){ - .action = DIFF, - .index_page = -1, - .page = -1, - .path = repo_dir->name, - .commit = rc->commit_id, - }, "diff"); - if (r == -1) - goto done; - - if (fcgi_printf(c, " | ") == -1) - goto done; - - r = gotweb_link(c, &(struct gotweb_url){ - .action = TREE, - .index_page = -1, - .page = -1, - .path = repo_dir->name, - .commit = rc->commit_id, - }, "tree"); - if (r == -1) - goto done; - - if (fcgi_printf(c, "</div>\n" /* .navs */ - "</div>\n" /* .navs_wrapper */ - "<div class='dotted_line'></div>\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, "</div>\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, + }; +!} +<div class="commits_title_wrapper"> + <div class="commits_title">Commits</div> +</div> +<div class="commits_content"> + {{ tailq-foreach rc &t->repo_commits entry }} + {! + diff.commit = rc->commit_id; + tree.commit = rc->commit_id; + !} + <div class="commits_header_wrapper"> + <div class="commits_header"> + <div class="header_commit_title">Commit:</div> + <div class="header_commit">{{ rc->commit_id }}</div> + <div class="header_author_title">Author:</div> + <div class="header_author">{{ rc->author }}</div> + <div class="header_age_title">Date:</div> + <div class="header_age"> + {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }} + </div> + </div> + </div> + <div class="navs_wrapper"> + <div class="navs"> + <a href="{{ render gotweb_render_url(c, &diff) }}">diff</a> + {{ " | " }} + <a href="{{ render gotweb_render_url(c, &tree) }}">tree</a> + </div> + </div> + <div class="dotted_line"></div> + {{ end }} + {{ if t->next_id || t->prev_id }} + {{ render gotweb_render_navs(tp) }} + {{ end }} +</div> +{{ end }}
templateify gotweb_render_commits