debugrevspec: show nesting structure of smartsets if verbose
authorYuya Nishihara <yuya@tcha.org>
Mon, 16 Mar 2015 18:36:53 +0900
changeset 24458 7d87f672d069
parent 24457 c5022f3579b9
child 24459 7d369fae098e
debugrevspec: show nesting structure of smartsets if verbose This shows how smartsets are constructed from the query. It will be somewhat useful to track problems such as stack overflow.
mercurial/commands.py
mercurial/revset.py
tests/test-revset-dirstate-parents.t
tests/test-revset.t
--- a/mercurial/commands.py	Mon Mar 16 18:15:06 2015 +0900
+++ b/mercurial/commands.py	Mon Mar 16 18:36:53 2015 +0900
@@ -2929,7 +2929,10 @@
             weight, optimizedtree = revset.optimize(newtree, True)
             ui.note("* optimized:\n", revset.prettyformat(optimizedtree), "\n")
     func = revset.match(ui, expr)
-    for c in func(repo):
+    revs = func(repo)
+    if ui.verbose:
+        ui.note("* set:\n", revset.prettyformatset(revs), "\n")
+    for c in revs:
         ui.write("%s\n" % c)
 
 @command('debugsetparents', [], _('REV1 [REV2]'))
--- a/mercurial/revset.py	Mon Mar 16 18:15:06 2015 +0900
+++ b/mercurial/revset.py	Mon Mar 16 18:36:53 2015 +0900
@@ -3419,5 +3419,19 @@
         other.sort(reverse=self.isdescending())
         return other
 
+def prettyformatset(revs):
+    lines = []
+    rs = repr(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)
+
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = symbols.values()
--- a/tests/test-revset-dirstate-parents.t	Mon Mar 16 18:15:06 2015 +0900
+++ b/tests/test-revset-dirstate-parents.t	Mon Mar 16 18:36:53 2015 +0900
@@ -16,14 +16,20 @@
   (func
     ('symbol', 'p1')
     None)
+  * set:
+  <baseset []>
   $ try 'p2()'
   (func
     ('symbol', 'p2')
     None)
+  * set:
+  <baseset []>
   $ try 'parents()'
   (func
     ('symbol', 'parents')
     None)
+  * set:
+  <baseset+ []>
 
 null revision
   $ log 'p1()'
--- a/tests/test-revset.t	Mon Mar 16 18:15:06 2015 +0900
+++ b/tests/test-revset.t	Mon Mar 16 18:36:53 2015 +0900
@@ -93,31 +93,83 @@
   $ echo "[paths]" >> .hg/hgrc
   $ echo "default = ../remote1" >> .hg/hgrc
 
+trivial
+
+  $ try 0:1
+  (range
+    ('symbol', '0')
+    ('symbol', '1'))
+  * set:
+  <filteredset
+    <spanset+ 0:1>>
+  0
+  1
+  $ try 3::6
+  (dagrange
+    ('symbol', '3')
+    ('symbol', '6'))
+  * set:
+  <filteredset
+    <baseset [3, 5, 6]>>
+  3
+  5
+  6
+  $ try '0|1|2'
+  (or
+    (or
+      ('symbol', '0')
+      ('symbol', '1'))
+    ('symbol', '2'))
+  * set:
+  <addset
+    <addset
+      <baseset [0]>,
+      <baseset [1]>>,
+    <baseset [2]>>
+  0
+  1
+  2
+
 names that should work without quoting
 
   $ try a
   ('symbol', 'a')
+  * set:
+  <baseset [0]>
   0
   $ try b-a
   (minus
     ('symbol', 'b')
     ('symbol', 'a'))
+  * set:
+  <filteredset
+    <baseset [1]>>
   1
   $ try _a_b_c_
   ('symbol', '_a_b_c_')
+  * set:
+  <baseset [6]>
   6
   $ try _a_b_c_-a
   (minus
     ('symbol', '_a_b_c_')
     ('symbol', 'a'))
+  * set:
+  <filteredset
+    <baseset [6]>>
   6
   $ try .a.b.c.
   ('symbol', '.a.b.c.')
+  * set:
+  <baseset [7]>
   7
   $ try .a.b.c.-a
   (minus
     ('symbol', '.a.b.c.')
     ('symbol', 'a'))
+  * set:
+  <filteredset
+    <baseset [7]>>
   7
   $ try -- '-a-b-c-' # complains
   hg: parse error at 7: not a prefix: end
@@ -139,6 +191,8 @@
   [255]
   $ try é
   ('symbol', '\xc3\xa9')
+  * set:
+  <baseset [9]>
   9
 
 no quoting needed
@@ -154,6 +208,9 @@
   (minus
     ('string', '-a-b-c-')
     ('symbol', 'a'))
+  * set:
+  <filteredset
+    <baseset [4]>>
   4
 
   $ log '1 or 2'
@@ -170,6 +227,10 @@
       ('symbol', '1')
       ('symbol', '2'))
     ('symbol', '3'))
+  * set:
+  <addset
+    <baseset []>,
+    <baseset [3]>>
   3
   $ try '1|2&3'
   (or
@@ -177,6 +238,10 @@
     (and
       ('symbol', '2')
       ('symbol', '3')))
+  * set:
+  <addset
+    <baseset [1]>,
+    <baseset []>>
   1
   $ try '1&2&3' # associativity
   (and
@@ -184,6 +249,8 @@
       ('symbol', '1')
       ('symbol', '2'))
     ('symbol', '3'))
+  * set:
+  <baseset []>
   $ try '1|(2|3)'
   (or
     ('symbol', '1')
@@ -191,6 +258,12 @@
       (or
         ('symbol', '2')
         ('symbol', '3'))))
+  * set:
+  <addset
+    <baseset [1]>,
+    <addset
+      <baseset [2]>,
+      <baseset [3]>>>
   1
   2
   3
@@ -325,10 +398,16 @@
   (func
     ('symbol', 'grep')
     ('string', '\x08issue\\d+'))
+  * set:
+  <filteredset
+    <fullreposet+ 0:9>>
   $ try 'grep(r"\bissue\d+")'
   (func
     ('symbol', 'grep')
     ('string', '\\bissue\\d+'))
+  * set:
+  <filteredset
+    <fullreposet+ 0:9>>
   6
   $ try 'grep(r"\")'
   hg: parse error at 7: unterminated string
@@ -691,6 +770,8 @@
     (list
       ('symbol', '3')
       ('symbol', '1')))
+  * set:
+  <baseset+ [3]>
   3
   $ try --optimize 'ancestors(1) - ancestors(3)'
   (minus
@@ -706,6 +787,8 @@
     (list
       ('symbol', '1')
       ('symbol', '3')))
+  * set:
+  <baseset+ []>
   $ try --optimize 'not ::2 and ::6'
   (and
     (not
@@ -719,6 +802,8 @@
     (list
       ('symbol', '6')
       ('symbol', '2')))
+  * set:
+  <baseset+ [3, 4, 5, 6]>
   3
   4
   5
@@ -738,6 +823,8 @@
     (list
       ('symbol', '6')
       ('symbol', '4')))
+  * set:
+  <baseset+ [3, 5, 6]>
   3
   5
   6
@@ -974,6 +1061,9 @@
   (func
     ('symbol', 'merge')
     None)
+  * set:
+  <filteredset
+    <fullreposet+ 0:9>>
   6
 
 test alias recursion
@@ -985,6 +1075,11 @@
     (func
       ('symbol', 'merge')
       None))
+  * set:
+  <addset+
+    <filteredset
+      <fullreposet+ 0:9>>,
+    <generatorset+>>
   6
   7
 
@@ -1014,6 +1109,12 @@
     (or
       ('symbol', '1')
       ('symbol', '2')))
+  * set:
+  <addset
+    <baseset [3]>,
+    <addset
+      <baseset [1]>,
+      <baseset [2]>>>
   3
   1
   2
@@ -1034,6 +1135,8 @@
     (range
       ('symbol', '2')
       ('symbol', '5')))
+  * set:
+  <baseset [5]>
   5
 
 test variable isolation, variable placeholders are rewritten as string
@@ -1070,17 +1173,23 @@
   ('symbol', 'tip')
   warning: failed to parse the definition of revset alias "anotherbadone": at 7: not a prefix: end
   warning: failed to parse the definition of revset alias "injectparamasstring2": unknown identifier: _aliasarg
+  * set:
+  <baseset [9]>
   9
   >>> data = file('.hg/hgrc', 'rb').read()
   >>> file('.hg/hgrc', 'wb').write(data.replace('_aliasarg', ''))
 
   $ try 'tip'
   ('symbol', 'tip')
+  * set:
+  <baseset [9]>
   9
 
   $ hg debugrevspec --debug --config revsetalias.'bad name'='tip' "tip"
   ('symbol', 'tip')
   warning: failed to parse the declaration of revset alias "bad name": at 4: invalid token
+  * set:
+  <baseset [9]>
   9
   $ echo 'strictreplacing($1, $10) = $10 or desc("$1")' >> .hg/hgrc
   $ try 'strictreplacing("foo", tip)'
@@ -1094,6 +1203,12 @@
     (func
       ('symbol', 'desc')
       ('string', '$1')))
+  * set:
+  <addset
+    <baseset [9]>,
+    <filteredset
+      <filteredset
+        <fullreposet+ 0:9>>>>
   9
 
   $ try 'd(2:5)'
@@ -1111,6 +1226,8 @@
           ('symbol', '2')
           ('symbol', '5'))
         ('symbol', 'date'))))
+  * set:
+  <baseset [4, 5, 3, 2]>
   4
   5
   3
@@ -1132,6 +1249,8 @@
           ('symbol', '2')
           ('symbol', '3'))
         ('symbol', 'date'))))
+  * set:
+  <baseset [3, 2]>
   3
   2
   $ try 'rs()'
@@ -1177,6 +1296,8 @@
           ('symbol', '2')
           ('symbol', '3'))
         ('symbol', 'date'))))
+  * set:
+  <baseset [3, 2]>
   3
   2
 
@@ -1317,6 +1438,8 @@
       ('symbol', '1ee'))
     ('string', 'ce5'))
   ('string', '2785f51eece5')
+  * set:
+  <baseset [0]>
   0
 
   $ echo 'cat4($1, $2, $3, $4) = $1 ## $2 ## $3 ## $4' >> .hg/hgrc
@@ -1338,6 +1461,8 @@
       ('symbol', '1ee'))
     ('string', 'ce5'))
   ('string', '2785f51eece5')
+  * set:
+  <baseset [0]>
   0
 
 (check concatenation in alias nesting)