Skip to content

Commit a07fb05

Browse files
dschogitster
authored andcommitted
t0006 & t5000: prepare for 64-bit timestamps
Git's source code refers to timestamps as unsigned longs. On 32-bit platforms, as well as on Windows, unsigned long is not large enough to capture dates that are "absurdly far in the future". It is perfectly valid by the C standard, of course, for the `long` data type to refer to 32-bit integers. That is why the `time_t` data type exists: so that it can be 64-bit even if `long` is 32-bit. Git's source code simply uses an incorrect data type for timestamps, is all. The earlier quick fix 6b9c38e (t0006: skip "far in the future" test when unsigned long is not long enough, 2016-07-11) papered over this issue simply by skipping the respective test cases on platforms where they would fail due to the data type in use. This quick fix, however, tests for *long* to be 64-bit or not. What we need, though, is a test that says whether *whatever data type we use for timestamps* is 64-bit or not. The same quick fix was used to handle the similar problem where Git's source code uses `unsigned long` to represent size, instead of `size_t`, conflating the two issues. So let's just add another prerequisite to test specifically whether timestamps are represented by a 64-bit data type or not. Later, after we switch to a larger data type, we can flip that prerequisite to test `time_t` instead of `long`. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e467dc1 commit a07fb05

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

t/helper/test-date.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ static const char *usage_msg = "\n"
44
" test-date relative [time_t]...\n"
55
" test-date show:<format> [time_t]...\n"
66
" test-date parse [date]...\n"
7-
" test-date approxidate [date]...\n";
7+
" test-date approxidate [date]...\n"
8+
" test-date is64bit\n";
89

910
static void show_relative_dates(const char **argv, struct timeval *now)
1011
{
@@ -93,6 +94,8 @@ int cmd_main(int argc, const char **argv)
9394
parse_dates(argv+1, &now);
9495
else if (!strcmp(*argv, "approxidate"))
9596
parse_approxidate(argv+1, &now);
97+
else if (!strcmp(*argv, "is64bit"))
98+
return sizeof(unsigned long) == 8 ? 0 : 1;
9699
else
97100
usage(usage_msg);
98101
return 0;

t/t0006-date.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ check_show unix-local "$TIME" '1466000000'
5353

5454
# arbitrary time absurdly far in the future
5555
FUTURE="5758122296 -0400"
56-
check_show iso "$FUTURE" "2152-06-19 18:24:56 -0400" LONG_IS_64BIT
57-
check_show iso-local "$FUTURE" "2152-06-19 22:24:56 +0000" LONG_IS_64BIT
56+
check_show iso "$FUTURE" "2152-06-19 18:24:56 -0400" TIME_IS_64BIT
57+
check_show iso-local "$FUTURE" "2152-06-19 22:24:56 +0000" TIME_IS_64BIT
5858

5959
check_parse() {
6060
echo "$1 -> $2" >expect

t/t5000-tar-tree.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,19 +390,19 @@ test_expect_success TAR_HUGE,LONG_IS_64BIT 'system tar can read our huge size' '
390390
test_cmp expect actual
391391
'
392392

393-
test_expect_success LONG_IS_64BIT 'set up repository with far-future commit' '
393+
test_expect_success TIME_IS_64BIT 'set up repository with far-future commit' '
394394
rm -f .git/index &&
395395
echo content >file &&
396396
git add file &&
397397
GIT_COMMITTER_DATE="@68719476737 +0000" \
398398
git commit -m "tempori parendum"
399399
'
400400

401-
test_expect_success LONG_IS_64BIT 'generate tar with future mtime' '
401+
test_expect_success TIME_IS_64BIT 'generate tar with future mtime' '
402402
git archive HEAD >future.tar
403403
'
404404

405-
test_expect_success TAR_HUGE,LONG_IS_64BIT 'system tar can read our future mtime' '
405+
test_expect_success TAR_HUGE,TIME_IS_64BIT 'system tar can read our future mtime' '
406406
echo 4147 >expect &&
407407
tar_info future.tar | cut -d" " -f2 >actual &&
408408
test_cmp expect actual

t/test-lib.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,3 +1164,5 @@ build_option () {
11641164
test_lazy_prereq LONG_IS_64BIT '
11651165
test 8 -le "$(build_option sizeof-long)"
11661166
'
1167+
1168+
test_lazy_prereq TIME_IS_64BIT 'test-date is64bit'

0 commit comments

Comments
 (0)