This is an archive of the discontinued Mercurial Phabricator instance.

changelog: pass default extras into decodeextra()
AbandonedPublic

Authored by martinvonz on Apr 2 2019, 3:30 PM.

Details

Reviewers
None
Group Reviewers
hg-reviewers
Summary

I want to use the function with a different default (empty dict, to be
specific) and this enables that.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

martinvonz created this revision.Apr 2 2019, 3:30 PM
yuja added a subscriber: yuja.Apr 13 2019, 7:45 AM

+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())

In D6185#90696, @yuja wrote:

+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.

Good point. I'll change it.

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())

martinvonz updated this revision to Diff 14735.Apr 13 2019, 6:16 PM
martinvonz abandoned this revision.Apr 13 2019, 6:19 PM

Oh, I actually don't need this patch anymore since I added the string_unescape() method. I'll drop this one.