Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit bdb830c

Browse files
committed
Merge branch 'jk/commit-dates-parsing-fix'
Finishing touches for portability. * jk/commit-dates-parsing-fix: t4212: loosen far-in-future test for AIX date: recognize bogus FreeBSD gmtime output
2 parents 4e49d95 + f80d1f9 commit bdb830c

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ all::
338338
# Define TEST_GIT_INDEX_VERSION to 2, 3 or 4 to run the test suite
339339
# with a different indexfile format version. If it isn't set the index
340340
# file format used is index-v[23].
341+
#
342+
# Define GMTIME_UNRELIABLE_ERRORS if your gmtime() function does not
343+
# return NULL when it receives a bogus time_t.
341344

342345
GIT-VERSION-FILE: FORCE
343346
@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -1489,6 +1492,11 @@ ifneq (,$(XDL_FAST_HASH))
14891492
BASIC_CFLAGS += -DXDL_FAST_HASH
14901493
endif
14911494

1495+
ifdef GMTIME_UNRELIABLE_ERRORS
1496+
COMPAT_OBJS += compat/gmtime.o
1497+
BASIC_CFLAGS += -DGMTIME_UNRELIABLE_ERRORS
1498+
endif
1499+
14921500
ifeq ($(TCLTK_PATH),)
14931501
NO_TCLTK = NoThanks
14941502
endif

compat/gmtime.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "../git-compat-util.h"
2+
#undef gmtime
3+
#undef gmtime_r
4+
5+
struct tm *git_gmtime(const time_t *timep)
6+
{
7+
static struct tm result;
8+
return git_gmtime_r(timep, &result);
9+
}
10+
11+
struct tm *git_gmtime_r(const time_t *timep, struct tm *result)
12+
{
13+
struct tm *ret;
14+
15+
memset(result, 0, sizeof(*result));
16+
ret = gmtime_r(timep, result);
17+
18+
/*
19+
* Rather than NULL, FreeBSD gmtime simply leaves the "struct tm"
20+
* untouched when it encounters overflow. Since "mday" cannot otherwise
21+
* be zero, we can test this very quickly.
22+
*/
23+
if (ret && !ret->tm_mday) {
24+
ret = NULL;
25+
errno = EOVERFLOW;
26+
}
27+
28+
return ret;
29+
}

config.mak.uname

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ ifeq ($(uname_S),FreeBSD)
187187
endif
188188
PYTHON_PATH = /usr/local/bin/python
189189
HAVE_PATHS_H = YesPlease
190+
GMTIME_UNRELIABLE_ERRORS = UnfortunatelyYes
190191
endif
191192
ifeq ($(uname_S),OpenBSD)
192193
NO_STRCASESTR = YesPlease

git-compat-util.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,4 +716,11 @@ void warn_on_inaccessible(const char *path);
716716
/* Get the passwd entry for the UID of the current process. */
717717
struct passwd *xgetpwuid_self(void);
718718

719+
#ifdef GMTIME_UNRELIABLE_ERRORS
720+
struct tm *git_gmtime(const time_t *);
721+
struct tm *git_gmtime_r(const time_t *, struct tm *);
722+
#define gmtime git_gmtime
723+
#define gmtime_r git_gmtime_r
724+
#endif
725+
719726
#endif

t/t4212-log-corrupt.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,9 @@ test_expect_success 'date parser recognizes time_t overflow' '
8282
'
8383

8484
# date is within 2^63-1, but enough to choke glibc's gmtime
85-
test_expect_success 'absurdly far-in-future dates produce sentinel' '
85+
test_expect_success 'absurdly far-in-future date' '
8686
commit=$(munge_author_date HEAD 999999999999999999) &&
87-
echo "Thu Jan 1 00:00:00 1970 +0000" >expect &&
88-
git log -1 --format=%ad $commit >actual &&
89-
test_cmp expect actual
87+
git log -1 --format=%ad $commit
9088
'
9189

9290
test_done

0 commit comments

Comments
 (0)