diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-11-29 17:52:31 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-11-29 17:52:31 -0800 |
commit | f565f6e06511249c8c3690277023a8550dbdfb47 (patch) | |
tree | b2e897cd8dc1539ad3f27d78282f55ff4efd2418 /builtin | |
parent | feedaf43dbf31b18d96c4116e3b3f0c522b2cd7b (diff) | |
parent | 2d502e1f378a39ef375d6d5c1b3312d286ed2524 (diff) | |
download | git-f565f6e06511249c8c3690277023a8550dbdfb47.tar.gz git-f565f6e06511249c8c3690277023a8550dbdfb47.tar.xz |
Merge branch 'ak/apply-non-git-epoch'
* ak/apply-non-git-epoch:
apply: handle patches with funny filename and colon in timezone
apply: Recognize epoch timestamps with : in the timezone
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/apply.c | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/builtin/apply.c b/builtin/apply.c index 96246e960..3e43425f6 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -449,7 +449,7 @@ static char *find_name_gnu(const char *line, char *def, int p_value) return squash_slash(strbuf_detach(&name, NULL)); } -static size_t tz_len(const char *line, size_t len) +static size_t sane_tz_len(const char *line, size_t len) { const char *tz, *p; @@ -467,6 +467,24 @@ static size_t tz_len(const char *line, size_t len) return line + len - tz; } +static size_t tz_with_colon_len(const char *line, size_t len) +{ + const char *tz, *p; + + if (len < strlen(" +08:00") || line[len - strlen(":00")] != ':') + return 0; + tz = line + len - strlen(" +08:00"); + + if (tz[0] != ' ' || (tz[1] != '+' && tz[1] != '-')) + return 0; + p = tz + 2; + if (!isdigit(*p++) || !isdigit(*p++) || *p++ != ':' || + !isdigit(*p++) || !isdigit(*p++)) + return 0; + + return line + len - tz; +} + static size_t date_len(const char *line, size_t len) { const char *date, *p; @@ -561,7 +579,9 @@ static size_t diff_timestamp_len(const char *line, size_t len) if (!isdigit(end[-1])) return 0; - n = tz_len(line, end - line); + n = sane_tz_len(line, end - line); + if (!n) + n = tz_with_colon_len(line, end - line); end -= n; n = short_time_len(line, end - line); @@ -733,8 +753,8 @@ static int has_epoch_timestamp(const char *nameline) " " "[0-2][0-9]:[0-5][0-9]:00(\\.0+)?" " " - "([-+][0-2][0-9][0-5][0-9])\n"; - const char *timestamp = NULL, *cp; + "([-+][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; @@ -764,8 +784,11 @@ static int has_epoch_timestamp(const char *nameline) return 0; } - zoneoffset = strtol(timestamp + m[3].rm_so + 1, NULL, 10); - zoneoffset = (zoneoffset / 100) * 60 + (zoneoffset % 100); + zoneoffset = strtol(timestamp + m[3].rm_so + 1, (char **) &colon, 10); + if (*colon == ':') + zoneoffset = zoneoffset * 60 + strtol(colon + 1, NULL, 10); + else + zoneoffset = (zoneoffset / 100) * 60 + (zoneoffset % 100); if (timestamp[m[3].rm_so] == '-') zoneoffset = -zoneoffset; |