Patchwork [2,of,2] mq: drop updateheader - inserthgheader and insertplainheader is enough

login
register
mail settings
Submitter Mads Kiilerich
Date Dec. 2, 2014, 4:27 a.m.
Message ID <3bb9aed0c6c3b36d97e4.1417494424@localhost.localdomain>
Download mbox | patch
Permalink /patch/6942/
State Accepted
Headers show

Comments

Mads Kiilerich - Dec. 2, 2014, 4:27 a.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1417140559 -3600
#      Fri Nov 28 03:09:19 2014 +0100
# Node ID 3bb9aed0c6c3b36d97e42d4e3e78affb861768e4
# Parent  7be53db9a5b110568f8a306b4393159af1eb30a5
mq: drop updateheader - inserthgheader and insertplainheader is enough
Pierre-Yves David - Dec. 2, 2014, 10:55 p.m.
On 12/01/2014 08:27 PM, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <madski@unity3d.com>
> # Date 1417140559 -3600
> #      Fri Nov 28 03:09:19 2014 +0100
> # Node ID 3bb9aed0c6c3b36d97e42d4e3e78affb861768e4
> # Parent  7be53db9a5b110568f8a306b4393159af1eb30a5
> mq: drop updateheader - inserthgheader and insertplainheader is enough

These two looks good to me and are pushed to the clowncopter.

Patch

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -303,38 +303,34 @@  class patchheader(object):
                                    for c in self.comments))
 
     def setuser(self, user):
-        if not self.updateheader(['From: ', '# User '], user):
-            try:
-                inserthgheader(self.comments, '# User ', user)
-            except ValueError:
-                if self.plainmode:
-                    insertplainheader(self.comments, 'From', user)
-                else:
-                    tmp = ['# HG changeset patch', '# User ' + user]
-                    self.comments = tmp + self.comments
+        try:
+            inserthgheader(self.comments, '# User ', user)
+        except ValueError:
+            if self.plainmode:
+                insertplainheader(self.comments, 'From', user)
+            else:
+                tmp = ['# HG changeset patch', '# User ' + user]
+                self.comments = tmp + self.comments
         self.user = user
 
     def setdate(self, date):
-        if not self.updateheader(['Date: ', '# Date '], date):
-            try:
-                inserthgheader(self.comments, '# Date ', date)
-            except ValueError:
-                if self.plainmode:
-                    insertplainheader(self.comments, 'Date', date)
-                else:
-                    tmp = ['# HG changeset patch', '# Date ' + date]
-                    self.comments = tmp + self.comments
+        try:
+            inserthgheader(self.comments, '# Date ', date)
+        except ValueError:
+            if self.plainmode:
+                insertplainheader(self.comments, 'Date', date)
+            else:
+                tmp = ['# HG changeset patch', '# Date ' + date]
+                self.comments = tmp + self.comments
         self.date = date
 
     def setparent(self, parent):
-        if not (self.updateheader(['# Parent  '], parent) or
-                self.updateheader(['# Parent '], parent)):
-            try:
-                inserthgheader(self.comments, '# Parent  ', parent)
-            except ValueError:
-                if not self.plainmode:
-                    tmp = ['# HG changeset patch', '# Parent  ' + parent]
-                    self.comments = tmp + self.comments
+        try:
+            inserthgheader(self.comments, '# Parent  ', parent)
+        except ValueError:
+            if not self.plainmode:
+                tmp = ['# HG changeset patch', '# Parent  ' + parent]
+                self.comments = tmp + self.comments
         self.parent = parent
 
     def setmessage(self, message):
@@ -346,18 +342,6 @@  class patchheader(object):
                 self.comments.append('')
             self.comments.append(message)
 
-    def updateheader(self, prefixes, new):
-        '''Update all references to a field in the patch header.
-        Return whether the field is present.'''
-        res = False
-        for prefix in prefixes:
-            for i in xrange(len(self.comments)):
-                if self.comments[i].startswith(prefix):
-                    self.comments[i] = prefix + new
-                    res = True
-                    break
-        return res
-
     def __str__(self):
         s = '\n'.join(self.comments).rstrip()
         if not s: