Commit Diff


commit - 502374853d19661deb162553e55b6952a9f8d8de
commit + 53bf32b82a90b42a6feff46808c401af5d59f2c6
blob - e4c0296bd2054f17e6580ab90ac106d0cf9fe9bd
blob + 125258a15fc66665090af8fe98d6c3a3a3dd15fc
--- gotwebd/got_operations.c
+++ gotwebd/got_operations.c
@@ -126,8 +126,7 @@ got_get_repo_owner(char **owner, struct request *c)
 }
 
 const struct got_error *
-got_get_repo_age(char **repo_age, struct request *c,
-    const char *refname, int ref_tm)
+got_get_repo_age(time_t *repo_age, struct request *c, const char *refname)
 {
 	const struct got_error *error = NULL;
 	struct server *srv = c->srv;
@@ -138,7 +137,6 @@ got_get_repo_age(char **repo_age, struct request *c,
 	struct got_reflist_entry *re;
 	time_t committer_time = 0, cmp_time = 0;
 
-	*repo_age = NULL;
 	TAILQ_INIT(&refs);
 
 	if (srv->show_repo_age == 0)
@@ -178,10 +176,8 @@ got_get_repo_age(char **repo_age, struct request *c,
 			break;
 	}
 
-	if (cmp_time != 0) {
-		committer_time = cmp_time;
-		error = gotweb_get_time_str(repo_age, committer_time, ref_tm);
-	}
+	if (cmp_time != 0)
+		*repo_age = cmp_time;
 done:
 	got_ref_list_free(&refs);
 	return error;
blob - 4f7164d2bace49748ac8ac119d4fd82a57986f63
blob + fa82549de267b5966a36535f77026131c65ad216
--- gotwebd/gotweb.c
+++ gotwebd/gotweb.c
@@ -762,7 +762,6 @@ gotweb_free_repo_dir(struct repo_dir *repo_dir)
 		free(repo_dir->owner);
 		free(repo_dir->description);
 		free(repo_dir->url);
-		free(repo_dir->age);
 		free(repo_dir->path);
 	}
 	free(repo_dir);
@@ -1338,7 +1337,7 @@ done:
 	error = got_get_repo_owner(&repo_dir->owner, c);
 	if (error)
 		goto err;
-	error = got_get_repo_age(&repo_dir->age, c, NULL, TM_DIFF);
+	error = got_get_repo_age(&repo_dir->age, c, NULL);
 	if (error)
 		goto err;
 	error = gotweb_get_clone_url(&repo_dir->url, srv, repo_dir->path,
@@ -1368,7 +1367,6 @@ gotweb_init_repo_dir(struct repo_dir **repo_dir, const
 	(*repo_dir)->owner = NULL;
 	(*repo_dir)->description = NULL;
 	(*repo_dir)->url = NULL;
-	(*repo_dir)->age = NULL;
 	(*repo_dir)->path = NULL;
 
 	return NULL;
@@ -1466,9 +1464,10 @@ done:
 	return error;
 }
 
-const struct got_error *
-gotweb_get_time_str(char **repo_age, time_t committer_time, int ref_tm)
+int
+gotweb_render_age(struct template *tp, time_t committer_time, int ref_tm)
 {
+	struct request *c = tp->tp_arg;
 	struct tm tm;
 	long long diff_time;
 	const char *years = "years ago", *months = "months ago";
@@ -1479,69 +1478,67 @@ gotweb_get_time_str(char **repo_age, time_t committer_
 	char datebuf[64];
 	size_t r;
 
-	*repo_age = NULL;
-
 	switch (ref_tm) {
 	case TM_DIFF:
 		diff_time = time(NULL) - committer_time;
 		if (diff_time > 60 * 60 * 24 * 365 * 2) {
-			if (asprintf(repo_age, "%lld %s",
+			if (fcgi_printf(c, "%lld %s",
 			    (diff_time / 60 / 60 / 24 / 365), years) == -1)
-				return got_error_from_errno("asprintf");
+				return -1;
 		} else if (diff_time > 60 * 60 * 24 * (365 / 12) * 2) {
-			if (asprintf(repo_age, "%lld %s",
+			if (fcgi_printf(c, "%lld %s",
 			    (diff_time / 60 / 60 / 24 / (365 / 12)),
 			    months) == -1)
-				return got_error_from_errno("asprintf");
+				return -1;
 		} else if (diff_time > 60 * 60 * 24 * 7 * 2) {
-			if (asprintf(repo_age, "%lld %s",
+			if (fcgi_printf(c, "%lld %s",
 			    (diff_time / 60 / 60 / 24 / 7), weeks) == -1)
-				return got_error_from_errno("asprintf");
+				return -1;
 		} else if (diff_time > 60 * 60 * 24 * 2) {
-			if (asprintf(repo_age, "%lld %s",
+			if (fcgi_printf(c, "%lld %s",
 			    (diff_time / 60 / 60 / 24), days) == -1)
-				return got_error_from_errno("asprintf");
+				return -1;
 		} else if (diff_time > 60 * 60 * 2) {
-			if (asprintf(repo_age, "%lld %s",
+			if (fcgi_printf(c, "%lld %s",
 			    (diff_time / 60 / 60), hours) == -1)
-				return got_error_from_errno("asprintf");
+				return -1;
 		} else if (diff_time > 60 * 2) {
-			if (asprintf(repo_age, "%lld %s", (diff_time / 60),
+			if (fcgi_printf(c, "%lld %s", (diff_time / 60),
 			    minutes) == -1)
-				return got_error_from_errno("asprintf");
-		} else if (diff_time > 2) {
-			if (asprintf(repo_age, "%lld %s", diff_time,
+				return -1;
+		} else if (diff_time > 2) {
+			if (fcgi_printf(c, "%lld %s", diff_time,
 			    seconds) == -1)
-				return got_error_from_errno("asprintf");
+				return -1;
 		} else {
-			if (asprintf(repo_age, "%s", now) == -1)
-				return got_error_from_errno("asprintf");
+			if (fcgi_puts(tp, now) == -1)
+				return -1;
 		}
 		break;
 	case TM_LONG:
 		if (gmtime_r(&committer_time, &tm) == NULL)
-			return got_error_from_errno("gmtime_r");
+			return -1;
 
 		s = asctime_r(&tm, datebuf);
 		if (s == NULL)
-			return got_error_from_errno("asctime_r");
+			return -1;
 
-		if (asprintf(repo_age, "%s UTC", datebuf) == -1)
-			return got_error_from_errno("asprintf");
+		if (fcgi_puts(tp, datebuf) == -1 ||
+		    fcgi_puts(tp, " UTC") == -1)
+			return -1;
 		break;
 	case TM_RFC822:
 		if (gmtime_r(&committer_time, &tm) == NULL)
-			return got_error_from_errno("gmtime_r");
+			return -1;
 
 		r = strftime(datebuf, sizeof(datebuf),
 		    "%a, %d %b %Y %H:%M:%S GMT", &tm);
 		if (r == 0)
-			return got_error(GOT_ERR_NO_SPACE);
+			return -1;
 
-		*repo_age = strdup(datebuf);
-		if (*repo_age == NULL)
-			return got_error_from_errno("asprintf");
+		if (fcgi_puts(tp, datebuf) == -1)
+			return -1;
 		break;
 	}
-	return NULL;
+	return 0;
 }
blob - 2b9e284829e2499bdebb01fa9df0f485d139114f
blob + 5feba0db0d8be996bd0d6f2896886ec579598d19
--- gotwebd/gotwebd.h
+++ gotwebd/gotwebd.h
@@ -157,7 +157,7 @@ struct repo_dir {
 	char			*owner;
 	char			*description;
 	char			*url;
-	char			*age;
+	time_t			 age;
 	char			*path;
 };
 
@@ -453,7 +453,7 @@ int sockets_privinit(struct gotwebd *, struct socket *
 /* gotweb.c */
 void gotweb_get_navs(struct request *, struct gotweb_url *, int *,
     struct gotweb_url *, int *);
-const struct got_error *gotweb_get_time_str(char **, time_t, int);
+int gotweb_render_age(struct template *, time_t, int);
 const struct got_error *gotweb_init_transport(struct transport **);
 const char *gotweb_action_name(int);
 int gotweb_render_url(struct request *, struct gotweb_url *);
@@ -502,8 +502,8 @@ int fcgi_gen_binary_response(struct request *, const u
 /* got_operations.c */
 const struct got_error *got_gotweb_flushfile(FILE *, int);
 const struct got_error *got_get_repo_owner(char **, struct request *);
-const struct got_error *got_get_repo_age(char **, struct request *,
-    const char *, int);
+const struct got_error *got_get_repo_age(time_t *, struct request *,
+    const char *);
 const struct got_error *got_get_repo_commits(struct request *, int);
 const struct got_error *got_get_repo_tags(struct request *, int);
 const struct got_error *got_get_repo_heads(struct request *);
blob - 87784038ab934f1448d0562b439b954d3e2e2348
blob + 96d1039d6fa50bb6df8ad6e766bb7edb55b5ff13
--- gotwebd/pages.tmpl
+++ gotwebd/pages.tmpl
@@ -48,21 +48,6 @@ static inline int branch(struct template *, struct got
 static inline int rss_tag_item(struct template *, struct repo_tag *);
 static inline int rss_author(struct template *, char *);
 
-static int
-gotweb_render_age(struct template *tp, time_t time, int ref_tm)
-{
-	const struct got_error *err;
-	char *age;
-	int r;
-
-	err = gotweb_get_time_str(&age, time, ref_tm);
-	if (err)
-		return 0;
-	r = tp->tp_puts(tp, age);
-	free(age);
-	return r;
-}
-
 !}
 
 {{ define gotweb_render_header(struct template *tp) }}
@@ -220,7 +205,7 @@ gotweb_render_age(struct template *tp, time_t time, in
   {{ end }}
   {{ if srv->show_repo_age }}
     <div class="index_project_age">
-      {{ repo_dir->age }}
+      {{ render gotweb_render_age(tp, repo_dir->age, TM_DIFF) }}
     </div>
   {{ end }}
   <div class="navs_wrapper">
@@ -797,7 +782,7 @@ gotweb_render_age(struct template *tp, time_t time, in
 	struct request		*c = tp->tp_arg;
 	struct querystring	*qs = c->t->qs;
 	const char		*refname;
-	char			*age = NULL;
+	time_t			 age;
 	struct gotweb_url	 url = {
 		.action = SUMMARY,
 		.index_page = -1,
@@ -807,7 +792,7 @@ gotweb_render_age(struct template *tp, time_t time, in
 
 	refname = got_ref_get_name(re->ref);
 
-	err = got_get_repo_age(&age, c, refname, TM_DIFF);
+	err = got_get_repo_age(&age, c, refname);
 	if (err) {
 		log_warnx("%s: %s", __func__, err->msg);
 		return -1;
@@ -819,7 +804,9 @@ gotweb_render_age(struct template *tp, time_t time, in
 	url.headref = refname;
 !}
 <div class="branches_wrapper">
-  <div class="branches_age">{{ age }}</div>
+  <div class="branches_age">
+    {{ render gotweb_render_age(tp, age, TM_DIFF) }}
+  </div>
   <div class="branches_space">&nbsp;</div>
   <div class="branch">
     <a href="{{ render gotweb_render_url(c, &url) }}">{{ refname }}</a>
@@ -837,8 +824,6 @@ gotweb_render_age(struct template *tp, time_t time, in
   </div>
   <div class="dotted_line"></div>
 </div>
-{{ finally }}
-{! free(age); !}
 {{ end }}
 
 {{ define gotweb_render_summary(struct template *tp,
@@ -859,7 +844,9 @@ gotweb_render_age(struct template *tp, time_t time, in
   {{ end }}
   {{ if srv->show_repo_age }}
     <div id="last_change_title">Last Change:</div>
-    <div id="last_change">{{ t->repo_dir->age }}</div>
+    <div id="last_change">
+      {{ render gotweb_render_age(tp, t->repo_dir->age, TM_DIFF) }}
+    </div>
   {{ end }}
   {{ if srv->show_repo_cloneurl }}
     <div id="cloneurl_title">Clone URL:</div>