Mercurial > hg
changeset 22544:0d75ce895adc
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.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Sat, 20 Sep 2014 17:06:56 +0200 |
parents | 6a669d5a62b8 |
children | 6a2cfa61acb0 |
files | hgext/mq.py |
diffstat | 1 files changed, 7 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- 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: