Mercurial > public > mercurial-scm > hg-stable
diff mercurial/utils/stringutil.py @ 38276:fbb2eddea4d2
stringutil: fix prettyrepr() to not orphan foo=<...> line
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 10 Jun 2018 12:24:53 +0900 |
parents | f3033692ccef |
children | 96f65bdf0bf4 |
line wrap: on
line diff
--- a/mercurial/utils/stringutil.py Sun Jun 10 11:55:52 2018 +0900 +++ b/mercurial/utils/stringutil.py Sun Jun 10 12:24:53 2018 +0900 @@ -49,15 +49,26 @@ """Pretty print a representation of a possibly-nested object""" lines = [] rs = pycompat.byterepr(o) - p = 0 - while p < len(rs): - q = rs.find('<', p + 1) - if q < 0: - q = len(rs) - l = rs.count('<', 0, p) - rs.count('>', 0, p) + p0 = p1 = 0 + while p0 < len(rs): + # '... field=<type ... field=<type ...' + # ~~~~~~~~~~~~~~~~ + # p0 p1 q0 q1 + q0 = -1 + q1 = rs.find('<', p1 + 1) + if q1 < 0: + q1 = len(rs) + elif q1 > p1 + 1 and rs.startswith('=', q1 - 1): + # backtrack for ' field=<' + q0 = rs.rfind(' ', p1 + 1, q1 - 1) + if q0 < 0: + q0 = q1 + else: + q0 += 1 # skip ' ' + l = rs.count('<', 0, p0) - rs.count('>', 0, p0) assert l >= 0 - lines.append((l, rs[p:q].rstrip())) - p = q + lines.append((l, rs[p0:q0].rstrip())) + p0, p1 = q0, q1 return '\n'.join(' ' * l + s for l, s in lines) def binary(s):