Commit Diff


commit - 5fa52d6cdcc6de872ce3c7f6639cc638fd83eeea
commit + 3ab2c91424750aef75f929402e6a7581a704f36d
blob - 539e06b6f8271d8b51ac64fbfe665a5ad7a4a1ae
blob + df7d335b7261e2e7472a0004b490f669e3a56351
--- gotwebd/gotweb.c
+++ gotwebd/gotweb.c
@@ -96,7 +96,6 @@ static const struct got_error *gotweb_get_clone_url(ch
 static const struct got_error *gotweb_render_blame(struct request *);
 static const struct got_error *gotweb_render_summary(struct request *);
 static const struct got_error *gotweb_render_tags(struct request *);
-static const struct got_error *gotweb_render_branches(struct request *);
 
 static void gotweb_free_querystring(struct querystring *);
 static void gotweb_free_repo_dir(struct repo_dir *);
@@ -1012,16 +1011,13 @@ done:
 }
 
 static const struct got_error *
-gotweb_render_branches(struct request *c)
+gotweb_render_summary(struct request *c)
 {
 	const struct got_error *error = NULL;
 	struct got_reflist_head refs;
-	struct got_reflist_entry *re;
 	struct transport *t = c->t;
-	struct querystring *qs = t->qs;
-	struct got_repository *repo = t->repo;
-	char *escaped_refname = NULL;
-	char *age = NULL;
+	struct got_repository *repo = t->repo;
+	struct server *srv = c->srv;
 	int r;
 
 	TAILQ_INIT(&refs);
@@ -1030,124 +1026,7 @@ gotweb_render_branches(struct request *c)
 	    got_ref_cmp_by_name, NULL);
 	if (error)
 		goto done;
-
-	r = fcgi_printf(c, "<div id='branches_title_wrapper'>\n"
-	    "<div id='branches_title'>Branches</div>\n"
-	    "</div>\n"	/* #branches_title_wrapper */
-	    "<div id='branches_content'>\n");
-	if (r == -1)
-		goto done;
-
-	TAILQ_FOREACH(re, &refs, entry) {
-		const char *refname = NULL;
-
-		if (got_ref_is_symbolic(re->ref))
-			continue;
-
-		refname = got_ref_get_name(re->ref);
-		if (refname == NULL) {
-			error = got_error_from_errno("strdup");
-			goto done;
-		}
-		if (strncmp(refname, "refs/heads/", 11) != 0)
-			continue;
-
-		error = got_get_repo_age(&age, c, refname, TM_DIFF);
-		if (error)
-			goto done;
-
-		if (strncmp(refname, "refs/heads/", 11) == 0)
-			refname += 11;
-		error = gotweb_escape_html(&escaped_refname, refname);
-		if (error)
-			goto done;
-
-		r = fcgi_printf(c, "<div class='branches_wrapper'>\n"
-		    "<div class='branches_age'>%s</div>\n"
-		    "<div class='branches_space'>&nbsp;</div>\n"
-		    "<div class='branch'>", age);
-		if (r == -1)
-			goto done;
-
-		r = gotweb_link(c, &(struct gotweb_url){
-			.action = SUMMARY,
-			.index_page = -1,
-			.page = -1,
-			.path = qs->path,
-			.headref = refname,
-		    }, "%s", escaped_refname);
-		if (r == -1)
-			goto done;
-
-		if (fcgi_printf(c, "</div>\n"	/* .branch */
-		    "<div class='navs_wrapper'>\n"
-		    "<div class='navs'>") == -1)
-			goto done;
-
-		r = gotweb_link(c, &(struct gotweb_url){
-			.action = SUMMARY,
-			.index_page = -1,
-			.page = -1,
-			.path = qs->path,
-			.headref = refname,
-		    }, "summary");
-		if (r == -1)
-			goto done;
 
-		if (fcgi_printf(c, " | ") == -1)
-			goto done;
-
-		r = gotweb_link(c, &(struct gotweb_url){
-			.action = BRIEFS,
-			.index_page = -1,
-			.page = -1,
-			.path = qs->path,
-			.headref = refname,
-		    }, "commit briefs");
-		if (r == -1)
-			goto done;
-
-		if (fcgi_printf(c, " | ") == -1)
-			goto done;
-
-		r = gotweb_link(c, &(struct gotweb_url){
-			.action = COMMITS,
-			.index_page = -1,
-			.page = -1,
-			.path = qs->path,
-			.headref = refname,
-		    }, "commits");
-		if (r == -1)
-			goto done;
-
-		r = fcgi_printf(c, "</div>\n"	/* .navs */
-		    "</div>\n"			/* .navs_wrapper */
-		    "<div class='dotted_line'></div>\n"
-		    "</div>\n");		/* .branches_wrapper */
-		if (r == -1)
-			goto done;
-
-		free(age);
-		age = NULL;
-		free(escaped_refname);
-		escaped_refname = NULL;
-	}
-	fcgi_printf(c, "</div>\n"); /* #branches_content */
-done:
-	free(age);
-	free(escaped_refname);
-	got_ref_list_free(&refs);
-	return error;
-}
-
-static const struct got_error *
-gotweb_render_summary(struct request *c)
-{
-	const struct got_error *error = NULL;
-	struct transport *t = c->t;
-	struct server *srv = c->srv;
-	int r;
-
 	if (fcgi_printf(c, "<div id='summary_wrapper'>\n") == -1)
 		goto done;
 
@@ -1200,10 +1079,9 @@ gotweb_render_summary(struct request *c)
 		goto done;
 	}
 
-	error = gotweb_render_branches(c);
-	if (error)
-		log_warnx("%s: %s", __func__, error->msg);
+	gotweb_render_branches(c->tp, &refs);
 done:
+	got_ref_list_free(&refs);
 	return error;
 }
 
blob - e19e34593996941a09c53036aa3d995fb6867118
blob + 47eed11a0ded054e1f08fe6bee4bc4b5af4aea0e
--- gotwebd/gotwebd.h
+++ gotwebd/gotwebd.h
@@ -118,6 +118,7 @@
 /* Forward declaration */
 struct got_blob_object;
 struct got_tree_entry;
+struct got_reflist_head;
 
 enum imsg_type {
 	IMSG_CFG_SRV = IMSG_PROC_MAX,
@@ -472,6 +473,7 @@ int	gotweb_render_tree(struct template *);
 int	gotweb_render_tags_tmpl(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_rss(struct template *);
 
 /* parse.y */
blob - 3501ce16a0c13174e3e6a1d4fc06358a7b345061
blob + 6cf6d4d7e32e66e8dbd1cf8b8d9740fec9fe9ef2
--- gotwebd/pages.tmpl
+++ gotwebd/pages.tmpl
@@ -29,7 +29,9 @@
 #include <sha1.h>
 #include <imsg.h>
 
+#include "got_error.h"
 #include "got_object.h"
+#include "got_reference.h"
 
 #include "proc.h"
 
@@ -41,6 +43,7 @@ static int gotweb_render_tree_item(struct template *, 
 
 static inline int diff_line(struct template *, char *);
 static inline int tag_item(struct template *, struct repo_tag *);
+static inline int branch(struct template *, struct got_reflist_entry *);
 static inline int rss_tag_item(struct template *, struct repo_tag *);
 static inline int rss_author(struct template *, char *);
 
@@ -768,6 +771,73 @@ gotweb_render_age(struct template *tp, time_t time, in
 		*nl = '\0';
 !}
 <div class="diff_line {{ color }}">{{ line }}</div>
+{{ end }}
+
+{{ define gotweb_render_branches(struct template *tp,
+    struct got_reflist_head *refs) }}
+{!
+	struct got_reflist_entry	*re;
+!}
+<div id="branches_title_wrapper">
+  <div id="branches_title">Branches</div>
+</div>
+<div id="branches_content">
+  {{ tailq-foreach re refs entry }}
+    {{ if !got_ref_is_symbolic(re->ref) }}
+      {{ render branch(tp, re) }}
+    {{ end }}
+  {{ end }}
+</div>
+{{ end }}
+
+{{ define branch(struct template *tp, struct got_reflist_entry *re) }}
+{!
+	const struct got_error	*err;
+	struct request		*c = tp->tp_arg;
+	struct querystring	*qs = c->t->qs;
+	const char		*refname;
+	char			*age = NULL;
+	struct gotweb_url	 url = {
+		.action = SUMMARY,
+		.index_page = -1,
+		.page = -1,
+		.path = qs->path,
+	};
+
+	refname = got_ref_get_name(re->ref);
+
+	err = got_get_repo_age(&age, c, refname, TM_DIFF);
+	if (err) {
+		log_warnx("%s: %s", __func__, err->msg);
+		return -1;
+	}
+
+	if (strncmp(refname, "refs/heads/", 11) == 0)
+		refname += 11;
+
+	url.headref = refname;
+!}
+<div class="branches_wrapper">
+  <div class="branches_age">{{ age }}</div>
+  <div class="branches_space">&nbsp;</div>
+  <div class="branch">
+    <a href="{{ render gotweb_render_url(c, &url) }}">{{ refname }}</a>
+  </div>
+  <div class="navs_wrapper">
+    <div class="navs">
+      <a href="{{ render gotweb_render_url(c, &url) }}">summary</a>
+      {{" | "}}
+      {! url.action = BRIEFS; !}
+      <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
+      {{" | "}}
+      {! url.action = COMMITS; !}
+      <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
+    </div>
+  </div>
+  <div class="dotted_line"></div>
+</div>
+{{ finally }}
+{! free(age); !}
 {{ end }}
 
 {{ define gotweb_render_rss(struct template *tp) }}