mq: upgrade the patch to HG format when adding the author name with qrefresh
When setting the author field with qrefresh (-u|-U), and the patch does have
neither a 'From:' nor a '# User' header, add the author name as such:
- if the patch has a 'Date:' header, add a 'From:' header
- otherwise, upgrade to Mercurial extended patch format and add # From
--- a/hgext/mq.py Wed Aug 12 10:46:16 2009 +0200
+++ b/hgext/mq.py Wed Aug 12 10:48:18 2009 +0200
@@ -145,7 +145,11 @@
patchheaderat = self.comments.index('# HG changeset patch')
self.comments.insert(patchheaderat + 1, '# User ' + user)
except ValueError:
- self.comments = ['From: ' + user, ''] + self.comments
+ if self._hasheader(['Date: ']):
+ self.comments = ['From: ' + user] + self.comments
+ else:
+ tmp = ['# HG changeset patch', '# User ' + user, '']
+ self.comments = tmp + self.comments
self.user = user
def setdate(self, date):
--- a/tests/test-mq-header-date.out Wed Aug 12 10:46:16 2009 +0200
+++ b/tests/test-mq-header-date.out Wed Aug 12 10:48:18 2009 +0200
@@ -231,7 +231,8 @@
1: Three (again) - test
0: [mq]: 1.patch - test
==== qref -u -d
-From: john
+# HG changeset patch
+# User john
diff -r ... 8
@@ -261,7 +262,8 @@
1: Three (again) - test
0: [mq]: 1.patch - test
==== qref -u -d
-From: john
+# HG changeset patch
+# User john
Nine
--- a/tests/test-mq-header-from.out Wed Aug 12 10:46:16 2009 +0200
+++ b/tests/test-mq-header-from.out Wed Aug 12 10:48:18 2009 +0200
@@ -32,7 +32,8 @@
1: [mq]: 2.patch - test
0: [mq]: 1.patch - mary
==== qref -u
-From: jane
+# HG changeset patch
+# User jane
diff -r ... 2
@@ -117,7 +118,8 @@
1: [mq]: 2.patch - jane
0: [mq]: 1.patch - mary
==== qref -u
-From: jane
+# HG changeset patch
+# User jane
Four