about summary refs log tree commit diff
path: root/third_party/git/date.c
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-25T23·06+0100
committerVincent Ambo <tazjin@google.com>2020-05-25T23·06+0100
commit93ba78d6f4632ef1c5228965e3edc8c0faf88c1e (patch)
tree85730c182a9f5f492ade8e8ccdb1c2356f9900bd /third_party/git/date.c
parent6f8fbf4aa4b1654ab27d4829e114538761817de0 (diff)
revert(3p/git): Revert merge of git upstream at v2.26.2 r/852
This causes cgit to serve error pages, which is undesirable.

This reverts commit 5229c9b232de5bfa959ad6ebbb4c8192ac513352, reversing
changes made to f2b211131f2347342dde63975b09cf603149f1a3.
Diffstat (limited to 'third_party/git/date.c')
-rw-r--r--third_party/git/date.c45
1 files changed, 22 insertions, 23 deletions
diff --git a/third_party/git/date.c b/third_party/git/date.c
index 0355c0676bda..06340a77f319 100644
--- a/third_party/git/date.c
+++ b/third_party/git/date.c
@@ -64,16 +64,16 @@ static time_t gm_time_t(timestamp_t time, int tz)
  * thing, which means that tz -0100 is passed in as the integer -100,
  * even though it means "sixty minutes off"
  */
-static struct tm *time_to_tm(timestamp_t time, int tz, struct tm *tm)
+static struct tm *time_to_tm(timestamp_t time, int tz)
 {
 	time_t t = gm_time_t(time, tz);
-	return gmtime_r(&t, tm);
+	return gmtime(&t);
 }
 
-static struct tm *time_to_tm_local(timestamp_t time, struct tm *tm)
+static struct tm *time_to_tm_local(timestamp_t time)
 {
 	time_t t = time;
-	return localtime_r(&t, tm);
+	return localtime(&t);
 }
 
 /*
@@ -128,17 +128,16 @@ static void get_time(struct timeval *now)
 		gettimeofday(now, NULL);
 }
 
-void show_date_relative(timestamp_t time, struct strbuf *timebuf)
+void show_date_relative(timestamp_t time,
+			const struct timeval *now,
+			struct strbuf *timebuf)
 {
-	struct timeval now;
 	timestamp_t diff;
-
-	get_time(&now);
-	if (now.tv_sec < time) {
+	if (now->tv_sec < time) {
 		strbuf_addstr(timebuf, _("in the future"));
 		return;
 	}
-	diff = now.tv_sec - time;
+	diff = now->tv_sec - time;
 	if (diff < 90) {
 		strbuf_addf(timebuf,
 			 Q_("%"PRItime" second ago", "%"PRItime" seconds ago", diff), diff);
@@ -241,7 +240,9 @@ static void show_date_normal(struct strbuf *buf, timestamp_t time, struct tm *tm
 
 	/* Show "today" times as just relative times */
 	if (hide.wday) {
-		show_date_relative(time, buf);
+		struct timeval now;
+		get_time(&now);
+		show_date_relative(time, &now, buf);
 		return;
 	}
 
@@ -283,7 +284,6 @@ static void show_date_normal(struct strbuf *buf, timestamp_t time, struct tm *tm
 const char *show_date(timestamp_t time, int tz, const struct date_mode *mode)
 {
 	struct tm *tm;
-	struct tm tmbuf = { 0 };
 	struct tm human_tm = { 0 };
 	int human_tz = -1;
 	static struct strbuf timebuf = STRBUF_INIT;
@@ -313,17 +313,20 @@ const char *show_date(timestamp_t time, int tz, const struct date_mode *mode)
 	}
 
 	if (mode->type == DATE_RELATIVE) {
+		struct timeval now;
+
 		strbuf_reset(&timebuf);
-		show_date_relative(time, &timebuf);
+		get_time(&now);
+		show_date_relative(time, &now, &timebuf);
 		return timebuf.buf;
 	}
 
 	if (mode->local)
-		tm = time_to_tm_local(time, &tmbuf);
+		tm = time_to_tm_local(time);
 	else
-		tm = time_to_tm(time, tz, &tmbuf);
+		tm = time_to_tm(time, tz);
 	if (!tm) {
-		tm = time_to_tm(0, 0, &tmbuf);
+		tm = time_to_tm(0, 0);
 		tz = 0;
 	}
 
@@ -977,11 +980,10 @@ void datestamp(struct strbuf *out)
 {
 	time_t now;
 	int offset;
-	struct tm tm = { 0 };
 
 	time(&now);
 
-	offset = tm_to_time_t(localtime_r(&now, &tm)) - now;
+	offset = tm_to_time_t(localtime(&now)) - now;
 	offset /= 60;
 
 	date_string(now, offset, out);
@@ -1303,18 +1305,15 @@ static timestamp_t approxidate_str(const char *date,
 	return (timestamp_t)update_tm(&tm, &now, 0);
 }
 
-timestamp_t approxidate_relative(const char *date)
+timestamp_t approxidate_relative(const char *date, const struct timeval *tv)
 {
-	struct timeval tv;
 	timestamp_t timestamp;
 	int offset;
 	int errors = 0;
 
 	if (!parse_date_basic(date, &timestamp, &offset))
 		return timestamp;
-
-	get_time(&tv);
-	return approxidate_str(date, (const struct timeval *) &tv, &errors);
+	return approxidate_str(date, tv, &errors);
 }
 
 timestamp_t approxidate_careful(const char *date, int *error_ret)