git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Git List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 2/2] apply: remove epoch date from regex
Date: Fri, 25 Aug 2017 21:06:28 +0200	[thread overview]
Message-ID: <5dd40b51-ac5b-6885-b7b0-f2a33045c386@web.de> (raw)
In-Reply-To: <205339f5-bad8-62a3-8ccc-d3b0dd1d6736@web.de>

We check the date of epoch timestamp candidates already with
starts_with().  Move beyond that part using skip_prefix() instead of
checking it again using a regular expression.  Also group the minutes
part, so that we can access them using a substring match instead of
using a magic number.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 apply.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/apply.c b/apply.c
index e14077eaee..9c70b4040a 100644
--- a/apply.c
+++ b/apply.c
@@ -811,9 +811,7 @@ 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;
@@ -833,9 +831,9 @@ static int has_epoch_timestamp(const char *nameline)
 	 * 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"))
+	if (skip_prefix(timestamp, "1969-12-31 ", &timestamp))
 		epoch_hour = 24;
-	else if (starts_with(timestamp, "1970-01-01"))
+	else if (skip_prefix(timestamp, "1970-01-01 ", &timestamp))
 		epoch_hour = 0;
 	else
 		return 0;
@@ -857,8 +855,8 @@ static int has_epoch_timestamp(const char *nameline)
 		return 0;
 	}
 
-	hour = strtol(timestamp + 11, NULL, 10);
-	minute = strtol(timestamp + 14, NULL, 10);
+	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 == ':')
-- 
2.14.1


      reply	other threads:[~2017-08-25 19:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-25 19:04 [PATCH 1/2] apply: check date of potential epoch timestamps first René Scharfe
2017-08-25 19:06 ` René Scharfe [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5dd40b51-ac5b-6885-b7b0-f2a33045c386@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).