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

Yann E. MORIN yann.morin.1998 at anciens.enib.fr
Mon Aug 10 13:27:03 CDT 2009


# HG changeset patch
# User "Yann E. MORIN" <yann.morin.1998 at anciens.enib.fr>
# Date 1249928255 -7200
# Node ID 32dc1c3f3058f7b55d2426045b49b9f459c590f5
# Parent  5caf4e3f9de1b0c2a1dece0fbfd53b08b340b9ac
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
@@ -154,8 +154,19 @@
         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:
+                    self.comments = (['# HG changeset patch',
+                                      '# Date ' + date,
+                                      '']
+                                     + self.comments)
+        self.date = date
 
     def setmessage(self, message):
         if self.comments:
@@ -2588,8 +2599,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