##// END OF EJS Templates
stringutil: promote smartset.prettyformat() to utility function...
Yuya Nishihara -
r38280:f3033692 default
parent child Browse files
Show More
@@ -70,7 +70,6 b' from . import ('
70 scmutil,
70 scmutil,
71 setdiscovery,
71 setdiscovery,
72 simplemerge,
72 simplemerge,
73 smartset,
74 sshpeer,
73 sshpeer,
75 sslutil,
74 sslutil,
76 streamclone,
75 streamclone,
@@ -2236,8 +2235,8 b' def debugrevspec(ui, repo, expr, **opts)'
2236 arevs = revset.makematcher(treebystage['analyzed'])(repo)
2235 arevs = revset.makematcher(treebystage['analyzed'])(repo)
2237 brevs = revset.makematcher(treebystage['optimized'])(repo)
2236 brevs = revset.makematcher(treebystage['optimized'])(repo)
2238 if opts['show_set'] or (opts['show_set'] is None and ui.verbose):
2237 if opts['show_set'] or (opts['show_set'] is None and ui.verbose):
2239 ui.write(("* analyzed set:\n"), smartset.prettyformat(arevs), "\n")
2238 ui.write(("* analyzed set:\n"), stringutil.prettyrepr(arevs), "\n")
2240 ui.write(("* optimized set:\n"), smartset.prettyformat(brevs), "\n")
2239 ui.write(("* optimized set:\n"), stringutil.prettyrepr(brevs), "\n")
2241 arevs = list(arevs)
2240 arevs = list(arevs)
2242 brevs = list(brevs)
2241 brevs = list(brevs)
2243 if arevs == brevs:
2242 if arevs == brevs:
@@ -2260,7 +2259,7 b' def debugrevspec(ui, repo, expr, **opts)'
2260 func = revset.makematcher(tree)
2259 func = revset.makematcher(tree)
2261 revs = func(repo)
2260 revs = func(repo)
2262 if opts['show_set'] or (opts['show_set'] is None and ui.verbose):
2261 if opts['show_set'] or (opts['show_set'] is None and ui.verbose):
2263 ui.write(("* set:\n"), smartset.prettyformat(revs), "\n")
2262 ui.write(("* set:\n"), stringutil.prettyrepr(revs), "\n")
2264 if not opts['show_revs']:
2263 if not opts['show_revs']:
2265 return
2264 return
2266 for c in revs:
2265 for c in revs:
@@ -1129,17 +1129,3 b' class fullreposet(_spanset):'
1129
1129
1130 other.sort(reverse=self.isdescending())
1130 other.sort(reverse=self.isdescending())
1131 return other
1131 return other
1132
1133 def prettyformat(revs):
1134 lines = []
1135 rs = pycompat.byterepr(revs)
1136 p = 0
1137 while p < len(rs):
1138 q = rs.find('<', p + 1)
1139 if q < 0:
1140 q = len(rs)
1141 l = rs.count('<', 0, p) - rs.count('>', 0, p)
1142 assert l >= 0
1143 lines.append((l, rs[p:q].rstrip()))
1144 p = q
1145 return '\n'.join(' ' * l + s for l, s in lines)
@@ -45,6 +45,21 b' def pprint(o, bprefix=False):'
45 else:
45 else:
46 return pycompat.byterepr(o)
46 return pycompat.byterepr(o)
47
47
48 def prettyrepr(o):
49 """Pretty print a representation of a possibly-nested object"""
50 lines = []
51 rs = pycompat.byterepr(o)
52 p = 0
53 while p < len(rs):
54 q = rs.find('<', p + 1)
55 if q < 0:
56 q = len(rs)
57 l = rs.count('<', 0, p) - rs.count('>', 0, p)
58 assert l >= 0
59 lines.append((l, rs[p:q].rstrip()))
60 p = q
61 return '\n'.join(' ' * l + s for l, s in lines)
62
48 def binary(s):
63 def binary(s):
49 """return true if a string is binary data"""
64 """return true if a string is binary data"""
50 return bool(s and '\0' in s)
65 return bool(s and '\0' in s)
@@ -91,6 +91,7 b' o (0) root'
91 > revsetlang,
91 > revsetlang,
92 > smartset,
92 > smartset,
93 > )
93 > )
94 > from mercurial.utils import stringutil
94 >
95 >
95 > def logrevset(repo, pats, opts):
96 > def logrevset(repo, pats, opts):
96 > revs = logcmdutil._initialrevs(repo, opts)
97 > revs = logcmdutil._initialrevs(repo, opts)
@@ -112,7 +113,7 b' o (0) root'
112 > ui = repo.ui
113 > ui = repo.ui
113 > ui.write(b'%r\n' % (opts.get(b'rev', []),))
114 > ui.write(b'%r\n' % (opts.get(b'rev', []),))
114 > ui.write(revsetlang.prettyformat(tree) + b'\n')
115 > ui.write(revsetlang.prettyformat(tree) + b'\n')
115 > ui.write(smartset.prettyformat(revs) + b'\n')
116 > ui.write(stringutil.prettyrepr(revs) + b'\n')
116 > revs = smartset.baseset() # display no revisions
117 > revs = smartset.baseset() # display no revisions
117 > return revs, filematcher
118 > return revs, filematcher
118 > extensions.wrapfunction(logcmdutil, 'getrevs', printrevset)
119 > extensions.wrapfunction(logcmdutil, 'getrevs', printrevset)
@@ -42,8 +42,8 b" these predicates use '\\0' as a separator"
42 > registrar,
42 > registrar,
43 > revset,
43 > revset,
44 > revsetlang,
44 > revsetlang,
45 > smartset,
46 > )
45 > )
46 > from mercurial.utils import stringutil
47 > cmdtable = {}
47 > cmdtable = {}
48 > command = registrar.command(cmdtable)
48 > command = registrar.command(cmdtable)
49 > @command(b'debugrevlistspec',
49 > @command(b'debugrevlistspec',
@@ -63,7 +63,7 b" these predicates use '\\0' as a separator"
63 > func = revset.match(ui, expr, lookup=revset.lookupfn(repo))
63 > func = revset.match(ui, expr, lookup=revset.lookupfn(repo))
64 > revs = func(repo)
64 > revs = func(repo)
65 > if ui.verbose:
65 > if ui.verbose:
66 > ui.note(b"* set:\n", smartset.prettyformat(revs), b"\n")
66 > ui.note(b"* set:\n", stringutil.prettyrepr(revs), b"\n")
67 > for c in revs:
67 > for c in revs:
68 > ui.write(b"%d\n" % c)
68 > ui.write(b"%d\n" % c)
69 > EOF
69 > EOF
General Comments 0
You need to be logged in to leave comments. Login now