Skip to content

Commit 4fdee76

Browse files
committed
extra warning hack
This is to get information from Windows CI, which is failing. I think the issue is that its gmtime() returns garbage (or maybe an error?) for negative timestamps. We'd probably need to steal reverse of days_to_civil() from the HowardHinnant/date collection. Signed-off-by: Jeff King <[email protected]>
1 parent 5f00e02 commit 4fdee76

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

date.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "gettext.h"
1212
#include "pager.h"
1313
#include "strbuf.h"
14+
#include "trace.h"
1415

1516
/*
1617
* Convert a year-month-day time into a number of days since 1970 (possibly
@@ -96,10 +97,20 @@ static time_t gm_time_t(timestamp_t time, int tz)
9697
* thing, which means that tz -0100 is passed in as the integer -100,
9798
* even though it means "sixty minutes off"
9899
*/
100+
static struct trace_key trace_date = TRACE_KEY_INIT(DATE);
101+
99102
static struct tm *time_to_tm(timestamp_t time, int tz, struct tm *tm)
100103
{
104+
struct tm *ret;
101105
time_t t = gm_time_t(time, tz);
102-
return gmtime_r(&t, tm);
106+
trace_printf_key(&trace_date,
107+
"gm_time_t(%"PRIdMAX", %d) = %"PRIdMAX,
108+
(intmax_t)time, tz, (intmax_t)t);
109+
ret = gmtime_r(&t, tm);
110+
trace_printf_key(&trace_date,
111+
"gmtime_r(%"PRIdMAX") = %p",
112+
(intmax_t)t, (void *)ret);
113+
return ret;
103114
}
104115

105116
static struct tm *time_to_tm_local(timestamp_t time, struct tm *tm)
@@ -354,6 +365,9 @@ const char *show_date(timestamp_t time, int tz, struct date_mode mode)
354365
else
355366
tm = time_to_tm(time, tz, &tmbuf);
356367
if (!tm) {
368+
trace_printf_key(&trace_date,
369+
"unable to handle timestamp %"PRIdMAX,
370+
(intmax_t)time);
357371
tm = time_to_tm(0, 0, &tmbuf);
358372
tz = 0;
359373
}

t/t1200-negative-timestamps.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
test_description='handling of timestamps before 1970'
44
. ./test-lib.sh
55

6+
GIT_TRACE_DATE=1
7+
export GIT_TRACE_DATE
8+
69
test_expect_success 'create a commit with a negative timestamp' '
710
tree=$(git hash-object -w -t tree --stdin </dev/null) &&
811
commit=$(

0 commit comments

Comments
 (0)