# HG changeset patch # User Martin Geisler # Date 1242343284 -7200 # Node ID 53ff4a5af284a235f2a430e1f8edfb25c82905aa # Parent 3acc6279b3648fc587db571c531ba102d735686f changelog: turn {de,en}code_extra methods into functions The methods were not really methods -- they didn't use 'self'. Having them as functions in the module it useful for other modules (like the commitsigs extension) that want to recompute the changeset hash and thus want to encode dicts the same way as changelog does it. Removed the underbars from their names at the same time. diff -r 3acc6279b364 -r 53ff4a5af284 mercurial/changelog.py --- a/mercurial/changelog.py Sat May 16 11:16:23 2009 +0200 +++ b/mercurial/changelog.py Fri May 15 01:21:24 2009 +0200 @@ -23,6 +23,19 @@ text = text.replace('\\', '\\\\').replace('\n', '\\n').replace('\r', '\\r') return text.replace('\0', '\\0') +def decodeextra(text): + extra = {} + for l in text.split('\0'): + if l: + k, v = l.decode('string_escape').split(':', 1) + extra[k] = v + return extra + +def encodeextra(d): + # keys must be sorted to produce a deterministic changelog entry + items = [_string_escape('%s:%s' % (k, d[k])) for k in sorted(d)] + return "\0".join(items) + class appender: '''the changelog index must be updated last on disk, so we use this class to delay writes to it''' @@ -145,19 +158,6 @@ return return revlog.revlog.checkinlinesize(self, tr, fp) - def decode_extra(self, text): - extra = {} - for l in text.split('\0'): - if l: - k, v = l.decode('string_escape').split(':', 1) - extra[k] = v - return extra - - def encode_extra(self, d): - # keys must be sorted to produce a deterministic changelog entry - items = [_string_escape('%s:%s' % (k, d[k])) for k in sorted(d)] - return "\0".join(items) - def read(self, node): """ format used: @@ -192,7 +192,7 @@ else: time, timezone, extra = extra_data time, timezone = float(time), int(timezone) - extra = self.decode_extra(extra) + extra = decodeextra(extra) if not extra.get('branch'): extra['branch'] = 'default' files = l[3:] @@ -218,7 +218,7 @@ if extra and extra.get("branch") in ("default", ""): del extra["branch"] if extra: - extra = self.encode_extra(extra) + extra = encodeextra(extra) parseddate = "%s %s" % (parseddate, extra) l = [hex(manifest), user, parseddate] + sorted(files) + ["", desc] text = "\n".join(l)