Patchwork [4,of,8] mq: simplify patchheader handling of the empty line before the diff

login
register
mail settings
Submitter Mads Kiilerich
Date Sept. 24, 2014, 1 a.m.
Message ID <889f7da574226e636d68.1411520405@localhost.localdomain>
Download mbox | patch
Permalink /patch/5949/
State Accepted
Headers show

Comments

Mads Kiilerich - Sept. 24, 2014, 1 a.m.
# HG changeset patch
# User Mads Kiilerich <madski@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.
Pierre-Yves David - Sept. 24, 2014, 4:58 p.m.
On 09/23/2014 06:00 PM, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <madski@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.

Patches 1-4  pushed to the clowncopter.

Patch

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.