@matheusbsbs / matheus-bagliano / commits / 08e6710f76
Fork 0

mailinfo: cleanup extra spaces for complex 'From:'

currently for cases like From: A U Thor <a.u.thor@example.com> (Comment) mailinfo extracts the following 'Author:' field: Author: A U Thor (Comment) ^^ which has two extra spaces left in there after removed email part. I think this is wrong so here is a fix. Signed-off-by: Kirill Smelkov <kirr@landau.phys.spbu.ru> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kirill Smelkov committed Feb 1, 2009 at 20:45 UTC 08e6710f76165f79cfa3cde9b10bb051fb0d0dc9
4 files changed +19 -8
builtin-mailinfo.c
+15 -4
@@ -29,6 +29,9 @@ static struct strbuf **p_hdr_data, **s_hdr_data;
29 #define MAX_HDR_PARSED 10
30 #define MAX_BOUNDARIES 5
31
32 +static void cleanup_space(struct strbuf *sb);
33 +
34 +
35 static void get_sane_name(struct strbuf *out, struct strbuf *name, struct strbuf *email)
36 {
37 struct strbuf *src = name;
@@ -109,11 +112,19 @@ static void handle_from(const struct strbuf *from)
112 strbuf_add(&email, at, el);
113 strbuf_remove(&f, at - f.buf, el + (at[el] ? 1 : 0));
114
112 - /* The remainder is name. It could be "John Doe <john.doe@xz>"
113 - * or "john.doe@xz (John Doe)", but we have removed the
114 - * email part, so trim from both ends, possibly removing
115 - * the () pair at the end.
115 + /* The remainder is name. It could be
116 + *
117 + * - "John Doe <john.doe@xz>" (a), or
118 + * - "john.doe@xz (John Doe)" (b), or
119 + * - "John (zzz) Doe <john.doe@xz> (Comment)" (c)
120 + *
121 + * but we have removed the email part, so
122 + *
123 + * - remove extra spaces which could stay after email (case 'c'), and
124 + * - trim from both ends, possibly removing the () pair at the end
125 + * (cases 'a' and 'b').
126 */
127 + cleanup_space(&f);
128 strbuf_trim(&f);
129 if (f.buf[0] == '(' && f.len && f.buf[f.len - 1] == ')') {
130 strbuf_remove(&f, 0, 1);
t/t5100/info0001
+1 -1
@@ -1,4 +1,4 @@
1 -Author: A U Thor
1 +Author: A (zzz) U Thor (Comment)
2 Email: a.u.thor@example.com
3 Subject: a commit.
4 Date: Fri, 9 Jun 2006 00:44:16 -0700
t/t5100/rfc2047-info-0004
+1 -1
@@ -1,4 +1,4 @@
1 -Author: Nathaniel Borenstein (םולש ןב ילטפנ)
1 +Author: Nathaniel Borenstein (םולש ןב ילטפנ)
2 Email: nsb@thumper.bellcore.com
3 Subject: Test of new header generator
4
t/t5100/sample.mbox
+2 -2
@@ -2,10 +2,10 @@
2
3
4 From nobody Mon Sep 17 00:00:00 2001
5 -From: A
5 +From: A (zzz)
6 U
7 Thor
8 - <a.u.thor@example.com>
8 + <a.u.thor@example.com> (Comment)
9 Date: Fri, 9 Jun 2006 00:44:16 -0700
10 Subject: [PATCH] a commit.
11