Mercurial > public > mercurial-scm > hg
comparison mercurial/changelog.py @ 5745:234e40e636a8
changelog: inline trivial call for extra data unescaping
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 27 Dec 2007 23:55:40 -0600 |
parents | 9db7fd77417d |
children | d09ccdbf7286 |
comparison
equal
deleted
inserted
replaced
5744:9db7fd77417d | 5745:234e40e636a8 |
---|---|
14 >>> d = {'nl': chr(10), 'bs': chr(92), 'cr': chr(13), 'nul': chr(0)} | 14 >>> d = {'nl': chr(10), 'bs': chr(92), 'cr': chr(13), 'nul': chr(0)} |
15 >>> s = "ab%(nl)scd%(bs)s%(bs)sn%(nul)sab%(cr)scd%(bs)s%(nl)s" % d | 15 >>> s = "ab%(nl)scd%(bs)s%(bs)sn%(nul)sab%(cr)scd%(bs)s%(nl)s" % d |
16 >>> s | 16 >>> s |
17 'ab\\ncd\\\\\\\\n\\x00ab\\rcd\\\\\\n' | 17 'ab\\ncd\\\\\\\\n\\x00ab\\rcd\\\\\\n' |
18 >>> res = _string_escape(s) | 18 >>> res = _string_escape(s) |
19 >>> s == _string_unescape(res) | 19 >>> s == res.decode('string_escape') |
20 True | 20 True |
21 """ | 21 """ |
22 # subset of the string_escape codec | 22 # subset of the string_escape codec |
23 text = text.replace('\\', '\\\\').replace('\n', '\\n').replace('\r', '\\r') | 23 text = text.replace('\\', '\\\\').replace('\n', '\\n').replace('\r', '\\r') |
24 return text.replace('\0', '\\0') | 24 return text.replace('\0', '\\0') |
25 | |
26 def _string_unescape(text): | |
27 return text.decode('string_escape') | |
28 | 25 |
29 class appender: | 26 class appender: |
30 '''the changelog index must be update last on disk, so we use this class | 27 '''the changelog index must be update last on disk, so we use this class |
31 to delay writes to it''' | 28 to delay writes to it''' |
32 def __init__(self, fp, buf): | 29 def __init__(self, fp, buf): |
121 return revlog.checkinlinesize(self, tr, fp) | 118 return revlog.checkinlinesize(self, tr, fp) |
122 | 119 |
123 def decode_extra(self, text): | 120 def decode_extra(self, text): |
124 extra = {} | 121 extra = {} |
125 for l in text.split('\0'): | 122 for l in text.split('\0'): |
126 if not l: | 123 if l: |
127 continue | 124 k, v = text.decode('string_escape').split(':', 1) |
128 k, v = _string_unescape(l).split(':', 1) | 125 extra[k] = v |
129 extra[k] = v | |
130 return extra | 126 return extra |
131 | 127 |
132 def encode_extra(self, d): | 128 def encode_extra(self, d): |
133 # keys must be sorted to produce a deterministic changelog entry | 129 # keys must be sorted to produce a deterministic changelog entry |
134 keys = d.keys() | 130 keys = d.keys() |