remote-hg: improve email sanitation

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Felipe Contreras committed Apr 22, 2013 at 16:55 UTC a2e462c5b50c6072e478d434b3892c9f7155a084
2 files changed +12 -6
contrib/remote-helpers/git-remote-hg
+8 -2
@@ -51,6 +51,7 @@ import urlparse
51
52 NAME_RE = re.compile('^([^<>]+)')
53 AUTHOR_RE = re.compile('^([^<>]+?)? ?<([^<>]*)>$')
54 +EMAIL_RE = re.compile('^([^<>]+[^ \\\t<>])?\\b(?:[ \\t<>]*?)\\b([^ \\t<>]+@[^ \\t<>]+)')
55 AUTHOR_HG_RE = re.compile('^(.*?) ?<(.*?)(?:>(.+)?)?$')
56 RAW_AUTHOR_RE = re.compile('^(\w+) (?:(.+)? )?<(.*)> (\d+) ([+-]\d+)')
57
@@ -245,9 +246,14 @@ def fixup_user_git(user):
246 name = m.group(1)
247 mail = m.group(2).strip()
248 else:
248 - m = NAME_RE.match(user)
249 + m = EMAIL_RE.match(user)
250 if m:
250 - name = m.group(1).strip()
251 + name = m.group(1)
252 + mail = m.group(2)
253 + else:
254 + m = NAME_RE.match(user)
255 + if m:
256 + name = m.group(1).strip()
257 return (name, mail)
258
259 def fixup_user_hg(user):
contrib/remote-helpers/test-hg.sh
+4 -4
@@ -137,15 +137,15 @@ test_expect_success 'authors' '
137
138 author_test alpha "" "H G Wells <wells@example.com>" &&
139 author_test beta "test" "test <unknown>" &&
140 - author_test beta "test <test@example.com> (comment)" "test <unknown>" &&
140 + author_test beta "test <test@example.com> (comment)" "test <test@example.com>" &&
141 author_test gamma "<test@example.com>" "Unknown <test@example.com>" &&
142 author_test delta "name<test@example.com>" "name <test@example.com>" &&
143 - author_test epsilon "name <test@example.com" "name <unknown>" &&
143 + author_test epsilon "name <test@example.com" "name <test@example.com>" &&
144 author_test zeta " test " "test <unknown>" &&
145 author_test eta "test < test@example.com >" "test <test@example.com>" &&
146 - author_test theta "test >test@example.com>" "test <unknown>" &&
146 + author_test theta "test >test@example.com>" "test <test@example.com>" &&
147 author_test iota "test < test <at> example <dot> com>" "test <unknown>" &&
148 - author_test kappa "test@example.com" "test@example.com <unknown>"
148 + author_test kappa "test@example.com" "Unknown <test@example.com>"
149 ) &&
150
151 git clone "hg::$PWD/hgrepo" gitrepo &&