patch: fix git sendmail handling without proper mail headers
authorPatrick Mezard <pmezard@gmail.com>
Mon, 08 Oct 2007 22:20:23 +0200
changeset 5418 9b469bdb1ce1
parent 5417 b8872655f951
child 5419 041bd297f01e
patch: fix git sendmail handling without proper mail headers
mercurial/patch.py
tests/test-import
tests/test-import.out
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -59,6 +59,7 @@ def extract(ui, fileobj):
 
         subject = msg['Subject']
         user = msg['From']
+        gitsendmail = 'git-send-email' in msg.get('X-Mailer', '')
         # should try to parse msg['Date']
         date = None
         nodeid = None
@@ -111,7 +112,7 @@ def extract(ui, fileobj):
                             nodeid = line[10:]
                         elif line.startswith("# Parent "):
                             parents.append(line[10:])
-                    elif line == '---' and 'git-send-email' in msg['X-Mailer']:
+                    elif line == '---' and gitsendmail:
                         ignoretext = True
                     if not line.startswith('# ') and not ignoretext:
                         cfp.write(line)
--- a/tests/test-import
+++ b/tests/test-import
@@ -94,10 +94,11 @@ hg --cwd b tip | grep second
 rm -r b
 
 # subject: duplicate detection, removal of [PATCH]
+# The '---' tests the gitsendmail handling without proper mail headers
 cat > mkmsg2.py <<EOF
 import email.Message, sys
 msg = email.Message.Message()
-msg.set_payload('email patch\n\nnext line\n' + open('tip.patch').read())
+msg.set_payload('email patch\n\nnext line\n---\n' + open('tip.patch').read())
 msg['Subject'] = '[PATCH] email patch'
 msg['From'] = 'email patcher'
 sys.stdout.write(msg.as_string())
--- a/tests/test-import.out
+++ b/tests/test-import.out
@@ -111,6 +111,7 @@ applying patch from stdin
 email patch
 
 next line
+---
 % hg import in a subdirectory
 requesting all changes
 adding changesets