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

[PATCH v2 4/8] Specify explicitly where we parse timestamps

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Apr 2, 2017, 19:06 UTC
Message-ID
<7876460edaa85d93b60c0cc1b2f9a715de97180c.1491159939.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1491159939.git.johannes.schindelin@gmx.de>

Currently, Git's source code represents all timestamps as `unsigned long`. In preparation for using a more appropriate data type, let's introduce a symbol `parse_timestamp` (currently being defined to `strtoul`) where appropriate, so that we can later easily switch to, say, use `strtoull()` instead.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin/am.c           | 2 +-
 builtin/receive-pack.c | 4 ++--
 bundle.c               | 2 +-
 commit.c               | 6 +++---
 date.c                 | 6 +++---
 fsck.c                 | 2 +-
 git-compat-util.h      | 2 ++
 pretty.c               | 2 +-
 ref-filter.c           | 2 +-
 refs/files-backend.c   | 2 +-
 t/helper/test-date.c   | 2 +-
 tag.c                  | 4 ++--
 upload-pack.c          | 2 +-
 13 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/builtin/am.c b/builtin/am.c
index f7a7a971fbe..2c93adc69c3 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -882,7 +882,7 @@ static int hg_patch_to_mail(FILE *out, FILE *in, int keep_cr)
 			char *end;
 
 			errno = 0;
-			timestamp = strtoul(str, &end, 10);
+			timestamp = parse_timestamp(str, &end, 10);
 			if (errno)
 				return error(_("invalid timestamp"));
 
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index aca9c33d8d8..fd8a24dd47e 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -534,7 +534,7 @@ static const char *check_nonce(const char *buf, size_t len)
 		retval = NONCE_BAD;
 		goto leave;
 	}
-	stamp = strtoul(nonce, &bohmac, 10);
+	stamp = parse_timestamp(nonce, &bohmac, 10);
 	if (bohmac == nonce || bohmac[0] != '-') {
 		retval = NONCE_BAD;
 		goto leave;
@@ -552,7 +552,7 @@ static const char *check_nonce(const char *buf, size_t len)
 	 * would mean it was issued by another server with its clock
 	 * skewed in the future.
 	 */
-	ostamp = strtoul(push_cert_nonce, NULL, 10);
+	ostamp = parse_timestamp(push_cert_nonce, NULL, 10);
 	nonce_stamp_slop = (long)ostamp - (long)stamp;
 
 	if (nonce_stamp_slop_limit &&
diff --git a/bundle.c b/bundle.c
index bbf4efa0a0a..f43bfcf5ff3 100644
--- a/bundle.c
+++ b/bundle.c
@@ -227,7 +227,7 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
 	line = memchr(line, '>', lineend ? lineend - line : buf + size - line);
 	if (!line++)
 		goto out;
-	date = strtoul(line, NULL, 10);
+	date = parse_timestamp(line, NULL, 10);
 	result = (revs->max_age == -1 || revs->max_age < date) &&
 		(revs->min_age == -1 || revs->min_age > date);
 out:
diff --git a/commit.c b/commit.c
index 73c78c2b80c..0d2d0fa1984 100644
--- a/commit.c
+++ b/commit.c
@@ -89,8 +89,8 @@ static unsigned long parse_commit_date(const char *buf, const char *tail)
 		/* nada */;
 	if (buf >= tail)
 		return 0;
-	/* dateptr < buf && buf[-1] == '\n', so strtoul will stop at buf-1 */
-	return strtoul(dateptr, NULL, 10);
+	/* dateptr < buf && buf[-1] == '\n', so parsing will stop at buf-1 */
+	return parse_timestamp(dateptr, NULL, 10);
 }
 
 static struct commit_graft **commit_graft;
@@ -607,7 +607,7 @@ static void record_author_date(struct author_date_slab *author_date,
 	    !ident.date_begin || !ident.date_end)
 		goto fail_exit; /* malformed "author" line */
 
-	date = strtoul(ident.date_begin, &date_end, 10);
+	date = parse_timestamp(ident.date_begin, &date_end, 10);
 	if (date_end != ident.date_end)
 		goto fail_exit; /* malformed date */
 	*(author_date_slab_at(author_date, commit)) = date;
diff --git a/date.c b/date.c
index a996331f5b3..495c207c64f 100644
--- a/date.c
+++ b/date.c
@@ -510,7 +510,7 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt
 	char *end;
 	unsigned long num;
 
-	num = strtoul(date, &end, 10);
+	num = parse_timestamp(date, &end, 10);
 
 	/*
 	 * Seconds since 1970? We trigger on that for any numbers with
@@ -658,7 +658,7 @@ static int match_object_header_date(const char *date, unsigned long *timestamp,
 
 	if (*date < '0' || '9' < *date)
 		return -1;
-	stamp = strtoul(date, &end, 10);
+	stamp = parse_timestamp(date, &end, 10);
 	if (*end != ' ' || stamp == ULONG_MAX || (end[1] != '+' && end[1] != '-'))
 		return -1;
 	date = end + 2;
@@ -1066,7 +1066,7 @@ static const char *approxidate_digit(const char *date, struct tm *tm, int *num,
 				     time_t now)
 {
 	char *end;
-	unsigned long number = strtoul(date, &end, 10);
+	unsigned long number = parse_timestamp(date, &end, 10);
 
 	switch (*end) {
 	case ':':
diff --git a/fsck.c b/fsck.c
index 939792752bf..33a66e68a83 100644
--- a/fsck.c
+++ b/fsck.c
@@ -690,7 +690,7 @@ static int fsck_ident(const char **ident, struct object *obj, struct fsck_option
 	p++;
 	if (*p == '0' && p[1] != ' ')
 		return report(options, obj, FSCK_MSG_ZERO_PADDED_DATE, "invalid author/committer line - zero-padded date");
-	if (date_overflows(strtoul(p, &end, 10)))
+	if (date_overflows(parse_timestamp(p, &end, 10)))
 		return report(options, obj, FSCK_MSG_BAD_DATE_OVERFLOW, "invalid author/committer line - date causes integer overflow");
 	if ((end == p || *end != ' '))
 		return report(options, obj, FSCK_MSG_BAD_DATE, "invalid author/committer line - bad date");
diff --git a/git-compat-util.h b/git-compat-util.h
index 8a4a3f85e7b..fc1b5fe1a6c 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -319,6 +319,8 @@ extern char *gitdirname(char *);
 #define PRIo32 "o"
 #endif
 
+#define parse_timestamp strtoul
+
 #ifndef PATH_SEP
 #define PATH_SEP ':'
 #endif
diff --git a/pretty.c b/pretty.c
index d0f86f5d85c..24fb0c79062 100644
--- a/pretty.c
+++ b/pretty.c
@@ -409,7 +409,7 @@ const char *show_ident_date(const struct ident_split *ident,
 	long tz = 0;
 
 	if (ident->date_begin && ident->date_end)
-		date = strtoul(ident->date_begin, NULL, 10);
+		date = parse_timestamp(ident->date_begin, NULL, 10);
 	if (date_overflows(date))
 		date = 0;
 	else {
diff --git a/ref-filter.c b/ref-filter.c
index 8538328fc7f..d81dd938579 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -868,7 +868,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam
 
 	if (!eoemail)
 		goto bad;
-	timestamp = strtoul(eoemail + 2, &zone, 10);
+	timestamp = parse_timestamp(eoemail + 2, &zone, 10);
 	if (timestamp == ULONG_MAX)
 		goto bad;
 	tz = strtol(zone, NULL, 10);
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 50188e92f9f..fe3e2ac8afe 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -3114,7 +3114,7 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c
 	    parse_oid_hex(p, &noid, &p) || *p++ != ' ' ||
 	    !(email_end = strchr(p, '>')) ||
 	    email_end[1] != ' ' ||
-	    !(timestamp = strtoul(email_end + 2, &message, 10)) ||
+	    !(timestamp = parse_timestamp(email_end + 2, &message, 10)) ||
 	    !message || message[0] != ' ' ||
 	    (message[1] != '+' && message[1] != '-') ||
 	    !isdigit(message[2]) || !isdigit(message[3]) ||
diff --git a/t/helper/test-date.c b/t/helper/test-date.c
index ac7c66c733b..52d1fc34454 100644
--- a/t/helper/test-date.c
+++ b/t/helper/test-date.c
@@ -34,7 +34,7 @@ static void show_dates(const char **argv, const char *format)
 		 * Do not use our normal timestamp parsing here, as the point
 		 * is to test the formatting code in isolation.
 		 */
-		t = strtol(*argv, &arg, 10);
+		t = parse_timestamp(*argv, &arg, 10);
 		while (*arg == ' ')
 			arg++;
 		tz = atoi(arg);
diff --git a/tag.c b/tag.c
index 243d1fdbbcb..9b6725e02c9 100644
--- a/tag.c
+++ b/tag.c
@@ -110,8 +110,8 @@ static unsigned long parse_tag_date(const char *buf, const char *tail)
 		/* nada */;
 	if (buf >= tail)
 		return 0;
-	/* dateptr < buf && buf[-1] == '\n', so strtoul will stop at buf-1 */
-	return strtoul(dateptr, NULL, 10);
+	/* dateptr < buf && buf[-1] == '\n', so parsing will stop at buf-1 */
+	return parse_timestamp(dateptr, NULL, 10);
 }
 
 int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
diff --git a/upload-pack.c b/upload-pack.c
index ffb028d6231..f17f4dd1233 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -775,7 +775,7 @@ static void receive_needs(void)
 		}
 		if (skip_prefix(line, "deepen-since ", &arg)) {
 			char *end = NULL;
-			deepen_since = strtoul(arg, &end, 0);
+			deepen_since = parse_timestamp(arg, &end, 0);
 			if (!end || *end || !deepen_since ||
 			    /* revisions.c's max_age -1 is special */
 			    deepen_since == -1)
-- 
2.12.2.windows.1
Previous: Johannes SchindelinNext: Torsten Bögershausen
Message 37 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.