# HG changeset patch # User Mads Kiilerich # Date 2014-09-23 23:39:25 # Node ID 382c2be610dc5c1cd275150fbd2c8b8dd73e0e21 # Parent 3f948469bac011a96bb9944008e3a944649181c7 mq: simplify patchheader handling of the empty line before the diff Don't try to append empty lines to HG patch headers - instead, add them in str method. This minor change removes some apparently redundant code and makes the code more robust. diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -191,7 +191,6 @@ class patchheader(object): # make sure message isn't empty if format and format.startswith("tag") and subject: - message.insert(0, "") message.insert(0, subject) self.message = message @@ -214,7 +213,7 @@ class patchheader(object): if self.plainmode or self._hasheader(['Date: ']): self.comments = ['From: ' + user] + self.comments else: - tmp = ['# HG changeset patch', '# User ' + user, ''] + tmp = ['# HG changeset patch', '# User ' + user] self.comments = tmp + self.comments self.user = user @@ -227,7 +226,7 @@ class patchheader(object): if self.plainmode or self._hasheader(['From: ']): self.comments = ['Date: ' + date] + self.comments else: - tmp = ['# HG changeset patch', '# Date ' + date, ''] + tmp = ['# HG changeset patch', '# Date ' + date] self.comments = tmp + self.comments self.date = date @@ -268,9 +267,10 @@ class patchheader(object): return False def __str__(self): - if not self.comments: + s = '\n'.join(self.comments).rstrip() + if not s: return '' - return '\n'.join(self.comments) + '\n\n' + return s + '\n\n' def _delmsg(self): '''Remove existing message, keeping the rest of the comments fields.