diff --git a/mercurial/changelog.py b/mercurial/changelog.py
index a7462ca7f75e60ae765114b2fcdf8dc7a262372b_bWVyY3VyaWFsL2NoYW5nZWxvZy5weQ==..2894d180afa1851d896368fab2edaa7123a5d920_bWVyY3VyaWFsL2NoYW5nZWxvZy5weQ== 100644
--- 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)