diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-09-10 17:08:25 +0900 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-09-10 17:08:25 +0900 |
commit | ef1d87c64b4f9a41fa03b039761f599750227d5a (patch) | |
tree | a25e0da9e7cd9cde12d7d8801f10adff4ff0991c /apply.c | |
parent | Merge branch 'jk/drop-sha1-entry-pos' (diff) | |
parent | apply: remove epoch date from regex (diff) | |
download | tgif-ef1d87c64b4f9a41fa03b039761f599750227d5a.tar.xz |
Merge branch 'rs/apply-epoch'
Code simplification.
* rs/apply-epoch:
apply: remove epoch date from regex
apply: check date of potential epoch timestamps first
Diffstat (limited to 'apply.c')
-rw-r--r-- | apply.c | 37 |
1 files changed, 18 insertions, 19 deletions
@@ -812,16 +812,13 @@ static int has_epoch_timestamp(const char *nameline) * 1970-01-01, and the seconds part must be "00". */ const char stamp_regexp[] = - "^(1969-12-31|1970-01-01)" - " " - "[0-2][0-9]:[0-5][0-9]:00(\\.0+)?" + "^[0-2][0-9]:([0-5][0-9]):00(\\.0+)?" " " "([-+][0-2][0-9]:?[0-5][0-9])\n"; const char *timestamp = NULL, *cp, *colon; static regex_t *stamp; regmatch_t m[10]; - int zoneoffset; - int hourminute; + int zoneoffset, epoch_hour, hour, minute; int status; for (cp = nameline; *cp != '\n'; cp++) { @@ -830,6 +827,18 @@ static int has_epoch_timestamp(const char *nameline) } if (!timestamp) return 0; + + /* + * YYYY-MM-DD hh:mm:ss must be from either 1969-12-31 + * (west of GMT) or 1970-01-01 (east of GMT) + */ + if (skip_prefix(timestamp, "1969-12-31 ", ×tamp)) + epoch_hour = 24; + else if (skip_prefix(timestamp, "1970-01-01 ", ×tamp)) + epoch_hour = 0; + else + return 0; + if (!stamp) { stamp = xmalloc(sizeof(*stamp)); if (regcomp(stamp, stamp_regexp, REG_EXTENDED)) { @@ -847,6 +856,9 @@ static int has_epoch_timestamp(const char *nameline) return 0; } + hour = strtol(timestamp, NULL, 10); + minute = strtol(timestamp + m[1].rm_so, NULL, 10); + zoneoffset = strtol(timestamp + m[3].rm_so + 1, (char **) &colon, 10); if (*colon == ':') zoneoffset = zoneoffset * 60 + strtol(colon + 1, NULL, 10); @@ -855,20 +867,7 @@ static int has_epoch_timestamp(const char *nameline) if (timestamp[m[3].rm_so] == '-') zoneoffset = -zoneoffset; - /* - * YYYY-MM-DD hh:mm:ss must be from either 1969-12-31 - * (west of GMT) or 1970-01-01 (east of GMT) - */ - if ((zoneoffset < 0 && memcmp(timestamp, "1969-12-31", 10)) || - (0 <= zoneoffset && memcmp(timestamp, "1970-01-01", 10))) - return 0; - - hourminute = (strtol(timestamp + 11, NULL, 10) * 60 + - strtol(timestamp + 14, NULL, 10) - - zoneoffset); - - return ((zoneoffset < 0 && hourminute == 1440) || - (0 <= zoneoffset && !hourminute)); + return hour * 60 + minute - zoneoffset == epoch_hour * 60; } /* |