summaryrefslogtreecommitdiff
path: root/apply.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2017-08-25 21:04:54 +0200
committerJunio C Hamano <gitster@pobox.com>2017-08-25 14:06:08 -0700
commite4905019df568762d5f9ab66227eefcb32915b40 (patch)
tree8e3f7cf1909184c69bd3011ac8aef175756837e4 /apply.c
parentedc74bc7f0c6884027e851ef09b2e0c9380dcd45 (diff)
downloadgit-e4905019df568762d5f9ab66227eefcb32915b40.tar.gz
apply: check date of potential epoch timestamps first
has_epoch_timestamp() looks for time stamps that amount to either 1969-12-31 24:00 or 1970-01-01 00:00 after applying the time zone offset. Move the check for these two dates up, set the expected hour based on which one is found, or exit early if none of them are present, thus avoiding to engage the regex machinery for newer dates. This also gets rid of two magic string length constants. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'apply.c')
-rw-r--r--apply.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/apply.c b/apply.c
index 40707ca50c..e5d7959b29 100644
--- a/apply.c
+++ b/apply.c
@@ -820,8 +820,7 @@ static int has_epoch_timestamp(const char *nameline)
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 +829,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 (starts_with(timestamp, "1969-12-31"))
+ epoch_hour = 24;
+ else if (starts_with(timestamp, "1970-01-01"))
+ epoch_hour = 0;
+ else
+ return 0;
+
if (!stamp) {
stamp = xmalloc(sizeof(*stamp));
if (regcomp(stamp, stamp_regexp, REG_EXTENDED)) {
@@ -847,6 +858,9 @@ static int has_epoch_timestamp(const char *nameline)
return 0;
}
+ hour = strtol(timestamp + 11, NULL, 10);
+ minute = strtol(timestamp + 14, 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 +869,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;
}
/*