[PATCH 5 of 6] mq: add the date with qrefresh, even if missing (issue 1768)

Yann E. MORIN yann.morin.1998 at anciens.enib.fr
Mon Aug 10 16:52:35 CDT 2009


# HG changeset patch
# User "Yann E. MORIN" <yann.morin.1998 at anciens.enib.fr>
# Date 1249937314 -7200
# Node ID c363a4c182723667d724fe776e309b51ab611250
# Parent  46f24ebe07ce1fb2e8cb7dfd54bfb9dbbd547ba7
mq: add the date with qrefresh, even if missing (issue 1768)

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 the patch to the Mercurial extended patch format, and
   add a '# Date' header

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -152,8 +152,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:
@@ -2582,8 +2591,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':
diff --git a/tests/test-mq-header-date.out b/tests/test-mq-header-date.out
--- a/tests/test-mq-header-date.out
+++ b/tests/test-mq-header-date.out
@@ -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




More information about the Mercurial-devel mailing list