equal
deleted
inserted
replaced
22 error, |
22 error, |
23 pycompat, |
23 pycompat, |
24 revlog, |
24 revlog, |
25 util, |
25 util, |
26 ) |
26 ) |
27 from .utils import dateutil |
27 from .utils import ( |
|
28 dateutil, |
|
29 stringutil, |
|
30 ) |
28 |
31 |
29 _defaultextra = {'branch': 'default'} |
32 _defaultextra = {'branch': 'default'} |
30 |
33 |
31 def _string_escape(text): |
34 def _string_escape(text): |
32 """ |
35 """ |
34 >>> d = {b'nl': chr(10), b'bs': chr(92), b'cr': chr(13), b'nul': chr(0)} |
37 >>> d = {b'nl': chr(10), b'bs': chr(92), b'cr': chr(13), b'nul': chr(0)} |
35 >>> s = b"ab%(nl)scd%(bs)s%(bs)sn%(nul)sab%(cr)scd%(bs)s%(nl)s" % d |
38 >>> s = b"ab%(nl)scd%(bs)s%(bs)sn%(nul)sab%(cr)scd%(bs)s%(nl)s" % d |
36 >>> s |
39 >>> s |
37 'ab\\ncd\\\\\\\\n\\x00ab\\rcd\\\\\\n' |
40 'ab\\ncd\\\\\\\\n\\x00ab\\rcd\\\\\\n' |
38 >>> res = _string_escape(s) |
41 >>> res = _string_escape(s) |
39 >>> s == util.unescapestr(res) |
42 >>> s == stringutil.unescapestr(res) |
40 True |
43 True |
41 """ |
44 """ |
42 # subset of the string_escape codec |
45 # subset of the string_escape codec |
43 text = text.replace('\\', '\\\\').replace('\n', '\\n').replace('\r', '\\r') |
46 text = text.replace('\\', '\\\\').replace('\n', '\\n').replace('\r', '\\r') |
44 return text.replace('\0', '\\0') |
47 return text.replace('\0', '\\0') |
60 if '\\0' in l: |
63 if '\\0' in l: |
61 # fix up \0 without getting into trouble with \\0 |
64 # fix up \0 without getting into trouble with \\0 |
62 l = l.replace('\\\\', '\\\\\n') |
65 l = l.replace('\\\\', '\\\\\n') |
63 l = l.replace('\\0', '\0') |
66 l = l.replace('\\0', '\0') |
64 l = l.replace('\n', '') |
67 l = l.replace('\n', '') |
65 k, v = util.unescapestr(l).split(':', 1) |
68 k, v = stringutil.unescapestr(l).split(':', 1) |
66 extra[k] = v |
69 extra[k] = v |
67 return extra |
70 return extra |
68 |
71 |
69 def encodeextra(d): |
72 def encodeextra(d): |
70 # keys must be sorted to produce a deterministic changelog entry |
73 # keys must be sorted to produce a deterministic changelog entry |