Commit Diff


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, "<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 - 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,
+	};
+!}
+<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 }}