[PATCH 4 of 8] mq: simplify patchheader handling of the empty line before the diff
Mads Kiilerich
mads at kiilerich.com
Tue Sep 23 20:00:05 CDT 2014
# HG changeset patch
# User Mads Kiilerich <madski at unity3d.com>
# Date 1411515565 -7200
# Wed Sep 24 01:39:25 2014 +0200
# Node ID 889f7da574226e636d689fa4dd425b2b1fbb5ac5
# Parent 746ea8e313f052ebdb2618bfa549b9e9a9b9dff1
mq: simplify patchheader handling of the empty line before the diff
Don't try to append empty lines to HG patche 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.
More information about the Mercurial-devel
mailing list