changeset 23443:3b653c2fd6ba

mq: drop updateheader - inserthgheader and insertplainheader is enough
author Mads Kiilerich <madski@unity3d.com>
date Fri, 28 Nov 2014 03:09:19 +0100
parents a5c94ea3b8af
children 88629daa727b
files hgext/mq.py
diffstat 1 files changed, 22 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/mq.py	Fri Nov 28 03:09:06 2014 +0100
+++ b/hgext/mq.py	Fri Nov 28 03:09:19 2014 +0100
@@ -303,38 +303,34 @@
                                    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 @@
                 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: