Skip to content

Commit 0db3dc7

Browse files
rscharfegitster
authored andcommitted
apply: remove epoch date from regex
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e490501 commit 0db3dc7

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

apply.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -812,9 +812,7 @@ static int has_epoch_timestamp(const char *nameline)
812812
* 1970-01-01, and the seconds part must be "00".
813813
*/
814814
const char stamp_regexp[] =
815-
"^(1969-12-31|1970-01-01)"
816-
" "
817-
"[0-2][0-9]:[0-5][0-9]:00(\\.0+)?"
815+
"^[0-2][0-9]:([0-5][0-9]):00(\\.0+)?"
818816
" "
819817
"([-+][0-2][0-9]:?[0-5][0-9])\n";
820818
const char *timestamp = NULL, *cp, *colon;
@@ -834,9 +832,9 @@ static int has_epoch_timestamp(const char *nameline)
834832
* YYYY-MM-DD hh:mm:ss must be from either 1969-12-31
835833
* (west of GMT) or 1970-01-01 (east of GMT)
836834
*/
837-
if (starts_with(timestamp, "1969-12-31"))
835+
if (skip_prefix(timestamp, "1969-12-31 ", &timestamp))
838836
epoch_hour = 24;
839-
else if (starts_with(timestamp, "1970-01-01"))
837+
else if (skip_prefix(timestamp, "1970-01-01 ", &timestamp))
840838
epoch_hour = 0;
841839
else
842840
return 0;
@@ -858,8 +856,8 @@ static int has_epoch_timestamp(const char *nameline)
858856
return 0;
859857
}
860858

861-
hour = strtol(timestamp + 11, NULL, 10);
862-
minute = strtol(timestamp + 14, NULL, 10);
859+
hour = strtol(timestamp, NULL, 10);
860+
minute = strtol(timestamp + m[1].rm_so, NULL, 10);
863861

864862
zoneoffset = strtol(timestamp + m[3].rm_so + 1, (char **) &colon, 10);
865863
if (*colon == ':')

0 commit comments

Comments
 (0)