mq: add the date with qrefresh, even if missing (issue1768)
authorYann E. MORIN <yann.morin.1998@anciens.enib.fr>
Wed, 12 Aug 2009 10:57:27 +0200
changeset 9337 2b1260436f83
parent 9336 dd6f605b15c0
child 9338 4cc0815a0dd4
mq: add the date with qrefresh, even if missing (issue1768) When setting the date with qrefresh (-d|-D), and the patch does have neither a 'Date:' nor a '# Date' header, add the date field as such: - if the patch has a 'From:' header, add a 'Date:' header - otherwise, upgrade to Mercurial extended patch format and add '# Date'
hgext/mq.py
tests/test-mq-header-date.out
--- a/hgext/mq.py	Wed Aug 12 10:48:18 2009 +0200
+++ b/hgext/mq.py	Wed Aug 12 10:57:27 2009 +0200
@@ -153,8 +153,17 @@
         self.user = user
 
     def setdate(self, date):
-        if self.updateheader(['# Date '], date):
-            self.date = date
+        if not self.updateheader(['Date: ', '# Date '], date):
+            try:
+                patchheaderat = self.comments.index('# HG changeset patch')
+                self.comments.insert(patchheaderat + 1, '# Date ' + date)
+            except ValueError:
+                if self._hasheader(['From: ']):
+                    self.comments = ['Date: ' + date] + self.comments
+                else:
+                    tmp = ['# HG changeset patch', '# Date ' + date, '']
+                    self.comments = tmp + self.comments
+        self.date = date
 
     def setmessage(self, message):
         if self.comments:
@@ -2599,8 +2608,8 @@
           ('s', 'short', None, _('refresh only files already in the patch and specified files')),
           ('U', 'currentuser', None, _('add/update "From: <current user>" in patch')),
           ('u', 'user', '', _('add/update "From: <given user>" in patch')),
-          ('D', 'currentdate', None, _('update "Date: <current date>" in patch (if present)')),
-          ('d', 'date', '', _('update "Date: <given date>" in patch (if present)'))
+          ('D', 'currentdate', None, _('add/update "Date: <current date>" in patch')),
+          ('d', 'date', '', _('add/update "Date: <given date>" in patch'))
           ] + commands.walkopts + commands.commitopts,
          _('hg qrefresh [-I] [-X] [-e] [-m TEXT] [-l FILE] [-s] [FILE]...')),
     'qrename|qmv':
--- a/tests/test-mq-header-date.out	Wed Aug 12 10:48:18 2009 +0200
+++ b/tests/test-mq-header-date.out	Wed Aug 12 10:57:27 2009 +0200
@@ -35,6 +35,10 @@
 1: [mq]: 2.patch - test
 0: [mq]: 1.patch - test
 ==== qref -d
+# HG changeset patch
+# Date 5 0
+
+
 diff -r ... 2
 --- /dev/null
 +++ b/2
@@ -118,6 +122,9 @@
 1: Three (again) - test
 0: [mq]: 1.patch - test
 ==== qref -d
+# HG changeset patch
+# Date 9 0
+
 Four
 
 diff -r ... 4
@@ -177,6 +184,7 @@
 1: Three (again) - test
 0: [mq]: 1.patch - test
 ==== qref -d
+Date: 12 0
 From: jane
 
 diff -r ... 6
@@ -232,6 +240,7 @@
 0: [mq]: 1.patch - test
 ==== qref -u -d
 # HG changeset patch
+# Date 14 0
 # User john
 
 
@@ -263,6 +272,7 @@
 0: [mq]: 1.patch - test
 ==== qref -u -d
 # HG changeset patch
+# Date 15 0
 # User john
 
 Nine