# HG changeset patch # User Pierre-Yves David # Date 2014-10-09 05:34:48 # Node ID 72100c1d53d437ca983fca25911f07c5b63e4e84 # Parent 37460ee2003c9aead078cfb62dc03fddb3fd9105 obsolete: gather _fm0 meta encoding with other _fm0 code diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py --- a/mercurial/obsolete.py +++ b/mercurial/obsolete.py @@ -208,6 +208,27 @@ def _fm0encodeonemarker(marker): data.extend(sucs) return _pack(format, *data) + metadata +def _fm0encodemeta(meta): + """Return encoded metadata string to string mapping. + + Assume no ':' in key and no '\0' in both key and value.""" + for key, value in meta.iteritems(): + if ':' in key or '\0' in key: + raise ValueError("':' and '\0' are forbidden in metadata key'") + if '\0' in value: + raise ValueError("':' is forbidden in metadata value'") + return '\0'.join(['%s:%s' % (k, meta[k]) for k in sorted(meta)]) + +def _fm0decodemeta(data): + """Return string to string dictionary from encoded version.""" + d = {} + for l in data.split('\0'): + if l: + key, value = l.split(':') + d[key] = value + return d + + # mapping to read/write various marker formats # -> (decoder, encoder) formats = {_fm0version: (_fm0readmarkers, _fm0encodeonemarker)} @@ -232,26 +253,6 @@ def encodemarkers(markers, addheader=Fal yield encodeone(marker) -def _fm0encodemeta(meta): - """Return encoded metadata string to string mapping. - - Assume no ':' in key and no '\0' in both key and value.""" - for key, value in meta.iteritems(): - if ':' in key or '\0' in key: - raise ValueError("':' and '\0' are forbidden in metadata key'") - if '\0' in value: - raise ValueError("':' is forbidden in metadata value'") - return '\0'.join(['%s:%s' % (k, meta[k]) for k in sorted(meta)]) - -def _fm0decodemeta(data): - """Return string to string dictionary from encoded version.""" - d = {} - for l in data.split('\0'): - if l: - key, value = l.split(':') - d[key] = value - return d - class marker(object): """Wrap obsolete marker raw data"""