changeset 38261:f3033692ccef

stringutil: promote smartset.prettyformat() to utility function It will be used by debugwalk.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 10 Jun 2018 11:50:09 +0900
parents 15a1e37f80bd
children 7c3a59e2971b
files mercurial/debugcommands.py mercurial/smartset.py mercurial/utils/stringutil.py tests/test-glog.t tests/test-revset.t
diffstat 5 files changed, 22 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/debugcommands.py	Fri Jun 01 17:27:58 2018 +0200
+++ b/mercurial/debugcommands.py	Sun Jun 10 11:50:09 2018 +0900
@@ -70,7 +70,6 @@
     scmutil,
     setdiscovery,
     simplemerge,
-    smartset,
     sshpeer,
     sslutil,
     streamclone,
@@ -2236,8 +2235,8 @@
         arevs = revset.makematcher(treebystage['analyzed'])(repo)
         brevs = revset.makematcher(treebystage['optimized'])(repo)
         if opts['show_set'] or (opts['show_set'] is None and ui.verbose):
-            ui.write(("* analyzed set:\n"), smartset.prettyformat(arevs), "\n")
-            ui.write(("* optimized set:\n"), smartset.prettyformat(brevs), "\n")
+            ui.write(("* analyzed set:\n"), stringutil.prettyrepr(arevs), "\n")
+            ui.write(("* optimized set:\n"), stringutil.prettyrepr(brevs), "\n")
         arevs = list(arevs)
         brevs = list(brevs)
         if arevs == brevs:
@@ -2260,7 +2259,7 @@
     func = revset.makematcher(tree)
     revs = func(repo)
     if opts['show_set'] or (opts['show_set'] is None and ui.verbose):
-        ui.write(("* set:\n"), smartset.prettyformat(revs), "\n")
+        ui.write(("* set:\n"), stringutil.prettyrepr(revs), "\n")
     if not opts['show_revs']:
         return
     for c in revs:
--- a/mercurial/smartset.py	Fri Jun 01 17:27:58 2018 +0200
+++ b/mercurial/smartset.py	Sun Jun 10 11:50:09 2018 +0900
@@ -1129,17 +1129,3 @@
 
         other.sort(reverse=self.isdescending())
         return other
-
-def prettyformat(revs):
-    lines = []
-    rs = pycompat.byterepr(revs)
-    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)
-        assert l >= 0
-        lines.append((l, rs[p:q].rstrip()))
-        p = q
-    return '\n'.join('  ' * l + s for l, s in lines)
--- a/mercurial/utils/stringutil.py	Fri Jun 01 17:27:58 2018 +0200
+++ b/mercurial/utils/stringutil.py	Sun Jun 10 11:50:09 2018 +0900
@@ -45,6 +45,21 @@
     else:
         return pycompat.byterepr(o)
 
+def prettyrepr(o):
+    """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)
+        assert l >= 0
+        lines.append((l, rs[p:q].rstrip()))
+        p = q
+    return '\n'.join('  ' * l + s for l, s in lines)
+
 def binary(s):
     """return true if a string is binary data"""
     return bool(s and '\0' in s)
--- a/tests/test-glog.t	Fri Jun 01 17:27:58 2018 +0200
+++ b/tests/test-glog.t	Sun Jun 10 11:50:09 2018 +0900
@@ -91,6 +91,7 @@
   >   revsetlang,
   >   smartset,
   > )
+  > from mercurial.utils import stringutil
   > 
   > def logrevset(repo, pats, opts):
   >     revs = logcmdutil._initialrevs(repo, opts)
@@ -112,7 +113,7 @@
   >             ui = repo.ui
   >             ui.write(b'%r\n' % (opts.get(b'rev', []),))
   >             ui.write(revsetlang.prettyformat(tree) + b'\n')
-  >             ui.write(smartset.prettyformat(revs) + b'\n')
+  >             ui.write(stringutil.prettyrepr(revs) + b'\n')
   >             revs = smartset.baseset()  # display no revisions
   >         return revs, filematcher
   >     extensions.wrapfunction(logcmdutil, 'getrevs', printrevset)
--- a/tests/test-revset.t	Fri Jun 01 17:27:58 2018 +0200
+++ b/tests/test-revset.t	Sun Jun 10 11:50:09 2018 +0900
@@ -42,8 +42,8 @@
   >     registrar,
   >     revset,
   >     revsetlang,
-  >     smartset,
   > )
+  > from mercurial.utils import stringutil
   > cmdtable = {}
   > command = registrar.command(cmdtable)
   > @command(b'debugrevlistspec',
@@ -63,7 +63,7 @@
   >     func = revset.match(ui, expr, lookup=revset.lookupfn(repo))
   >     revs = func(repo)
   >     if ui.verbose:
-  >         ui.note(b"* set:\n", smartset.prettyformat(revs), b"\n")
+  >         ui.note(b"* set:\n", stringutil.prettyrepr(revs), b"\n")
   >     for c in revs:
   >         ui.write(b"%d\n" % c)
   > EOF