[PATCH 1 of 3 V4] changelog: extract description cleaning logic in a dedicated function

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Oct 18 15:16:08 CDT 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1350590689 -7200
# Node ID 98cc94ed644898cebe25d41210cdf6e30cfab9d2
# Parent  a1c4b21fc1b206f5cf386a8d9d5b5882aaa6807f
changelog: extract description cleaning logic in a dedicated function

The amend logic have use for it.

diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -49,6 +49,10 @@
     items = [_string_escape('%s:%s' % (k, d[k])) for k in sorted(d)]
     return "\0".join(items)
 
+def stripdesc(desc):
+    """strip trailing whitespace and leading and trailing empty lines"""
+    return '\n'.join([l.rstrip() for l in desc.splitlines()]).strip('\n')
+
 class appender(object):
     '''the changelog index must be updated last on disk, so we use this class
     to delay writes to it'''
@@ -308,8 +312,7 @@
             raise error.RevlogError(_("username %s contains a newline")
                                     % repr(user))
 
-        # strip trailing whitespace and leading and trailing empty lines
-        desc = '\n'.join([l.rstrip() for l in desc.splitlines()]).strip('\n')
+        desc = stripdesc(desc)
 
         if date:
             parseddate = "%d %d" % util.parsedate(date)


More information about the Mercurial-devel mailing list