git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 2/8] t0006 & t5000: prepare for 64-bit timestamps

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Apr 20, 2017, 20:52 UTC
Message-ID
<4061101de2cea4e2b55b6b58bfd4bbd30fe5465e.1492721487.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1492721487.git.johannes.schindelin@gmx.de>

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 6b9c38e14cd (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 <johannes.schindelin@gmx.de>
---
 t/helper/test-date.c | 5 ++++-
 t/t0006-date.sh      | 4 ++--
 t/t5000-tar-tree.sh  | 6 +++---
 t/test-lib.sh        | 2 ++
 4 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/t/helper/test-date.c b/t/helper/test-date.c
index 506054bcd5d..4727bea255c 100644
--- a/t/helper/test-date.c
+++ b/t/helper/test-date.c
@@ -4,7 +4,8 @@ static const char *usage_msg = "\n"
 "  test-date relative [time_t]...\n"
 "  test-date show:<format> [time_t]...\n"
 "  test-date parse [date]...\n"
-"  test-date approxidate [date]...\n";
+"  test-date approxidate [date]...\n"
+"  test-date is64bit\n";
 
 static void show_relative_dates(const char **argv, struct timeval *now)
 {
@@ -93,6 +94,8 @@ int cmd_main(int argc, const char **argv)
 		parse_dates(argv+1, &now);
 	else if (!strcmp(*argv, "approxidate"))
 		parse_approxidate(argv+1, &now);
+	else if (!strcmp(*argv, "is64bit"))
+		return sizeof(unsigned long) == 8 ? 0 : 1;
 	else
 		usage(usage_msg);
 	return 0;
diff --git a/t/t0006-date.sh b/t/t0006-date.sh
index c0c910867d7..9539b425ffb 100755
--- a/t/t0006-date.sh
+++ b/t/t0006-date.sh
@@ -53,8 +53,8 @@ check_show unix-local "$TIME" '1466000000'
 
 # arbitrary time absurdly far in the future
 FUTURE="5758122296 -0400"
-check_show iso       "$FUTURE" "2152-06-19 18:24:56 -0400" LONG_IS_64BIT
-check_show iso-local "$FUTURE" "2152-06-19 22:24:56 +0000" LONG_IS_64BIT
+check_show iso       "$FUTURE" "2152-06-19 18:24:56 -0400" TIME_IS_64BIT
+check_show iso-local "$FUTURE" "2152-06-19 22:24:56 +0000" TIME_IS_64BIT
 
 check_parse() {
 	echo "$1 -> $2" >expect
diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh
index 886b6953e40..997aa9dea28 100755
--- a/t/t5000-tar-tree.sh
+++ b/t/t5000-tar-tree.sh
@@ -390,7 +390,7 @@ test_expect_success TAR_HUGE,LONG_IS_64BIT 'system tar can read our huge size' '
 	test_cmp expect actual
 '
 
-test_expect_success LONG_IS_64BIT 'set up repository with far-future commit' '
+test_expect_success TIME_IS_64BIT 'set up repository with far-future commit' '
 	rm -f .git/index &&
 	echo content >file &&
 	git add file &&
@@ -398,11 +398,11 @@ test_expect_success LONG_IS_64BIT 'set up repository with far-future commit' '
 		git commit -m "tempori parendum"
 '
 
-test_expect_success LONG_IS_64BIT 'generate tar with future mtime' '
+test_expect_success TIME_IS_64BIT 'generate tar with future mtime' '
 	git archive HEAD >future.tar
 '
 
-test_expect_success TAR_HUGE,LONG_IS_64BIT 'system tar can read our future mtime' '
+test_expect_success TAR_HUGE,TIME_IS_64BIT 'system tar can read our future mtime' '
 	echo 4147 >expect &&
 	tar_info future.tar | cut -d" " -f2 >actual &&
 	test_cmp expect actual
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 13b5696822d..beee1d847ff 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1164,3 +1164,5 @@ build_option () {
 test_lazy_prereq LONG_IS_64BIT '
 	test 8 -le "$(build_option sizeof-long)"
 '
+
+test_lazy_prereq TIME_IS_64BIT 'test-date is64bit'
-- 
2.12.2.windows.2.406.gd14a8f8640f
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 46 of 113 in “Use time_t”
  1. 0/6 Use time_tJohannes Schindelin, Feb 27, 2017
  2. 5/6 ref-filter: avoid using `unsigned long` for catch-all data typeJohannes Schindelin, Feb 27, 2017
  3. 4/6 Prepare for timestamps to use 64-bit signed typesJohannes Schindelin, Feb 27, 2017
  4. 3/6 Introduce a new "printf format" for timestampsJohannes Schindelin, Feb 27, 2017
  5. Junio C HamanoMar 1, 2017
  6. Junio C HamanoMar 1, 2017
  7. 2/6 Specify explicitly where we parse timestampsJohannes Schindelin, Feb 27, 2017
  8. Junio C HamanoFeb 27, 2017
  9. Junio C HamanoFeb 27, 2017
  10. Johannes SchindelinFeb 28, 2017
  11. 1/6 t0006 & t5000: prepare for 64-bit time_tJohannes Schindelin, Feb 27, 2017
  12. Junio C HamanoFeb 27, 2017
  13. 6/6 Use time_t where appropriateJohannes Schindelin, Feb 27, 2017
  14. Junio C HamanoFeb 27, 2017
  15. Johannes SchindelinFeb 28, 2017
  16. Jeff KingFeb 28, 2017
  17. Johannes SchindelinFeb 28, 2017
  18. René ScharfeFeb 28, 2017
  19. Junio C HamanoFeb 28, 2017
  20. Jeff KingFeb 28, 2017
  21. Johannes SchindelinFeb 28, 2017
  22. Jeff KingFeb 28, 2017
  23. René ScharfeFeb 28, 2017
  24. Johannes SchindelinFeb 28, 2017
  25. René ScharfeMar 1, 2017
  26. Junio C HamanoFeb 28, 2017
  27. Jeff KingFeb 28, 2017
  28. Junio C HamanoFeb 28, 2017
  29. Jeff KingFeb 28, 2017
  30. Junio C HamanoMar 1, 2017
  31. 0/8 Introduce timestamp_t for timestampsJohannes Schindelin, Apr 2, 2017
  32. 1/8 ref-filter: avoid using `unsigned long` for catch-all data typeJohannes Schindelin, Apr 2, 2017
  33. Torsten BögershausenApr 3, 2017
  34. Johannes SchindelinApr 3, 2017
  35. 2/8 t0006 & t5000: prepare for 64-bit timestampsJohannes Schindelin, Apr 2, 2017
  36. 3/8 t0006 & t5000: skip "far in the future" test when time_t is too limitedJohannes Schindelin, Apr 2, 2017
  37. 4/8 Specify explicitly where we parse timestampsJohannes Schindelin, Apr 2, 2017
  38. Torsten BögershausenApr 3, 2017
  39. Johannes SchindelinApr 3, 2017
  40. 5/8 Introduce a new "printf format" for timestampsJohannes Schindelin, Apr 2, 2017
  41. 6/8 Introduce a new data type for timestampsJohannes Schindelin, Apr 2, 2017
  42. 7/8 Abort if the system time cannot handle one of our timestampsJohannes Schindelin, Apr 2, 2017
  43. 8/8 Use uintmax_t for timestampsJohannes Schindelin, Apr 2, 2017
  44. 0/8 Introduce timestamp_t for timestampsJohannes Schindelin, Apr 20, 2017
  45. 1/8 ref-filter: avoid using `unsigned long` for catch-all data typeJohannes Schindelin, Apr 20, 2017
  46. 2/8 t0006 & t5000: prepare for 64-bit timestampsJohannes Schindelin, Apr 20, 2017
  47. 3/8 t0006 & t5000: skip "far in the future" test when time_t is too limitedJohannes Schindelin, Apr 20, 2017
  48. 4/8 Specify explicitly where we parse timestampsJohannes Schindelin, Apr 20, 2017
  49. 5/8 Introduce a new "printf format" for timestampsJohannes Schindelin, Apr 20, 2017
  50. 6/8 Introduce a new data type for timestampsJohannes Schindelin, Apr 20, 2017
  51. 8/8 Use uintmax_t for timestampsJohannes Schindelin, Apr 20, 2017
  52. 7/8 Abort if the system time cannot handle one of our timestampsJohannes Schindelin, Apr 20, 2017
  53. Junio C HamanoApr 21, 2017
  54. Johannes SchindelinApr 21, 2017
  55. 0/9 Introduce timestamp_t for timestampsJohannes Schindelin, Apr 21, 2017
  56. 1/9 ref-filter: avoid using `unsigned long` for catch-all data typeJohannes Schindelin, Apr 21, 2017
  57. 2/9 t0006 & t5000: prepare for 64-bit timestampsJohannes Schindelin, Apr 21, 2017
  58. 3/9 t0006 & t5000: skip "far in the future" test when time_t is too limitedJohannes Schindelin, Apr 21, 2017
  59. 4/9 Specify explicitly where we parse timestampsJohannes Schindelin, Apr 21, 2017
  60. Junio C HamanoApr 24, 2017
  61. 5/9 Introduce a new "printf format" for timestampsJohannes Schindelin, Apr 21, 2017
  62. 6/9 Introduce a new data type for timestampsJohannes Schindelin, Apr 21, 2017
  63. 7/9 Abort if the system time cannot handle one of our timestampsJohannes Schindelin, Apr 21, 2017
  64. Junio C HamanoApr 24, 2017
  65. Johannes SchindelinApr 24, 2017
  66. Junio C HamanoApr 25, 2017
  67. Junio C HamanoApr 25, 2017
  68. 8/9 Use uintmax_t for timestampsJohannes Schindelin, Apr 21, 2017
  69. Junio C HamanoApr 24, 2017
  70. Johannes SchindelinApr 24, 2017
  71. Junio C HamanoApr 25, 2017
  72. Johannes SchindelinApr 25, 2017
  73. Junio C HamanoApr 26, 2017
  74. Junio C HamanoApr 26, 2017
  75. Johannes SchindelinApr 26, 2017
  76. Junio C HamanoApr 26, 2017
  77. 9/9 show_date_ident(): defer date overflow checkJohannes Schindelin, Apr 21, 2017
  78. Junio C HamanoApr 24, 2017
  79. Jacob KellerApr 24, 2017
  80. Johannes SchindelinApr 24, 2017
  81. Jeff KingApr 24, 2017
  82. Johannes SchindelinApr 25, 2017
  83. Johannes SchindelinApr 24, 2017
  84. 0/8 Introduce timestamp_t for timestampsJohannes Schindelin, Apr 24, 2017
  85. 1/8 ref-filter: avoid using `unsigned long` for catch-all data typeJohannes Schindelin, Apr 24, 2017
  86. 2/8 t0006 & t5000: prepare for 64-bit timestampsJohannes Schindelin, Apr 24, 2017
  87. 3/8 t0006 & t5000: skip "far in the future" test when time_t is too limitedJohannes Schindelin, Apr 24, 2017
  88. 5/8 Introduce a new "printf format" for timestampsJohannes Schindelin, Apr 24, 2017
  89. 4/8 Specify explicitly where we parse timestampsJohannes Schindelin, Apr 24, 2017
  90. Junio C HamanoApr 25, 2017
  91. 6/8 Introduce a new data type for timestampsJohannes Schindelin, Apr 24, 2017
  92. Johannes SixtApr 26, 2017
  93. Johannes SchindelinApr 26, 2017
  94. René ScharfeApr 26, 2017
  95. 7/8 Abort if the system time cannot handle one of our timestampsJohannes Schindelin, Apr 24, 2017
  96. 8/8 Use uintmax_t for timestampsJohannes Schindelin, Apr 24, 2017
  97. Johannes SixtApr 26, 2017
  98. Johannes SchindelinApr 26, 2017
  99. René ScharfeApr 25, 2017
  100. Johannes SchindelinApr 25, 2017
  101. René ScharfeApr 26, 2017
  102. Junio C HamanoApr 26, 2017
  103. 0/8 Introduce timestamp_t for timestampsJohannes Schindelin, Apr 26, 2017
  104. 1/8 ref-filter: avoid using `unsigned long` for catch-all data typeJohannes Schindelin, Apr 26, 2017
  105. 2/8 t0006 & t5000: prepare for 64-bit timestampsJohannes Schindelin, Apr 26, 2017
  106. 3/8 t0006 & t5000: skip "far in the future" test when time_t is too limitedJohannes Schindelin, Apr 26, 2017
  107. 4/8 Specify explicitly where we parse timestampsJohannes Schindelin, Apr 26, 2017
  108. 5/8 Introduce a new "printf format" for timestampsJohannes Schindelin, Apr 26, 2017
  109. 6/8 Introduce a new data type for timestampsJohannes Schindelin, Apr 26, 2017
  110. name-rev: change a "long" variable to timestamp_tJunio C Hamano, May 20, 2017
  111. Johannes SchindelinMay 22, 2017
  112. 7/8 Abort if the system time cannot handle one of our timestampsJohannes Schindelin, Apr 26, 2017
  113. 8/8 Use uintmax_t for timestampsJohannes Schindelin, Apr 26, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.