# HG changeset patch # User Yann E. MORIN # Date 1250067447 -7200 # Node ID 2b1260436f834201b87fa816eb4fafdb232f98b3 # Parent dd6f605b15c0bec023795ab56fa71e5d509ec01f 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' diff -r dd6f605b15c0 -r 2b1260436f83 hgext/mq.py --- 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: " in patch')), ('u', 'user', '', _('add/update "From: " in patch')), - ('D', 'currentdate', None, _('update "Date: " in patch (if present)')), - ('d', 'date', '', _('update "Date: " in patch (if present)')) + ('D', 'currentdate', None, _('add/update "Date: " in patch')), + ('d', 'date', '', _('add/update "Date: " in patch')) ] + commands.walkopts + commands.commitopts, _('hg qrefresh [-I] [-X] [-e] [-m TEXT] [-l FILE] [-s] [FILE]...')), 'qrename|qmv': diff -r dd6f605b15c0 -r 2b1260436f83 tests/test-mq-header-date.out --- 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