comparison mercurial/changelog.py @ 17810:2894d180afa1

changelog: extract description cleaning logic in a dedicated function The amend logic have use for it.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Thu, 18 Oct 2012 22:04:49 +0200
parents 5c89e7fa5bc2
children 6f79c32c0bdf
comparison
equal deleted inserted replaced
17809:a7462ca7f75e 17810:2894d180afa1
47 def encodeextra(d): 47 def encodeextra(d):
48 # keys must be sorted to produce a deterministic changelog entry 48 # keys must be sorted to produce a deterministic changelog entry
49 items = [_string_escape('%s:%s' % (k, d[k])) for k in sorted(d)] 49 items = [_string_escape('%s:%s' % (k, d[k])) for k in sorted(d)]
50 return "\0".join(items) 50 return "\0".join(items)
51 51
52 def stripdesc(desc):
53 """strip trailing whitespace and leading and trailing empty lines"""
54 return '\n'.join([l.rstrip() for l in desc.splitlines()]).strip('\n')
55
52 class appender(object): 56 class appender(object):
53 '''the changelog index must be updated last on disk, so we use this class 57 '''the changelog index must be updated last on disk, so we use this class
54 to delay writes to it''' 58 to delay writes to it'''
55 def __init__(self, fp, buf): 59 def __init__(self, fp, buf):
56 self.data = buf 60 self.data = buf
306 raise error.RevlogError(_("empty username")) 310 raise error.RevlogError(_("empty username"))
307 if "\n" in user: 311 if "\n" in user:
308 raise error.RevlogError(_("username %s contains a newline") 312 raise error.RevlogError(_("username %s contains a newline")
309 % repr(user)) 313 % repr(user))
310 314
311 # strip trailing whitespace and leading and trailing empty lines 315 desc = stripdesc(desc)
312 desc = '\n'.join([l.rstrip() for l in desc.splitlines()]).strip('\n')
313 316
314 if date: 317 if date:
315 parseddate = "%d %d" % util.parsedate(date) 318 parseddate = "%d %d" % util.parsedate(date)
316 else: 319 else:
317 parseddate = "%d %d" % util.makedate() 320 parseddate = "%d %d" % util.makedate()