patch: do not swallow header-like patch first line (issue1859)
authorPatrick Mezard <pmezard@gmail.com>
Thu, 08 Oct 2009 23:42:33 +0200
changeset 9573 b8352a3617f3
parent 9572 1f665246dab3
child 9574 9e9f63d5c456
child 9591 012f1244cd4c
patch: do not swallow header-like patch first line (issue1859) Current solution is hackish but looks like a good trade-off short of rewriting patch.extract() significantly.
mercurial/patch.py
tests/test-import
tests/test-import.out
--- a/mercurial/patch.py	Thu Oct 08 23:32:36 2009 +0200
+++ b/mercurial/patch.py	Thu Oct 08 23:42:33 2009 +0200
@@ -63,6 +63,10 @@
 
         subject = msg['Subject']
         user = msg['From']
+        if not subject and not user:
+            # Not an email, restore parsed headers if any
+            subject = '\n'.join(': '.join(h) for h in msg.items()) + '\n'
+
         gitsendmail = 'git-send-email' in msg.get('X-Mailer', '')
         # should try to parse msg['Date']
         date = None
--- a/tests/test-import	Thu Oct 08 23:32:36 2009 +0200
+++ b/tests/test-import	Thu Oct 08 23:42:33 2009 +0200
@@ -332,3 +332,23 @@
 EOF
 hg import --no-commit a.patch
 cd ..
+
+echo % 'first line mistaken for email headers (issue 1859)'
+hg init emailconfusion
+cd emailconfusion
+cat > a.patch <<EOF
+module: summary
+
+description
+
+
+diff -r 000000000000 -r 9b4c1e343b55 test.txt
+--- /dev/null
++++ b/a
+@@ -0,0 +1,1 @@
++a
+EOF
+hg import -d '0 0' a.patch
+hg parents -v
+cd ..
+
--- a/tests/test-import.out	Thu Oct 08 23:32:36 2009 +0200
+++ b/tests/test-import.out	Thu Oct 08 23:42:33 2009 +0200
@@ -292,3 +292,16 @@
 % add empty file from the end of patch (issue 1495)
 adding a
 applying a.patch
+% first line mistaken for email headers (issue 1859)
+applying a.patch
+changeset:   0:5a681217c0ad
+tag:         tip
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+files:       a
+description:
+module: summary
+
+description
+
+