зеркало из https://github.com/microsoft/git.git
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>
This commit is contained in:
Родитель
efac8ac84b
Коммит
1aeb7e756c
|
@ -882,7 +882,7 @@ static int hg_patch_to_mail(FILE *out, FILE *in, int keep_cr)
|
||||||
char *end;
|
char *end;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
timestamp = strtoul(str, &end, 10);
|
timestamp = parse_timestamp(str, &end, 10);
|
||||||
if (errno)
|
if (errno)
|
||||||
return error(_("invalid timestamp"));
|
return error(_("invalid timestamp"));
|
||||||
|
|
||||||
|
|
|
@ -534,7 +534,7 @@ static const char *check_nonce(const char *buf, size_t len)
|
||||||
retval = NONCE_BAD;
|
retval = NONCE_BAD;
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
stamp = strtoul(nonce, &bohmac, 10);
|
stamp = parse_timestamp(nonce, &bohmac, 10);
|
||||||
if (bohmac == nonce || bohmac[0] != '-') {
|
if (bohmac == nonce || bohmac[0] != '-') {
|
||||||
retval = NONCE_BAD;
|
retval = NONCE_BAD;
|
||||||
goto leave;
|
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
|
* would mean it was issued by another server with its clock
|
||||||
* skewed in the future.
|
* 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;
|
nonce_stamp_slop = (long)ostamp - (long)stamp;
|
||||||
|
|
||||||
if (nonce_stamp_slop_limit &&
|
if (nonce_stamp_slop_limit &&
|
||||||
|
|
2
bundle.c
2
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);
|
line = memchr(line, '>', lineend ? lineend - line : buf + size - line);
|
||||||
if (!line++)
|
if (!line++)
|
||||||
goto out;
|
goto out;
|
||||||
date = strtoul(line, NULL, 10);
|
date = parse_timestamp(line, NULL, 10);
|
||||||
result = (revs->max_age == -1 || revs->max_age < date) &&
|
result = (revs->max_age == -1 || revs->max_age < date) &&
|
||||||
(revs->min_age == -1 || revs->min_age > date);
|
(revs->min_age == -1 || revs->min_age > date);
|
||||||
out:
|
out:
|
||||||
|
|
6
commit.c
6
commit.c
|
@ -89,8 +89,8 @@ static unsigned long parse_commit_date(const char *buf, const char *tail)
|
||||||
/* nada */;
|
/* nada */;
|
||||||
if (buf >= tail)
|
if (buf >= tail)
|
||||||
return 0;
|
return 0;
|
||||||
/* dateptr < buf && buf[-1] == '\n', so strtoul will stop at buf-1 */
|
/* dateptr < buf && buf[-1] == '\n', so parsing will stop at buf-1 */
|
||||||
return strtoul(dateptr, NULL, 10);
|
return parse_timestamp(dateptr, NULL, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct commit_graft **commit_graft;
|
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)
|
!ident.date_begin || !ident.date_end)
|
||||||
goto fail_exit; /* malformed "author" line */
|
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)
|
if (date_end != ident.date_end)
|
||||||
goto fail_exit; /* malformed date */
|
goto fail_exit; /* malformed date */
|
||||||
*(author_date_slab_at(author_date, commit)) = date;
|
*(author_date_slab_at(author_date, commit)) = date;
|
||||||
|
|
6
date.c
6
date.c
|
@ -510,7 +510,7 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt
|
||||||
char *end;
|
char *end;
|
||||||
unsigned long num;
|
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
|
* 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)
|
if (*date < '0' || '9' < *date)
|
||||||
return -1;
|
return -1;
|
||||||
stamp = strtoul(date, &end, 10);
|
stamp = parse_timestamp(date, &end, 10);
|
||||||
if (*end != ' ' || stamp == ULONG_MAX || (end[1] != '+' && end[1] != '-'))
|
if (*end != ' ' || stamp == ULONG_MAX || (end[1] != '+' && end[1] != '-'))
|
||||||
return -1;
|
return -1;
|
||||||
date = end + 2;
|
date = end + 2;
|
||||||
|
@ -1066,7 +1066,7 @@ static const char *approxidate_digit(const char *date, struct tm *tm, int *num,
|
||||||
time_t now)
|
time_t now)
|
||||||
{
|
{
|
||||||
char *end;
|
char *end;
|
||||||
unsigned long number = strtoul(date, &end, 10);
|
unsigned long number = parse_timestamp(date, &end, 10);
|
||||||
|
|
||||||
switch (*end) {
|
switch (*end) {
|
||||||
case ':':
|
case ':':
|
||||||
|
|
2
fsck.c
2
fsck.c
|
@ -691,7 +691,7 @@ static int fsck_ident(const char **ident, struct object *obj, struct fsck_option
|
||||||
p++;
|
p++;
|
||||||
if (*p == '0' && p[1] != ' ')
|
if (*p == '0' && p[1] != ' ')
|
||||||
return report(options, obj, FSCK_MSG_ZERO_PADDED_DATE, "invalid author/committer line - zero-padded date");
|
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");
|
return report(options, obj, FSCK_MSG_BAD_DATE_OVERFLOW, "invalid author/committer line - date causes integer overflow");
|
||||||
if ((end == p || *end != ' '))
|
if ((end == p || *end != ' '))
|
||||||
return report(options, obj, FSCK_MSG_BAD_DATE, "invalid author/committer line - bad date");
|
return report(options, obj, FSCK_MSG_BAD_DATE, "invalid author/committer line - bad date");
|
||||||
|
|
|
@ -319,6 +319,8 @@ extern char *gitdirname(char *);
|
||||||
#define PRIo32 "o"
|
#define PRIo32 "o"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define parse_timestamp strtoul
|
||||||
|
|
||||||
#ifndef PATH_SEP
|
#ifndef PATH_SEP
|
||||||
#define PATH_SEP ':'
|
#define PATH_SEP ':'
|
||||||
#endif
|
#endif
|
||||||
|
|
2
pretty.c
2
pretty.c
|
@ -409,7 +409,7 @@ const char *show_ident_date(const struct ident_split *ident,
|
||||||
long tz = 0;
|
long tz = 0;
|
||||||
|
|
||||||
if (ident->date_begin && ident->date_end)
|
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))
|
if (date_overflows(date))
|
||||||
date = 0;
|
date = 0;
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -868,7 +868,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam
|
||||||
|
|
||||||
if (!eoemail)
|
if (!eoemail)
|
||||||
goto bad;
|
goto bad;
|
||||||
timestamp = strtoul(eoemail + 2, &zone, 10);
|
timestamp = parse_timestamp(eoemail + 2, &zone, 10);
|
||||||
if (timestamp == ULONG_MAX)
|
if (timestamp == ULONG_MAX)
|
||||||
goto bad;
|
goto bad;
|
||||||
tz = strtol(zone, NULL, 10);
|
tz = strtol(zone, NULL, 10);
|
||||||
|
|
|
@ -3247,7 +3247,7 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c
|
||||||
parse_oid_hex(p, &noid, &p) || *p++ != ' ' ||
|
parse_oid_hex(p, &noid, &p) || *p++ != ' ' ||
|
||||||
!(email_end = strchr(p, '>')) ||
|
!(email_end = strchr(p, '>')) ||
|
||||||
email_end[1] != ' ' ||
|
email_end[1] != ' ' ||
|
||||||
!(timestamp = strtoul(email_end + 2, &message, 10)) ||
|
!(timestamp = parse_timestamp(email_end + 2, &message, 10)) ||
|
||||||
!message || message[0] != ' ' ||
|
!message || message[0] != ' ' ||
|
||||||
(message[1] != '+' && message[1] != '-') ||
|
(message[1] != '+' && message[1] != '-') ||
|
||||||
!isdigit(message[2]) || !isdigit(message[3]) ||
|
!isdigit(message[2]) || !isdigit(message[3]) ||
|
||||||
|
|
|
@ -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
|
* Do not use our normal timestamp parsing here, as the point
|
||||||
* is to test the formatting code in isolation.
|
* is to test the formatting code in isolation.
|
||||||
*/
|
*/
|
||||||
t = strtol(*argv, &arg, 10);
|
t = parse_timestamp(*argv, &arg, 10);
|
||||||
while (*arg == ' ')
|
while (*arg == ' ')
|
||||||
arg++;
|
arg++;
|
||||||
tz = atoi(arg);
|
tz = atoi(arg);
|
||||||
|
|
4
tag.c
4
tag.c
|
@ -110,8 +110,8 @@ static unsigned long parse_tag_date(const char *buf, const char *tail)
|
||||||
/* nada */;
|
/* nada */;
|
||||||
if (buf >= tail)
|
if (buf >= tail)
|
||||||
return 0;
|
return 0;
|
||||||
/* dateptr < buf && buf[-1] == '\n', so strtoul will stop at buf-1 */
|
/* dateptr < buf && buf[-1] == '\n', so parsing will stop at buf-1 */
|
||||||
return strtoul(dateptr, NULL, 10);
|
return parse_timestamp(dateptr, NULL, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
|
int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
|
||||||
|
|
|
@ -775,7 +775,7 @@ static void receive_needs(void)
|
||||||
}
|
}
|
||||||
if (skip_prefix(line, "deepen-since ", &arg)) {
|
if (skip_prefix(line, "deepen-since ", &arg)) {
|
||||||
char *end = NULL;
|
char *end = NULL;
|
||||||
deepen_since = strtoul(arg, &end, 0);
|
deepen_since = parse_timestamp(arg, &end, 0);
|
||||||
if (!end || *end || !deepen_since ||
|
if (!end || *end || !deepen_since ||
|
||||||
/* revisions.c's max_age -1 is special */
|
/* revisions.c's max_age -1 is special */
|
||||||
deepen_since == -1)
|
deepen_since == -1)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче