Merge branch 'jc/maint-mailinfo-mime-attr'
authorJunio C Hamano <gitster@pobox.com>
Tue, 25 Sep 2012 17:39:56 +0000 (10:39 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 25 Sep 2012 17:39:56 +0000 (10:39 -0700)
When "git am" is fed an input that has multiple "Content-type: ..."
header, it did not grok charset= attribute correctly.

* jc/maint-mailinfo-mime-attr:
mailinfo: do not concatenate charset= attribute values from mime headers

1  2 
builtin/mailinfo.c
t/t5100/sample.mbox
diff --combined builtin/mailinfo.c
index b691b771587ac676b23c40f8d9090a3750eaa43f,dd8b67cfaafb15272d424fb01ead8b51276ec957..2b3f4d955eaad6f7a020291b628588188974e388
@@@ -160,10 -160,9 +160,9 @@@ static int slurp_attr(const char *line
        const char *ends, *ap = strcasestr(line, name);
        size_t sz;
  
-       if (!ap) {
-               strbuf_setlen(attr, 0);
+       strbuf_setlen(attr, 0);
+       if (!ap)
                return 0;
-       }
        ap += strlen(name);
        if (*ap == '"') {
                ap++;
@@@ -232,9 -231,7 +231,9 @@@ static void cleanup_subject(struct strb
                case 'r': case 'R':
                        if (subject->len <= at + 3)
                                break;
 -                      if (!memcmp(subject->buf + at + 1, "e:", 2)) {
 +                      if ((subject->buf[at + 1] == 'e' ||
 +                           subject->buf[at + 1] == 'E') &&
 +                          subject->buf[at + 2] == ':') {
                                strbuf_remove(subject, at, 3);
                                continue;
                        }
@@@ -483,12 -480,36 +482,12 @@@ static struct strbuf *decode_b_segment(
        return out;
  }
  
 -/*
 - * When there is no known charset, guess.
 - *
 - * Right now we assume that if the target is UTF-8 (the default),
 - * and it already looks like UTF-8 (which includes US-ASCII as its
 - * subset, of course) then that is what it is and there is nothing
 - * to do.
 - *
 - * Otherwise, we default to assuming it is Latin1 for historical
 - * reasons.
 - */
 -static const char *guess_charset(const struct strbuf *line, const char *target_charset)
 -{
 -      if (is_encoding_utf8(target_charset)) {
 -              if (is_utf8(line->buf))
 -                      return NULL;
 -      }
 -      return "ISO8859-1";
 -}
 -
  static void convert_to_utf8(struct strbuf *line, const char *charset)
  {
        char *out;
  
 -      if (!charset || !*charset) {
 -              charset = guess_charset(line, metainfo_charset);
 -              if (!charset)
 -                      return;
 -      }
 -
 +      if (!charset || !*charset)
 +              return;
        if (!strcasecmp(metainfo_charset, charset))
                return;
        out = reencode_string(line->buf, metainfo_charset, charset);
diff --combined t/t5100/sample.mbox
index 34a09a0fc1c0ca9d1e68ed8bbf56e592c54e7227,fcc0e0d202fd6db7499763d8fec7564b137ea2f0..8b2ae064c36b969ca20324154cea66bf26739de6
@@@ -12,7 -12,7 +12,7 @@@ Subject: [PATCH] a commit
  Here is a patch from A U Thor.
  
  ---
 - foo |    2 +-
 + foo | 2 +-
   1 files changed, 1 insertions(+), 1 deletions(-)
  
  diff --git a/foo b/foo
@@@ -52,7 -52,7 +52,7 @@@ two truly blank and another full of spa
  Hope this helps.
  
  ---
 - foo |    2 +-
 + foo | 2 +-
   1 files changed, 1 insertions(+), 1 deletions(-)
  
  diff --git a/foo b/foo
@@@ -83,7 -83,7 +83,7 @@@ Message-Id: <nitpicker.12121212@example
  Hopefully this would fix the problem stated there.
  
  ---
 - foo |    2 +-
 + foo | 2 +-
   1 files changed, 1 insertions(+), 1 deletions(-)
  
  diff --git a/foo b/foo
@@@ -249,8 -249,8 +249,8 @@@ actual flags
  Signed-off-by: David K=E5gedal <davidk@lysator.liu.se>
  ---
  
 - Documentation/git-cvsimport-script.txt |    9 ++++++++-
 - git-cvsimport-script                   |    4 ++--
 + Documentation/git-cvsimport-script.txt | 9 ++++++++-
 + git-cvsimport-script                   | 4 ++--
   2 files changed, 10 insertions(+), 3 deletions(-)
  
  50452f9c0c2df1f04d83a26266ba704b13861632
@@@ -379,7 -379,7 +379,7 @@@ Subject: [PATCH] a commit
  Here is a patch from A U Thor.
  
  ---
 - foo |    2 +-
 + foo | 2 +-
   1 files changed, 1 insertions(+), 1 deletions(-)
  
  diff --git a/foo b/foo
@@@ -449,7 -449,7 +449,7 @@@ memcmp("Subject: ", header[i], 7) will 
  Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se>
  Signed-off-by: Junio C Hamano <gitster@pobox.com>
  ---
 - builtin-mailinfo.c |    2 +-
 + builtin-mailinfo.c | 2 +-
   1 files changed, 1 insertions(+), 1 deletions(-)
  
  diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
@@@ -482,7 -482,7 +482,7 @@@ Content-Transfer-Encoding: quoted-print
  Here comes a commit log message, and
  its second line is here.
  ---
 - builtin-mailinfo.c  |    4 ++--
 + builtin-mailinfo.c  | 4 ++--
  
  diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
  index 3e5fe51..aabfe5c 100644
@@@ -587,7 -587,7 +587,7 @@@ everything before it in the message bod
  
  Signed-off-by: Junio C Hamano <gitster@pobox.com>
  ---
 - builtin-mailinfo.c |   37 ++++++++++++++++++++++++++++++++++++-
 + builtin-mailinfo.c | 37 ++++++++++++++++++++++++++++++++++++-
   1 files changed, 36 insertions(+), 1 deletions(-)
  
  diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
@@@ -683,3 -683,19 +683,19 @@@ index e69de29..d95f3ad 10064
  @@ -0,0 +1 @@
  +content
  
+ From nobody Mon Sep 17 00:00:00 2001
+ From: A U Thor <a.u.thor@example.com>
+ Subject: A E I O U
+ Date: Mon, 17 Sep 2012 14:23:44 -0700
+ MIME-Version: 1.0
+ Content-Type: text/plain; charset="iso-2022-jp"
+ Content-type: text/plain; charset="UTF-8"
+ New content here
+ diff --git a/foo b/foo
+ index e69de29..d95f3ad 100644
+ --- a/foo
+ +++ b/foo
+ @@ -0,0 +1 @@
+ +New content