List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH 0/8] Show times in the originator's timezone
@ 2016-01-19 19:33 john
  2016-01-19 19:33 ` [PATCH 1/8] ui-shared: remove "format" from cgit_print_age() john
                   ` (8 more replies)
  0 siblings, 9 replies; 17+ messages in thread
From: john @ 2016-01-19 19:33 UTC (permalink / raw)


This is the result of an issue I identified a while ago [1].  Now that
we use Git 2.7 we can use the timezone handling code in libgit.a without
needing to use a very specific format when showing times in the local
timezone.

This changes the default used for displaying times from commits and tags
to use the timezone specified in the commit/tag object.  The
"local-time" configuration option works exactly as it did before, but
the previous default behaviour of using UTC is no longer supported.  I
think this is reasonably because it brings us closer to the behaviour of
the Git utilities as well as Gitweb and other web frontends for Git
repositories.

[1] http://article.gmane.org/gmane.comp.version-control.cgit/2515

John Keeping (8):
  ui-shared: remove "format" from cgit_print_age()
  parsing: add timezone to ident structures
  ui-shared: add cgit_date_mode()
  ui-{commit,tag}: show dates in originator's timezone
  ui: show ages in the originator's timezone
  ui-shared: use show_date for footer timestamp
  ui-atom: use show_date directly for atom dates
  ui-shared: remove cgit_print_date()

 cgit.h        |  3 +++
 parsing.c     | 10 ++++++----
 ui-atom.c     |  9 +++++++--
 ui-commit.c   |  6 ++++--
 ui-log.c      |  4 ++--
 ui-refs.c     |  6 +++---
 ui-repolist.c |  2 +-
 ui-shared.c   | 47 ++++++++++++++++++-----------------------------
 ui-shared.h   |  4 ++--
 ui-tag.c      |  3 ++-
 10 files changed, 48 insertions(+), 46 deletions(-)

-- 
2.7.0.226.gfe986fe



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 1/8] ui-shared: remove "format" from cgit_print_age()
  2016-01-19 19:33 [PATCH 0/8] Show times in the originator's timezone john
@ 2016-01-19 19:33 ` john
  2016-01-19 19:33 ` [PATCH 2/8] parsing: add timezone to ident structures john
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: john @ 2016-01-19 19:33 UTC (permalink / raw)


We never use any format other than FMT_SHORTDATE, so move that into the
function.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-log.c      | 4 ++--
 ui-refs.c     | 6 +++---
 ui-repolist.c | 2 +-
 ui-shared.c   | 4 ++--
 ui-shared.h   | 2 +-
 5 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/ui-log.c b/ui-log.c
index 4573255..bc625db 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -202,7 +202,7 @@ static void print_commit(struct commit *commit, struct rev_info *revs)
 	}
 	else {
 		html("<td>");
-		cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
+		cgit_print_age(commit->date, TM_WEEK * 2);
 		html("</td>");
 	}
 
@@ -242,7 +242,7 @@ static void print_commit(struct commit *commit, struct rev_info *revs)
 
 	if (revs->graph) {
 		html("</td><td>");
-		cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
+		cgit_print_age(commit->date, TM_WEEK * 2);
 	}
 
 	if (!lines_counted && (ctx.repo->enable_log_filecount ||
diff --git a/ui-refs.c b/ui-refs.c
index 295a4c7..0652b89 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -73,7 +73,7 @@ static int print_branch(struct refinfo *ref)
 		html_txt(info->author);
 		cgit_close_filter(ctx.repo->email_filter);
 		html("</td><td colspan='2'>");
-		cgit_print_age(info->commit->date, -1, NULL);
+		cgit_print_age(info->commit->date, -1);
 	} else {
 		html("</td><td></td><td>");
 		cgit_object_link(ref->object);
@@ -161,9 +161,9 @@ static int print_tag(struct refinfo *ref)
 	html("</td><td colspan='2'>");
 	if (info) {
 		if (info->tagger_date > 0)
-			cgit_print_age(info->tagger_date, -1, NULL);
+			cgit_print_age(info->tagger_date, -1);
 	} else if (ref->object->type == OBJ_COMMIT) {
-		cgit_print_age(ref->commit->commit->date, -1, NULL);
+		cgit_print_age(ref->commit->commit->date, -1);
 	}
 	html("</td></tr>\n");
 
diff --git a/ui-repolist.c b/ui-repolist.c
index 6010a39..6004469 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -79,7 +79,7 @@ static void print_modtime(struct cgit_repo *repo)
 {
 	time_t t;
 	if (get_repo_modtime(repo, &t))
-		cgit_print_age(t, -1, NULL);
+		cgit_print_age(t, -1);
 }
 
 static int is_match(struct cgit_repo *repo)
diff --git a/ui-shared.c b/ui-shared.c
index 5b48734..34d3367 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -635,7 +635,7 @@ static void print_rel_date(time_t t, double value,
 	htmlf("'>%.0f %s</span>", value, suffix);
 }
 
-void cgit_print_age(time_t t, time_t max_relative, const char *format)
+void cgit_print_age(time_t t, time_t max_relative)
 {
 	time_t now, secs;
 
@@ -650,7 +650,7 @@ void cgit_print_age(time_t t, time_t max_relative, const char *format)
 		html("<span title='");
 		html_attr(fmt_date(t, FMT_LONGDATE, ctx.cfg.local_time));
 		html("'>");
-		cgit_print_date(t, format, ctx.cfg.local_time);
+		cgit_print_date(t, FMT_SHORTDATE, ctx.cfg.local_time);
 		html("</span>");
 		return;
 	}
diff --git a/ui-shared.h b/ui-shared.h
index 474e0c5..4d655d9 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -62,7 +62,7 @@ extern void cgit_print_error(const char *fmt, ...);
 __attribute__((format (printf,1,0)))
 extern void cgit_vprint_error(const char *fmt, va_list ap);
 extern void cgit_print_date(time_t secs, const char *format, int local_time);
-extern void cgit_print_age(time_t t, time_t max_relative, const char *format);
+extern void cgit_print_age(time_t t, time_t max_relative);
 extern void cgit_print_http_headers(void);
 extern void cgit_redirect(const char *url, bool permanent);
 extern void cgit_print_docstart(void);
-- 
2.7.0.226.gfe986fe



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 2/8] parsing: add timezone to ident structures
  2016-01-19 19:33 [PATCH 0/8] Show times in the originator's timezone john
  2016-01-19 19:33 ` [PATCH 1/8] ui-shared: remove "format" from cgit_print_age() john
@ 2016-01-19 19:33 ` john
  2016-01-19 19:33 ` [PATCH 3/8] ui-shared: add cgit_date_mode() john
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: john @ 2016-01-19 19:33 UTC (permalink / raw)


This will allow us to mimic Git's behaviour of showing times in the
originator's timezone when displaying commits and tags.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 cgit.h    |  3 +++
 parsing.c | 10 ++++++----
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/cgit.h b/cgit.h
index b7eccdd..9cfa2df 100644
--- a/cgit.h
+++ b/cgit.h
@@ -129,9 +129,11 @@ struct commitinfo {
 	char *author;
 	char *author_email;
 	unsigned long author_date;
+	int author_tz;
 	char *committer;
 	char *committer_email;
 	unsigned long committer_date;
+	int committer_tz;
 	char *subject;
 	char *msg;
 	char *msg_encoding;
@@ -141,6 +143,7 @@ struct taginfo {
 	char *tagger;
 	char *tagger_email;
 	unsigned long tagger_date;
+	int tagger_tz;
 	char *msg;
 };
 
diff --git a/parsing.c b/parsing.c
index 5283e58..9dacb16 100644
--- a/parsing.c
+++ b/parsing.c
@@ -69,7 +69,7 @@ static char *substr(const char *head, const char *tail)
 	return buf;
 }
 
-static void parse_user(const char *t, char **name, char **email, unsigned long *date)
+static void parse_user(const char *t, char **name, char **email, unsigned long *date, int *tz)
 {
 	struct ident_split ident;
 	unsigned email_len;
@@ -83,6 +83,8 @@ static void parse_user(const char *t, char **name, char **email, unsigned long *
 
 		if (ident.date_begin)
 			*date = strtoul(ident.date_begin, NULL, 10);
+		if (ident.tz_begin)
+			*tz = atoi(ident.tz_begin);
 	}
 }
 
@@ -147,13 +149,13 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
 
 	if (p && skip_prefix(p, "author ", &p)) {
 		parse_user(p, &ret->author, &ret->author_email,
-			&ret->author_date);
+			&ret->author_date, &ret->author_tz);
 		p = next_header_line(p);
 	}
 
 	if (p && skip_prefix(p, "committer ", &p)) {
 		parse_user(p, &ret->committer, &ret->committer_email,
-			&ret->committer_date);
+			&ret->committer_date, &ret->committer_tz);
 		p = next_header_line(p);
 	}
 
@@ -208,7 +210,7 @@ struct taginfo *cgit_parse_tag(struct tag *tag)
 	for (p = data; !end_of_header(p); p = next_header_line(p)) {
 		if (skip_prefix(p, "tagger ", &p)) {
 			parse_user(p, &ret->tagger, &ret->tagger_email,
-				&ret->tagger_date);
+				&ret->tagger_date, &ret->tagger_tz);
 		}
 	}
 
-- 
2.7.0.226.gfe986fe



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 3/8] ui-shared: add cgit_date_mode()
  2016-01-19 19:33 [PATCH 0/8] Show times in the originator's timezone john
  2016-01-19 19:33 ` [PATCH 1/8] ui-shared: remove "format" from cgit_print_age() john
  2016-01-19 19:33 ` [PATCH 2/8] parsing: add timezone to ident structures john
@ 2016-01-19 19:33 ` john
  2016-02-08 13:20   ` Jason
  2016-01-19 19:33 ` [PATCH 4/8] ui-{commit,tag}: show dates in originator's timezone john
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 17+ messages in thread
From: john @ 2016-01-19 19:33 UTC (permalink / raw)


This returns the correct mode value for use with Git's show_date() based
on the current CGit configuration and will be used in the following
patches.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-shared.c | 9 +++++++++
 ui-shared.h | 1 +
 2 files changed, 10 insertions(+)

diff --git a/ui-shared.c b/ui-shared.c
index 34d3367..2a622cd 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -627,6 +627,15 @@ void cgit_print_date(time_t secs, const char *format, int local_time)
 	html_txt(fmt_date(secs, format, local_time));
 }
 
+const struct date_mode *cgit_date_mode(const char *format)
+{
+	static struct date_mode mode;
+	mode.type = DATE_STRFTIME;
+	mode.strftime_fmt = format;
+	mode.local = ctx.cfg.local_time;
+	return &mode;
+}
+
 static void print_rel_date(time_t t, double value,
 	const char *class, const char *suffix)
 {
diff --git a/ui-shared.h b/ui-shared.h
index 4d655d9..7c097c1 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -61,6 +61,7 @@ __attribute__((format (printf,1,2)))
 extern void cgit_print_error(const char *fmt, ...);
 __attribute__((format (printf,1,0)))
 extern void cgit_vprint_error(const char *fmt, va_list ap);
+extern const struct date_mode *cgit_date_mode(const char *format);
 extern void cgit_print_date(time_t secs, const char *format, int local_time);
 extern void cgit_print_age(time_t t, time_t max_relative);
 extern void cgit_print_http_headers(void);
-- 
2.7.0.226.gfe986fe



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 4/8] ui-{commit,tag}: show dates in originator's timezone
  2016-01-19 19:33 [PATCH 0/8] Show times in the originator's timezone john
                   ` (2 preceding siblings ...)
  2016-01-19 19:33 ` [PATCH 3/8] ui-shared: add cgit_date_mode() john
@ 2016-01-19 19:33 ` john
  2016-01-19 19:33 ` [PATCH 5/8] ui: show ages in the " john
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: john @ 2016-01-19 19:33 UTC (permalink / raw)


This is done by switching to Git's show_date() function and the mode
given by cgit_date_mode().

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-commit.c | 6 ++++--
 ui-tag.c    | 3 ++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/ui-commit.c b/ui-commit.c
index 0c3d740..e697571 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -55,7 +55,8 @@ void cgit_print_commit(char *hex, const char *prefix)
 	}
 	cgit_close_filter(ctx.repo->email_filter);
 	html("</td><td class='right'>");
-	cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
+	html_txt(show_date(info->author_date, info->author_tz,
+				cgit_date_mode(FMT_LONGDATE)));
 	html("</td></tr>\n");
 	html("<tr><th>committer</th><td>");
 	cgit_open_filter(ctx.repo->email_filter, info->committer_email, "commit");
@@ -66,7 +67,8 @@ void cgit_print_commit(char *hex, const char *prefix)
 	}
 	cgit_close_filter(ctx.repo->email_filter);
 	html("</td><td class='right'>");
-	cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
+	html_txt(show_date(info->committer_date, info->committer_tz,
+				cgit_date_mode(FMT_LONGDATE)));
 	html("</td></tr>\n");
 	html("<tr><th>commit</th><td colspan='2' class='sha1'>");
 	tmp = oid_to_hex(&commit->object.oid);
diff --git a/ui-tag.c b/ui-tag.c
index 0afc663..b011198 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -76,7 +76,8 @@ void cgit_print_tag(char *revname)
 		htmlf(" (%s)</td></tr>\n", sha1_to_hex(sha1));
 		if (info->tagger_date > 0) {
 			html("<tr><td>tag date</td><td>");
-			cgit_print_date(info->tagger_date, FMT_LONGDATE, ctx.cfg.local_time);
+			html_txt(show_date(info->tagger_date, info->tagger_tz,
+						cgit_date_mode(FMT_LONGDATE)));
 			html("</td></tr>\n");
 		}
 		if (info->tagger) {
-- 
2.7.0.226.gfe986fe



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 5/8] ui: show ages in the originator's timezone
  2016-01-19 19:33 [PATCH 0/8] Show times in the originator's timezone john
                   ` (3 preceding siblings ...)
  2016-01-19 19:33 ` [PATCH 4/8] ui-{commit,tag}: show dates in originator's timezone john
@ 2016-01-19 19:33 ` john
  2016-01-19 19:33 ` [PATCH 6/8] ui-shared: use show_date for footer timestamp john
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: john @ 2016-01-19 19:33 UTC (permalink / raw)


This affects the tooltip showing the full time and the case when a date
is sufficiently old to be shown in full rather than as an offset.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-log.c      |  4 ++--
 ui-refs.c     |  6 +++---
 ui-repolist.c |  2 +-
 ui-shared.c   | 22 +++++++++++-----------
 ui-shared.h   |  2 +-
 5 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/ui-log.c b/ui-log.c
index bc625db..272c073 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -202,7 +202,7 @@ static void print_commit(struct commit *commit, struct rev_info *revs)
 	}
 	else {
 		html("<td>");
-		cgit_print_age(commit->date, TM_WEEK * 2);
+		cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2);
 		html("</td>");
 	}
 
@@ -242,7 +242,7 @@ static void print_commit(struct commit *commit, struct rev_info *revs)
 
 	if (revs->graph) {
 		html("</td><td>");
-		cgit_print_age(commit->date, TM_WEEK * 2);
+		cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2);
 	}
 
 	if (!lines_counted && (ctx.repo->enable_log_filecount ||
diff --git a/ui-refs.c b/ui-refs.c
index 0652b89..5b4530e 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -73,7 +73,7 @@ static int print_branch(struct refinfo *ref)
 		html_txt(info->author);
 		cgit_close_filter(ctx.repo->email_filter);
 		html("</td><td colspan='2'>");
-		cgit_print_age(info->commit->date, -1);
+		cgit_print_age(info->committer_date, info->committer_tz, -1);
 	} else {
 		html("</td><td></td><td>");
 		cgit_object_link(ref->object);
@@ -161,9 +161,9 @@ static int print_tag(struct refinfo *ref)
 	html("</td><td colspan='2'>");
 	if (info) {
 		if (info->tagger_date > 0)
-			cgit_print_age(info->tagger_date, -1);
+			cgit_print_age(info->tagger_date, info->tagger_tz, -1);
 	} else if (ref->object->type == OBJ_COMMIT) {
-		cgit_print_age(ref->commit->commit->date, -1);
+		cgit_print_age(ref->commit->commit->date, 0, -1);
 	}
 	html("</td></tr>\n");
 
diff --git a/ui-repolist.c b/ui-repolist.c
index 6004469..30915df 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -79,7 +79,7 @@ static void print_modtime(struct cgit_repo *repo)
 {
 	time_t t;
 	if (get_repo_modtime(repo, &t))
-		cgit_print_age(t, -1);
+		cgit_print_age(t, 0, -1);
 }
 
 static int is_match(struct cgit_repo *repo)
diff --git a/ui-shared.c b/ui-shared.c
index 2a622cd..0322968 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -636,15 +636,15 @@ const struct date_mode *cgit_date_mode(const char *format)
 	return &mode;
 }
 
-static void print_rel_date(time_t t, double value,
+static void print_rel_date(time_t t, int tz, double value,
 	const char *class, const char *suffix)
 {
 	htmlf("<span class='%s' title='", class);
-	html_attr(fmt_date(t, FMT_LONGDATE, ctx.cfg.local_time));
+	html_attr(show_date(t, tz, cgit_date_mode(FMT_LONGDATE)));
 	htmlf("'>%.0f %s</span>", value, suffix);
 }
 
-void cgit_print_age(time_t t, time_t max_relative)
+void cgit_print_age(time_t t, int tz, time_t max_relative)
 {
 	time_t now, secs;
 
@@ -657,34 +657,34 @@ void cgit_print_age(time_t t, time_t max_relative)
 
 	if (secs > max_relative && max_relative >= 0) {
 		html("<span title='");
-		html_attr(fmt_date(t, FMT_LONGDATE, ctx.cfg.local_time));
+		html_attr(show_date(t, tz, cgit_date_mode(FMT_LONGDATE)));
 		html("'>");
-		cgit_print_date(t, FMT_SHORTDATE, ctx.cfg.local_time);
+		html_txt(show_date(t, tz, cgit_date_mode(FMT_SHORTDATE)));
 		html("</span>");
 		return;
 	}
 
 	if (secs < TM_HOUR * 2) {
-		print_rel_date(t, secs * 1.0 / TM_MIN, "age-mins", "min.");
+		print_rel_date(t, tz, secs * 1.0 / TM_MIN, "age-mins", "min.");
 		return;
 	}
 	if (secs < TM_DAY * 2) {
-		print_rel_date(t, secs * 1.0 / TM_HOUR, "age-hours", "hours");
+		print_rel_date(t, tz, secs * 1.0 / TM_HOUR, "age-hours", "hours");
 		return;
 	}
 	if (secs < TM_WEEK * 2) {
-		print_rel_date(t, secs * 1.0 / TM_DAY, "age-days", "days");
+		print_rel_date(t, tz, secs * 1.0 / TM_DAY, "age-days", "days");
 		return;
 	}
 	if (secs < TM_MONTH * 2) {
-		print_rel_date(t, secs * 1.0 / TM_WEEK, "age-weeks", "weeks");
+		print_rel_date(t, tz, secs * 1.0 / TM_WEEK, "age-weeks", "weeks");
 		return;
 	}
 	if (secs < TM_YEAR * 2) {
-		print_rel_date(t, secs * 1.0 / TM_MONTH, "age-months", "months");
+		print_rel_date(t, tz, secs * 1.0 / TM_MONTH, "age-months", "months");
 		return;
 	}
-	print_rel_date(t, secs * 1.0 / TM_YEAR, "age-years", "years");
+	print_rel_date(t, tz, secs * 1.0 / TM_YEAR, "age-years", "years");
 }
 
 void cgit_print_http_headers(void)
diff --git a/ui-shared.h b/ui-shared.h
index 7c097c1..ed351c2 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -63,7 +63,7 @@ __attribute__((format (printf,1,0)))
 extern void cgit_vprint_error(const char *fmt, va_list ap);
 extern const struct date_mode *cgit_date_mode(const char *format);
 extern void cgit_print_date(time_t secs, const char *format, int local_time);
-extern void cgit_print_age(time_t t, time_t max_relative);
+extern void cgit_print_age(time_t t, int tz, time_t max_relative);
 extern void cgit_print_http_headers(void);
 extern void cgit_redirect(const char *url, bool permanent);
 extern void cgit_print_docstart(void);
-- 
2.7.0.226.gfe986fe



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 6/8] ui-shared: use show_date for footer timestamp
  2016-01-19 19:33 [PATCH 0/8] Show times in the originator's timezone john
                   ` (4 preceding siblings ...)
  2016-01-19 19:33 ` [PATCH 5/8] ui: show ages in the " john
@ 2016-01-19 19:33 ` john
  2016-01-19 19:33 ` [PATCH 7/8] ui-atom: use show_date directly for atom dates john
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: john @ 2016-01-19 19:33 UTC (permalink / raw)


Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-shared.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ui-shared.c b/ui-shared.c
index 0322968..9699524 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -797,7 +797,7 @@ void cgit_print_docend(void)
 	else {
 		htmlf("<div class='footer'>generated by <a href='http://git.zx2c4.com/cgit/about/'>cgit %s</a> at ",
 			cgit_version);
-		cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time);
+		html_txt(show_date(time(NULL), 0, cgit_date_mode(FMT_LONGDATE)));
 		html("</div>\n");
 	}
 	html("</div> <!-- id=cgit -->\n");
-- 
2.7.0.226.gfe986fe



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 7/8] ui-atom: use show_date directly for atom dates
  2016-01-19 19:33 [PATCH 0/8] Show times in the originator's timezone john
                   ` (5 preceding siblings ...)
  2016-01-19 19:33 ` [PATCH 6/8] ui-shared: use show_date for footer timestamp john
@ 2016-01-19 19:33 ` john
  2016-01-19 19:33 ` [PATCH 8/8] ui-shared: remove cgit_print_date() john
  2016-02-08 13:23 ` [PATCH 0/8] Show times in the originator's timezone Jason
  8 siblings, 0 replies; 17+ messages in thread
From: john @ 2016-01-19 19:33 UTC (permalink / raw)


This will allow us to remove cgit_print_date and use Git's show_date
consistently.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-atom.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/ui-atom.c b/ui-atom.c
index 11ea0c0..0bf2cf2 100644
--- a/ui-atom.c
+++ b/ui-atom.c
@@ -17,6 +17,11 @@ static void add_entry(struct commit *commit, const char *host)
 	char *hex;
 	char *mail, *t, *t2;
 	struct commitinfo *info;
+	struct date_mode mode = {
+		.type = DATE_STRFTIME,
+		.strftime_fmt = FMT_ATOMDATE,
+		.local = 0,
+	};
 
 	info = cgit_parse_commit(commit);
 	hex = oid_to_hex(&commit->object.oid);
@@ -25,7 +30,7 @@ static void add_entry(struct commit *commit, const char *host)
 	html_txt(info->subject);
 	html("</title>\n");
 	html("<updated>");
-	cgit_print_date(info->committer_date, FMT_ATOMDATE, 0);
+	html_txt(show_date(info->committer_date, 0, &mode));
 	html("</updated>\n");
 	html("<author>\n");
 	if (info->author) {
@@ -50,7 +55,7 @@ static void add_entry(struct commit *commit, const char *host)
 	}
 	html("</author>\n");
 	html("<published>");
-	cgit_print_date(info->author_date, FMT_ATOMDATE, 0);
+	html_txt(show_date(info->author_date, 0, &mode));
 	html("</published>\n");
 	if (host) {
 		char *pageurl;
-- 
2.7.0.226.gfe986fe



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 8/8] ui-shared: remove cgit_print_date()
  2016-01-19 19:33 [PATCH 0/8] Show times in the originator's timezone john
                   ` (6 preceding siblings ...)
  2016-01-19 19:33 ` [PATCH 7/8] ui-atom: use show_date directly for atom dates john
@ 2016-01-19 19:33 ` john
  2016-02-08 13:23 ` [PATCH 0/8] Show times in the originator's timezone Jason
  8 siblings, 0 replies; 17+ messages in thread
From: john @ 2016-01-19 19:33 UTC (permalink / raw)


There are no longer any users of this function.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-shared.c | 20 --------------------
 ui-shared.h |  1 -
 2 files changed, 21 deletions(-)

diff --git a/ui-shared.c b/ui-shared.c
index 9699524..286aa92 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -607,26 +607,6 @@ void cgit_submodule_link(const char *class, char *path, const char *rev)
 		path[len - 1] = tail;
 }
 
-static const char *fmt_date(time_t secs, const char *format, int local_time)
-{
-	static char buf[64];
-	struct tm *time;
-
-	if (!secs)
-		return "";
-	if (local_time)
-		time = localtime(&secs);
-	else
-		time = gmtime(&secs);
-	strftime(buf, sizeof(buf)-1, format, time);
-	return buf;
-}
-
-void cgit_print_date(time_t secs, const char *format, int local_time)
-{
-	html_txt(fmt_date(secs, format, local_time));
-}
-
 const struct date_mode *cgit_date_mode(const char *format)
 {
 	static struct date_mode mode;
diff --git a/ui-shared.h b/ui-shared.h
index ed351c2..5a39947 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -62,7 +62,6 @@ extern void cgit_print_error(const char *fmt, ...);
 __attribute__((format (printf,1,0)))
 extern void cgit_vprint_error(const char *fmt, va_list ap);
 extern const struct date_mode *cgit_date_mode(const char *format);
-extern void cgit_print_date(time_t secs, const char *format, int local_time);
 extern void cgit_print_age(time_t t, int tz, time_t max_relative);
 extern void cgit_print_http_headers(void);
 extern void cgit_redirect(const char *url, bool permanent);
-- 
2.7.0.226.gfe986fe



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 3/8] ui-shared: add cgit_date_mode()
  2016-01-19 19:33 ` [PATCH 3/8] ui-shared: add cgit_date_mode() john
@ 2016-02-08 13:20   ` Jason
  2016-02-08 13:23     ` Jason
  0 siblings, 1 reply; 17+ messages in thread
From: Jason @ 2016-02-08 13:20 UTC (permalink / raw)


This is a step away from obtaining the reentrancy we want(ed). I'll
merge this and then try to fix it up.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 3/8] ui-shared: add cgit_date_mode()
  2016-02-08 13:20   ` Jason
@ 2016-02-08 13:23     ` Jason
  0 siblings, 0 replies; 17+ messages in thread
From: Jason @ 2016-02-08 13:23 UTC (permalink / raw)


On second thought, seeing as show_date isn't really reentrant either,
whatever. Lost cause at this point I suppose.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 0/8] Show times in the originator's timezone
  2016-01-19 19:33 [PATCH 0/8] Show times in the originator's timezone john
                   ` (7 preceding siblings ...)
  2016-01-19 19:33 ` [PATCH 8/8] ui-shared: remove cgit_print_date() john
@ 2016-02-08 13:23 ` Jason
  2016-02-08 13:38   ` Jason
  8 siblings, 1 reply; 17+ messages in thread
From: Jason @ 2016-02-08 13:23 UTC (permalink / raw)


Merged this series. Thanks!


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 0/8] Show times in the originator's timezone
  2016-02-08 13:23 ` [PATCH 0/8] Show times in the originator's timezone Jason
@ 2016-02-08 13:38   ` Jason
  2016-02-08 14:08     ` john
  0 siblings, 1 reply; 17+ messages in thread
From: Jason @ 2016-02-08 13:38 UTC (permalink / raw)


This series is faulty. See git.zx2c4.com

It shows (GMT) when those times are not GMT.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 0/8] Show times in the originator's timezone
  2016-02-08 13:38   ` Jason
@ 2016-02-08 14:08     ` john
  2016-02-08 14:33       ` Jason
  0 siblings, 1 reply; 17+ messages in thread
From: john @ 2016-02-08 14:08 UTC (permalink / raw)


On Mon, Feb 08, 2016 at 02:38:57PM +0100, Jason A. Donenfeld wrote:
> This series is faulty. See git.zx2c4.com
> 
> It shows (GMT) when those times are not GMT.

You're right, it seems that the problem is that we end up using
strftime(3) with %Z for the timezone, but that function doesn't take an
explicit timezone so it just ends up using the system one.

I think we should just switch to using DATE_SHORT and DATE_ISO8601 from
Git's date_mode_type enum; I didn't do so originally because the format
doesn't quite match what we have used traditionally, but now that I look
again it's not that different so I reckon we should just switch (it was
a bigger problem before Git learned that "local" is orthogonal to the
display mode).

We may still need a custom strftime(3) string for FMT_ATOMDATE, but
DATE_ISO8601_STRICT may be enough; it depends whether atom dates have to
be in +00:00 or not.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 0/8] Show times in the originator's timezone
  2016-02-08 14:08     ` john
@ 2016-02-08 14:33       ` Jason
  2016-02-08 15:05         ` [PATCH 1/2] Avoid DATE_STRFTIME for long/short dates john
  0 siblings, 1 reply; 17+ messages in thread
From: Jason @ 2016-02-08 14:33 UTC (permalink / raw)


Okay, well, awaiting your fixup patches.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 1/2] Avoid DATE_STRFTIME for long/short dates
  2016-02-08 14:33       ` Jason
@ 2016-02-08 15:05         ` john
  2016-02-08 15:06           ` [PATCH 2/2] ui-atom: avoid DATE_STRFTIME john
  0 siblings, 1 reply; 17+ messages in thread
From: john @ 2016-02-08 15:05 UTC (permalink / raw)


Git's DATE_STRFTIME ignores the timezone argument and just uses the
local timezone regardless of whether the "local" flag is set.

Since our existing FMT_LONGDATE and FMT_SHORTDATE are pretty-much
perfect matches to DATE_ISO8601 and DATE_SHORT, switch to taking a
date_mode_type directly in cgit_date_mode().

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 cgit.h      |  2 --
 ui-commit.c |  4 ++--
 ui-shared.c | 13 ++++++-------
 ui-shared.h |  2 +-
 ui-tag.c    |  2 +-
 5 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/cgit.h b/cgit.h
index 501cb48..5adef4d 100644
--- a/cgit.h
+++ b/cgit.h
@@ -32,8 +32,6 @@
 /*
  * Dateformats used on misc. pages
  */
-#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)"
-#define FMT_SHORTDATE "%Y-%m-%d"
 #define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ"
 
 
diff --git a/ui-commit.c b/ui-commit.c
index e697571..099d294 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -56,7 +56,7 @@ void cgit_print_commit(char *hex, const char *prefix)
 	cgit_close_filter(ctx.repo->email_filter);
 	html("</td><td class='right'>");
 	html_txt(show_date(info->author_date, info->author_tz,
-				cgit_date_mode(FMT_LONGDATE)));
+				cgit_date_mode(DATE_ISO8601)));
 	html("</td></tr>\n");
 	html("<tr><th>committer</th><td>");
 	cgit_open_filter(ctx.repo->email_filter, info->committer_email, "commit");
@@ -68,7 +68,7 @@ void cgit_print_commit(char *hex, const char *prefix)
 	cgit_close_filter(ctx.repo->email_filter);
 	html("</td><td class='right'>");
 	html_txt(show_date(info->committer_date, info->committer_tz,
-				cgit_date_mode(FMT_LONGDATE)));
+				cgit_date_mode(DATE_ISO8601)));
 	html("</td></tr>\n");
 	html("<tr><th>commit</th><td colspan='2' class='sha1'>");
 	tmp = oid_to_hex(&commit->object.oid);
diff --git a/ui-shared.c b/ui-shared.c
index d1f9249..03dcc08 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -607,11 +607,10 @@ void cgit_submodule_link(const char *class, char *path, const char *rev)
 		path[len - 1] = tail;
 }
 
-const struct date_mode *cgit_date_mode(const char *format)
+const struct date_mode *cgit_date_mode(enum date_mode_type type)
 {
 	static struct date_mode mode;
-	mode.type = DATE_STRFTIME;
-	mode.strftime_fmt = format;
+	mode.type = type;
 	mode.local = ctx.cfg.local_time;
 	return &mode;
 }
@@ -620,7 +619,7 @@ static void print_rel_date(time_t t, int tz, double value,
 	const char *class, const char *suffix)
 {
 	htmlf("<span class='%s' title='", class);
-	html_attr(show_date(t, tz, cgit_date_mode(FMT_LONGDATE)));
+	html_attr(show_date(t, tz, cgit_date_mode(DATE_ISO8601)));
 	htmlf("'>%.0f %s</span>", value, suffix);
 }
 
@@ -637,9 +636,9 @@ void cgit_print_age(time_t t, int tz, time_t max_relative)
 
 	if (secs > max_relative && max_relative >= 0) {
 		html("<span title='");
-		html_attr(show_date(t, tz, cgit_date_mode(FMT_LONGDATE)));
+		html_attr(show_date(t, tz, cgit_date_mode(DATE_ISO8601)));
 		html("'>");
-		html_txt(show_date(t, tz, cgit_date_mode(FMT_SHORTDATE)));
+		html_txt(show_date(t, tz, cgit_date_mode(DATE_SHORT)));
 		html("</span>");
 		return;
 	}
@@ -781,7 +780,7 @@ void cgit_print_docend(void)
 	else {
 		htmlf("<div class='footer'>generated by <a href='http://git.zx2c4.com/cgit/about/'>cgit %s</a> at ",
 			cgit_version);
-		html_txt(show_date(time(NULL), 0, cgit_date_mode(FMT_LONGDATE)));
+		html_txt(show_date(time(NULL), 0, cgit_date_mode(DATE_ISO8601)));
 		html("</div>\n");
 	}
 	html("</div> <!-- id=cgit -->\n");
diff --git a/ui-shared.h b/ui-shared.h
index 43789de..b457c97 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -61,7 +61,7 @@ __attribute__((format (printf,1,2)))
 extern void cgit_print_error(const char *fmt, ...);
 __attribute__((format (printf,1,0)))
 extern void cgit_vprint_error(const char *fmt, va_list ap);
-extern const struct date_mode *cgit_date_mode(const char *format);
+extern const struct date_mode *cgit_date_mode(enum date_mode_type type);
 extern void cgit_print_age(time_t t, int tz, time_t max_relative);
 extern void cgit_print_http_headers(void);
 extern void cgit_redirect(const char *url, bool permanent);
diff --git a/ui-tag.c b/ui-tag.c
index b011198..6b838cb 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -77,7 +77,7 @@ void cgit_print_tag(char *revname)
 		if (info->tagger_date > 0) {
 			html("<tr><td>tag date</td><td>");
 			html_txt(show_date(info->tagger_date, info->tagger_tz,
-						cgit_date_mode(FMT_LONGDATE)));
+						cgit_date_mode(DATE_ISO8601)));
 			html("</td></tr>\n");
 		}
 		if (info->tagger) {
-- 
2.7.0.389.ga73dcac



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 2/2] ui-atom: avoid DATE_STRFTIME
  2016-02-08 15:05         ` [PATCH 1/2] Avoid DATE_STRFTIME for long/short dates john
@ 2016-02-08 15:06           ` john
  0 siblings, 0 replies; 17+ messages in thread
From: john @ 2016-02-08 15:06 UTC (permalink / raw)


Git's DATE_STRFTIME ignores the timezone argument and just uses the
local timezone regardless of whether the "local" flag is set.

Since Atom accepts ISO8601 dates [1], we can use Git's
DATE_ISO8601_STRICT instead, which does get this right.  Additionally,
we never use the local timezone here so we can use the
date_mode_from_type() wrapper to simplify the code a bit.

[1] https://tools.ietf.org/html/rfc4287#section-3.3

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 cgit.h    |  5 -----
 ui-atom.c | 11 ++++-------
 2 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/cgit.h b/cgit.h
index 5adef4d..d10c799 100644
--- a/cgit.h
+++ b/cgit.h
@@ -29,11 +29,6 @@
 #undef isgraph
 #define isgraph(x) (isprint((x)) && !isspace((x)))
 
-/*
- * Dateformats used on misc. pages
- */
-#define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ"
-
 
 /*
  * Limits used for relative dates
diff --git a/ui-atom.c b/ui-atom.c
index 0bf2cf2..41838d3 100644
--- a/ui-atom.c
+++ b/ui-atom.c
@@ -17,11 +17,6 @@ static void add_entry(struct commit *commit, const char *host)
 	char *hex;
 	char *mail, *t, *t2;
 	struct commitinfo *info;
-	struct date_mode mode = {
-		.type = DATE_STRFTIME,
-		.strftime_fmt = FMT_ATOMDATE,
-		.local = 0,
-	};
 
 	info = cgit_parse_commit(commit);
 	hex = oid_to_hex(&commit->object.oid);
@@ -30,7 +25,8 @@ static void add_entry(struct commit *commit, const char *host)
 	html_txt(info->subject);
 	html("</title>\n");
 	html("<updated>");
-	html_txt(show_date(info->committer_date, 0, &mode));
+	html_txt(show_date(info->committer_date, 0,
+                    date_mode_from_type(DATE_ISO8601_STRICT)));
 	html("</updated>\n");
 	html("<author>\n");
 	if (info->author) {
@@ -55,7 +51,8 @@ static void add_entry(struct commit *commit, const char *host)
 	}
 	html("</author>\n");
 	html("<published>");
-	html_txt(show_date(info->author_date, 0, &mode));
+	html_txt(show_date(info->author_date, 0,
+                    date_mode_from_type(DATE_ISO8601_STRICT)));
 	html("</published>\n");
 	if (host) {
 		char *pageurl;
-- 
2.7.0.389.ga73dcac



^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2016-02-08 15:06 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-19 19:33 [PATCH 0/8] Show times in the originator's timezone john
2016-01-19 19:33 ` [PATCH 1/8] ui-shared: remove "format" from cgit_print_age() john
2016-01-19 19:33 ` [PATCH 2/8] parsing: add timezone to ident structures john
2016-01-19 19:33 ` [PATCH 3/8] ui-shared: add cgit_date_mode() john
2016-02-08 13:20   ` Jason
2016-02-08 13:23     ` Jason
2016-01-19 19:33 ` [PATCH 4/8] ui-{commit,tag}: show dates in originator's timezone john
2016-01-19 19:33 ` [PATCH 5/8] ui: show ages in the " john
2016-01-19 19:33 ` [PATCH 6/8] ui-shared: use show_date for footer timestamp john
2016-01-19 19:33 ` [PATCH 7/8] ui-atom: use show_date directly for atom dates john
2016-01-19 19:33 ` [PATCH 8/8] ui-shared: remove cgit_print_date() john
2016-02-08 13:23 ` [PATCH 0/8] Show times in the originator's timezone Jason
2016-02-08 13:38   ` Jason
2016-02-08 14:08     ` john
2016-02-08 14:33       ` Jason
2016-02-08 15:05         ` [PATCH 1/2] Avoid DATE_STRFTIME for long/short dates john
2016-02-08 15:06           ` [PATCH 2/2] ui-atom: avoid DATE_STRFTIME john

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).