D6185: changelog: pass default extras into decodeextra()

Yuya Nishihara yuya at tcha.org
Sat Apr 13 07:36:02 EDT 2019


> +def decodeextra(text, default):
>      """
>      >>> from .pycompat import bytechr as chr
> -    >>> sorted(decodeextra(encodeextra({b'foo': b'bar', b'baz': chr(0) + b'2'})
> -    ...                    ).items())
> +    >>> sorted(decodeextra(encodeextra({b'foo': b'bar', b'baz': chr(0) + b'2'}),
> +    ...                    _defaultextra).items())
>      [('baz', '\\x002'), ('branch', 'default'), ('foo', 'bar')]
>      >>> sorted(decodeextra(encodeextra({b'foo': b'bar',
> -    ...                                 b'baz': chr(92) + chr(0) + b'2'})
> -    ...                    ).items())
> +    ...                                 b'baz': chr(92) + chr(0) + b'2'}),
> +    ...                    _defaultextra).items())

Maybe these tests update `_defaultextra` in place?

>      [('baz', '\\\\\\x002'), ('branch', 'default'), ('foo', 'bar')]
>      """
> -    extra = _defaultextra.copy()
> +    extra = default

I think it's safer to do `default.copy()` here.

>      for l in text.split('\0'):
>          if l:
>              k, v = _string_unescape(l).split(':', 1)
> @@ -275,7 +275,7 @@
>          if raw is None:
>              return _defaultextra
>  
> -        return decodeextra(raw)
> +        return decodeextra(raw, _defaultextra.copy())


More information about the Mercurial-devel mailing list