D1909: cmdutil: add a kludge to make bytes repr() the same on 2 and 3
durin42 (Augie Fackler)
phabricator at mercurial-scm.org
Thu Jan 18 18:17:43 UTC 2018
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
This fixes the output formatting problems I see in debugobsolete. I
still am seeing some effectflag differences, which we'll need to
tackle separately.
I'm not in love with this approach. There might be something better we
could do, and I'd love it if someone else wanted to take a run at
this.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D1909
AFFECTED FILES
mercurial/cmdutil.py
CHANGE DETAILS
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1985,6 +1985,19 @@
return changeset_templater(ui, repo, spec, match, opts, buffered)
+class _regrettablereprbytes(bytes):
+ """Bytes subclass that makes the repr the same on Python 3 as Python 2.
+
+ This is a huge hack.
+ """
+ def __repr__(self):
+ return repr(pycompat.sysstr(self))
+
+def _maybebytestr(v):
+ if pycompat.ispy3 and isinstance(v, bytes):
+ return _regrettablereprbytes(v)
+ return v
+
def showmarker(fm, marker, index=None):
"""utility function to display obsolescence marker in a readable way
@@ -2003,7 +2016,8 @@
fm.write('date', '(%s) ', fm.formatdate(marker.date()))
meta = marker.metadata().copy()
meta.pop('date', None)
- fm.write('metadata', '{%s}', fm.formatdict(meta, fmt='%r: %r', sep=', '))
+ smeta = {_maybebytestr(k): _maybebytestr(v) for k, v in meta.iteritems()}
+ fm.write('metadata', '{%s}', fm.formatdict(smeta, fmt='%r: %r', sep=', '))
fm.plain('\n')
def finddate(ui, repo, date):
To: durin42, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list