[PATCH 6 of 7] revset: add inspection data to limit() and last() functions

Yuya Nishihara yuya at tcha.org
Sat Feb 27 09:38:20 EST 2016


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1455626631 -32400
#      Tue Feb 16 21:43:51 2016 +0900
# Node ID ca5471aaa2a27b79e8a99406a66d661612505bc4
# Parent  4ee1fb5324e180c94b3ff704f1ba078edb98563c
revset: add inspection data to limit() and last() functions

We are likely to be interested in how these functions calculate a result set.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1317,7 +1317,8 @@ def limit(repo, subset, x):
             break
         elif y in subset:
             result.append(y)
-    return baseset(result)
+    return baseset(result, datarepr=('<limit n=%d, offset=%d, %r, %r>',
+                                     lim, ofs, subset, os))
 
 @predicate('last(set, [n])', safe=True)
 def last(repo, subset, x):
@@ -1343,7 +1344,7 @@ def last(repo, subset, x):
             break
         elif y in subset:
             result.append(y)
-    return baseset(result)
+    return baseset(result, datarepr=('<last n=%d, %r, %r>', lim, subset, os))
 
 @predicate('max(set)', safe=True)
 def maxrev(repo, subset, x):
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -1984,11 +1984,48 @@ issue4553: check that revset aliases ove
 
 issue2549 - correct optimizations
 
-  $ log 'limit(1 or 2 or 3, 2) and not 2'
+  $ try 'limit(1 or 2 or 3, 2) and not 2'
+  (and
+    (func
+      ('symbol', 'limit')
+      (list
+        (or
+          ('symbol', '1')
+          ('symbol', '2')
+          ('symbol', '3'))
+        ('symbol', '2')))
+    (not
+      ('symbol', '2')))
+  * set:
+  <filteredset
+    <baseset
+      <limit n=2, offset=0,
+        <fullreposet+ 0:9>,
+        <baseset [1, 2, 3]>>>,
+    <not
+      <baseset [2]>>>
   1
   $ log 'max(1 or 2) and not 2'
   $ log 'min(1 or 2) and not 1'
-  $ log 'last(1 or 2, 1) and not 2'
+  $ try 'last(1 or 2, 1) and not 2'
+  (and
+    (func
+      ('symbol', 'last')
+      (list
+        (or
+          ('symbol', '1')
+          ('symbol', '2'))
+        ('symbol', '1')))
+    (not
+      ('symbol', '2')))
+  * set:
+  <filteredset
+    <baseset
+      <last n=1,
+        <fullreposet+ 0:9>,
+        <baseset [2, 1]>>>,
+    <not
+      <baseset [2]>>>
 
 issue4289 - ordering of built-ins
   $ hg log -M -q -r 3:2


More information about the Mercurial-devel mailing list