comparison mercurial/cmdutil.py @ 35914:1bee7762fd46

cmdutil: add a kludge to make bytes repr() the same on 2 and 3 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. Differential Revision: https://phab.mercurial-scm.org/D1909
author Augie Fackler <augie@google.com>
date Thu, 18 Jan 2018 12:59:40 -0500
parents e5b6ba786d83
children 7625b4f7db70
comparison
equal deleted inserted replaced
35913:29759c46aa1a 35914:1bee7762fd46
2075 if not spec.ref and not spec.tmpl and not spec.mapfile: 2075 if not spec.ref and not spec.tmpl and not spec.mapfile:
2076 return changeset_printer(ui, repo, match, opts, buffered) 2076 return changeset_printer(ui, repo, match, opts, buffered)
2077 2077
2078 return changeset_templater(ui, repo, spec, match, opts, buffered) 2078 return changeset_templater(ui, repo, spec, match, opts, buffered)
2079 2079
2080 class _regrettablereprbytes(bytes):
2081 """Bytes subclass that makes the repr the same on Python 3 as Python 2.
2082
2083 This is a huge hack.
2084 """
2085 def __repr__(self):
2086 return repr(pycompat.sysstr(self))
2087
2088 def _maybebytestr(v):
2089 if pycompat.ispy3 and isinstance(v, bytes):
2090 return _regrettablereprbytes(v)
2091 return v
2092
2080 def showmarker(fm, marker, index=None): 2093 def showmarker(fm, marker, index=None):
2081 """utility function to display obsolescence marker in a readable way 2094 """utility function to display obsolescence marker in a readable way
2082 2095
2083 To be used by debug function.""" 2096 To be used by debug function."""
2084 if index is not None: 2097 if index is not None:
2093 fm.write('parentnodes', '{%s} ', 2106 fm.write('parentnodes', '{%s} ',
2094 fm.formatlist(map(hex, parents), name='node', sep=', ')) 2107 fm.formatlist(map(hex, parents), name='node', sep=', '))
2095 fm.write('date', '(%s) ', fm.formatdate(marker.date())) 2108 fm.write('date', '(%s) ', fm.formatdate(marker.date()))
2096 meta = marker.metadata().copy() 2109 meta = marker.metadata().copy()
2097 meta.pop('date', None) 2110 meta.pop('date', None)
2098 fm.write('metadata', '{%s}', fm.formatdict(meta, fmt='%r: %r', sep=', ')) 2111 smeta = {_maybebytestr(k): _maybebytestr(v) for k, v in meta.iteritems()}
2112 fm.write('metadata', '{%s}', fm.formatdict(smeta, fmt='%r: %r', sep=', '))
2099 fm.plain('\n') 2113 fm.plain('\n')
2100 2114
2101 def finddate(ui, repo, date): 2115 def finddate(ui, repo, date):
2102 """Find the tipmost changeset that matches the given date spec""" 2116 """Find the tipmost changeset that matches the given date spec"""
2103 2117