@matheusbsbs / matheus-bagliano / commits / e0e3ba208d
Fork 0

mailinfo and git-am: allow "John Doe <johndoe>"

An isolated developer could have a local-only e-mail, which will be stripped out by mailinfo because it lacks '@'. Define a fallback parser to accomodate that. At the same time, reject authorless patch in git-am. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Dec 14, 2005 at 16:31 UTC e0e3ba208d235ab5623a86204fbd20b449520764
2 files changed +38 -1
git-am.sh
+7
@@ -249,6 +249,13 @@ do
249 GIT_AUTHOR_NAME="$(sed -n '/^Author/ s/Author: //p' "$dotest/info")"
250 GIT_AUTHOR_EMAIL="$(sed -n '/^Email/ s/Email: //p' "$dotest/info")"
251 GIT_AUTHOR_DATE="$(sed -n '/^Date/ s/Date: //p' "$dotest/info")"
252 +
253 + if test -z "$GIT_AUTHOR_EMAIL"
254 + then
255 + echo "Patch does not have a valid e-mail address."
256 + stop_here $this
257 + fi
258 +
259 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
260
261 SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' "$dotest/info")"
mailinfo.c
+31 -1
@@ -40,13 +40,43 @@ static char *sanity_check(char *name, char *email)
40 return name;
41 }
42
43 +static int bogus_from(char *line)
44 +{
45 + /* John Doe <johndoe> */
46 + char *bra, *ket, *dst, *cp;
47 +
48 + /* This is fallback, so do not bother if we already have an
49 + * e-mail address.
50 + */
51 + if (*email)
52 + return 0;
53 +
54 + bra = strchr(line, '<');
55 + if (!bra)
56 + return 0;
57 + ket = strchr(bra, '>');
58 + if (!ket)
59 + return 0;
60 +
61 + for (dst = email, cp = bra+1; cp < ket; )
62 + *dst++ = *cp++;
63 + *dst = 0;
64 + for (cp = line; isspace(*cp); cp++)
65 + ;
66 + for (bra--; isspace(*bra); bra--)
67 + *bra = 0;
68 + cp = sanity_check(cp, email);
69 + strcpy(name, cp);
70 + return 1;
71 +}
72 +
73 static int handle_from(char *line)
74 {
75 char *at = strchr(line, '@');
76 char *dst;
77
78 if (!at)
49 - return 0;
79 + return bogus_from(line);
80
81 /*
82 * If we already have one email, don't take any confusing lines