Merge branch 'ak/apply-non-git-epoch' into maint
authorJunio C Hamano <gitster@pobox.com>
Thu, 9 Dec 2010 18:36:16 +0000 (10:36 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 9 Dec 2010 18:36:16 +0000 (10:36 -0800)
* ak/apply-non-git-epoch:
apply: handle patches with funny filename and colon in timezone
apply: Recognize epoch timestamps with : in the timezone

1  2 
builtin/apply.c
diff --combined builtin/apply.c
index f051e66dcc5260e4e7ecb28c36e2c6da8e823d6b,40f564c400ee133aceb1c9c191f4a90273a52050..4e800b5c8d80abfacef573aeb585aeb62d0866ef
@@@ -449,7 -449,7 +449,7 @@@ static char *find_name_gnu(const char *
        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;
  
        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 +579,9 @@@ static size_t diff_timestamp_len(const 
        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 +753,8 @@@ static int has_epoch_timestamp(const ch
                " "
                "[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;
                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;
  
@@@ -2645,12 -2668,6 +2668,12 @@@ static int apply_binary_fragment(struc
        unsigned long len;
        void *dst;
  
 +      if (!fragment)
 +              return error("missing binary patch data for '%s'",
 +                           patch->new_name ?
 +                           patch->new_name :
 +                           patch->old_name);
 +
        /* Binary patch is irreversible without the optional second hunk */
        if (apply_in_reverse) {
                if (!fragment->next)