mq: make patchheader .plainmode more reliable
authorMads Kiilerich <madski@unity3d.com>
Sat, 20 Sep 2014 17:06:56 +0200
changeset 22544 0d75ce895adc
parent 22543 6a669d5a62b8
child 22545 6a2cfa61acb0
mq: make patchheader .plainmode more reliable Instead of having to make extra checks whenever we use .plainmode, let the initial value consider the actual patch header content.
hgext/mq.py
--- a/hgext/mq.py	Wed Sep 24 21:50:03 2014 -0700
+++ b/hgext/mq.py	Sat Sep 20 17:06:56 2014 +0200
@@ -202,7 +202,11 @@
         self.nodeid = nodeid
         self.branch = branch
         self.haspatch = diffstart > 1
-        self.plainmode = plainmode
+        self.plainmode = (plainmode or
+                          '# HG changeset patch' not in self.comments and
+                          util.any(c.startswith('Date: ') or
+                                   c.startswith('From: ')
+                                   for c in self.comments))
 
     def setuser(self, user):
         if not self.updateheader(['From: ', '# User '], user):
@@ -210,7 +214,7 @@
                 patchheaderat = self.comments.index('# HG changeset patch')
                 self.comments.insert(patchheaderat + 1, '# User ' + user)
             except ValueError:
-                if self.plainmode or self._hasheader(['Date: ']):
+                if self.plainmode:
                     self.comments = ['From: ' + user] + self.comments
                 else:
                     tmp = ['# HG changeset patch', '# User ' + user]
@@ -223,7 +227,7 @@
                 patchheaderat = self.comments.index('# HG changeset patch')
                 self.comments.insert(patchheaderat + 1, '# Date ' + date)
             except ValueError:
-                if self.plainmode or self._hasheader(['From: ']):
+                if self.plainmode:
                     self.comments = ['Date: ' + date] + self.comments
                 else:
                     tmp = ['# HG changeset patch', '# Date ' + date]
@@ -258,14 +262,6 @@
                     break
         return res
 
-    def _hasheader(self, prefixes):
-        '''Check if a header starts with any of the given prefixes.'''
-        for prefix in prefixes:
-            for comment in self.comments:
-                if comment.startswith(prefix):
-                    return True
-        return False
-
     def __str__(self):
         s = '\n'.join(self.comments).rstrip()
         if not s: