parse_timestamp(): specify explicitly where we parse timestamps

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Apr 21, 2017 at 12:45 UTC 1aeb7e756c82d31e46712ec7557c4cbae37dccd9
13 files changed +20 -18
builtin/am.c
+1 -1
@@ -882,7 +882,7 @@ static int hg_patch_to_mail(FILE *out, FILE *in, int keep_cr)
882 char *end;
883
884 errno = 0;
885 - timestamp = strtoul(str, &end, 10);
885 + timestamp = parse_timestamp(str, &end, 10);
886 if (errno)
887 return error(_("invalid timestamp"));
888
builtin/receive-pack.c
+2 -2
@@ -534,7 +534,7 @@ static const char *check_nonce(const char *buf, size_t len)
534 retval = NONCE_BAD;
535 goto leave;
536 }
537 - stamp = strtoul(nonce, &bohmac, 10);
537 + stamp = parse_timestamp(nonce, &bohmac, 10);
538 if (bohmac == nonce || bohmac[0] != '-') {
539 retval = NONCE_BAD;
540 goto leave;
@@ -552,7 +552,7 @@ static const char *check_nonce(const char *buf, size_t len)
552 * would mean it was issued by another server with its clock
553 * skewed in the future.
554 */
555 - ostamp = strtoul(push_cert_nonce, NULL, 10);
555 + ostamp = parse_timestamp(push_cert_nonce, NULL, 10);
556 nonce_stamp_slop = (long)ostamp - (long)stamp;
557
558 if (nonce_stamp_slop_limit &&
bundle.c
+1 -1
@@ -227,7 +227,7 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
227 line = memchr(line, '>', lineend ? lineend - line : buf + size - line);
228 if (!line++)
229 goto out;
230 - date = strtoul(line, NULL, 10);
230 + date = parse_timestamp(line, NULL, 10);
231 result = (revs->max_age == -1 || revs->max_age < date) &&
232 (revs->min_age == -1 || revs->min_age > date);
233 out:
commit.c
+3 -3
@@ -89,8 +89,8 @@ static unsigned long parse_commit_date(const char *buf, const char *tail)
89 /* nada */;
90 if (buf >= tail)
91 return 0;
92 - /* dateptr < buf && buf[-1] == '\n', so strtoul will stop at buf-1 */
93 - return strtoul(dateptr, NULL, 10);
92 + /* dateptr < buf && buf[-1] == '\n', so parsing will stop at buf-1 */
93 + return parse_timestamp(dateptr, NULL, 10);
94 }
95
96 static struct commit_graft **commit_graft;
@@ -607,7 +607,7 @@ static void record_author_date(struct author_date_slab *author_date,
607 !ident.date_begin || !ident.date_end)
608 goto fail_exit; /* malformed "author" line */
609
610 - date = strtoul(ident.date_begin, &date_end, 10);
610 + date = parse_timestamp(ident.date_begin, &date_end, 10);
611 if (date_end != ident.date_end)
612 goto fail_exit; /* malformed date */
613 *(author_date_slab_at(author_date, commit)) = date;
date.c
+3 -3
@@ -510,7 +510,7 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt
510 char *end;
511 unsigned long num;
512
513 - num = strtoul(date, &end, 10);
513 + num = parse_timestamp(date, &end, 10);
514
515 /*
516 * 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,
658
659 if (*date < '0' || '9' < *date)
660 return -1;
661 - stamp = strtoul(date, &end, 10);
661 + stamp = parse_timestamp(date, &end, 10);
662 if (*end != ' ' || stamp == ULONG_MAX || (end[1] != '+' && end[1] != '-'))
663 return -1;
664 date = end + 2;
@@ -1066,7 +1066,7 @@ static const char *approxidate_digit(const char *date, struct tm *tm, int *num,
1066 time_t now)
1067 {
1068 char *end;
1069 - unsigned long number = strtoul(date, &end, 10);
1069 + unsigned long number = parse_timestamp(date, &end, 10);
1070
1071 switch (*end) {
1072 case ':':
fsck.c
+1 -1
@@ -691,7 +691,7 @@ static int fsck_ident(const char **ident, struct object *obj, struct fsck_option
691 p++;
692 if (*p == '0' && p[1] != ' ')
693 return report(options, obj, FSCK_MSG_ZERO_PADDED_DATE, "invalid author/committer line - zero-padded date");
694 - if (date_overflows(strtoul(p, &end, 10)))
694 + if (date_overflows(parse_timestamp(p, &end, 10)))
695 return report(options, obj, FSCK_MSG_BAD_DATE_OVERFLOW, "invalid author/committer line - date causes integer overflow");
696 if ((end == p || *end != ' '))
697 return report(options, obj, FSCK_MSG_BAD_DATE, "invalid author/committer line - bad date");
git-compat-util.h
+2
@@ -319,6 +319,8 @@ extern char *gitdirname(char *);
319 #define PRIo32 "o"
320 #endif
321
322 +#define parse_timestamp strtoul
323 +
324 #ifndef PATH_SEP
325 #define PATH_SEP ':'
326 #endif
pretty.c
+1 -1
@@ -409,7 +409,7 @@ const char *show_ident_date(const struct ident_split *ident,
409 long tz = 0;
410
411 if (ident->date_begin && ident->date_end)
412 - date = strtoul(ident->date_begin, NULL, 10);
412 + date = parse_timestamp(ident->date_begin, NULL, 10);
413 if (date_overflows(date))
414 date = 0;
415 else {
ref-filter.c
+1 -1
@@ -868,7 +868,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam
868
869 if (!eoemail)
870 goto bad;
871 - timestamp = strtoul(eoemail + 2, &zone, 10);
871 + timestamp = parse_timestamp(eoemail + 2, &zone, 10);
872 if (timestamp == ULONG_MAX)
873 goto bad;
874 tz = strtol(zone, NULL, 10);
refs/files-backend.c
+1 -1
@@ -3247,7 +3247,7 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c
3247 parse_oid_hex(p, &noid, &p) || *p++ != ' ' ||
3248 !(email_end = strchr(p, '>')) ||
3249 email_end[1] != ' ' ||
3250 - !(timestamp = strtoul(email_end + 2, &message, 10)) ||
3250 + !(timestamp = parse_timestamp(email_end + 2, &message, 10)) ||
3251 !message || message[0] != ' ' ||
3252 (message[1] != '+' && message[1] != '-') ||
3253 !isdigit(message[2]) || !isdigit(message[3]) ||
t/helper/test-date.c
+1 -1
@@ -34,7 +34,7 @@ static void show_dates(const char **argv, const char *format)
34 * Do not use our normal timestamp parsing here, as the point
35 * is to test the formatting code in isolation.
36 */
37 - t = strtol(*argv, &arg, 10);
37 + t = parse_timestamp(*argv, &arg, 10);
38 while (*arg == ' ')
39 arg++;
40 tz = atoi(arg);
tag.c
+2 -2
@@ -110,8 +110,8 @@ static unsigned long parse_tag_date(const char *buf, const char *tail)
110 /* nada */;
111 if (buf >= tail)
112 return 0;
113 - /* dateptr < buf && buf[-1] == '\n', so strtoul will stop at buf-1 */
114 - return strtoul(dateptr, NULL, 10);
113 + /* dateptr < buf && buf[-1] == '\n', so parsing will stop at buf-1 */
114 + return parse_timestamp(dateptr, NULL, 10);
115 }
116
117 int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
upload-pack.c
+1 -1
@@ -775,7 +775,7 @@ static void receive_needs(void)
775 }
776 if (skip_prefix(line, "deepen-since ", &arg)) {
777 char *end = NULL;
778 - deepen_since = strtoul(arg, &end, 0);
778 + deepen_since = parse_timestamp(arg, &end, 0);
779 if (!end || *end || !deepen_since ||
780 /* revisions.c's max_age -1 is special */
781 deepen_since == -1)