[PATCH 3 of 5] log: use revsetlang.formatspec() to concatenate list expression

Yuya Nishihara yuya at tcha.org
Thu Jan 11 08:58:42 EST 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1514880798 -32400
#      Tue Jan 02 17:13:18 2018 +0900
# Node ID bab0b8954f8430710ddacf1db852a4420121f677
# Parent  c0c7ecef4093eae82fcff7589e534f96c9e8e8c5
log: use revsetlang.formatspec() to concatenate list expression

This rewrites 'not ancestors(x) and not ...' as 'not (ancestors(x) or ...)'
so we can use '%lr'. 'isinstance(val, list)' is replaced with 'listop' to
make sure 'listop' is applied.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -41,6 +41,7 @@ from . import (
     registrar,
     revlog,
     revset,
+    revsetlang,
     scmutil,
     smartset,
     templatekw,
@@ -2347,13 +2348,13 @@ def _makenofollowlogfilematcher(repo, pa
     '_fdescendants':    ('_firstdescendants(%(val)s)', None),
     '_matchfiles':      ('_matchfiles(%(val)s)', None),
     'date':             ('date(%(val)r)', None),
-    'branch':           ('branch(%(val)r)', ' or '),
-    '_patslog':         ('filelog(%(val)r)', ' or '),
-    '_patsfollow':      ('follow(%(val)r)', ' or '),
-    '_patsfollowfirst': ('_followfirst(%(val)r)', ' or '),
-    'keyword':          ('keyword(%(val)r)', ' or '),
-    'prune':            ('not ancestors(%(val)r)', ' and '),
-    'user':             ('user(%(val)r)', ' or '),
+    'branch':           ('branch(%(val)r)', '%lr'),
+    '_patslog':         ('filelog(%(val)r)', '%lr'),
+    '_patsfollow':      ('follow(%(val)r)', '%lr'),
+    '_patsfollowfirst': ('_followfirst(%(val)r)', '%lr'),
+    'keyword':          ('keyword(%(val)r)', '%lr'),
+    'prune':            ('ancestors(%(val)r)', 'not %lr'),
+    'user':             ('user(%(val)r)', '%lr'),
 }
 
 def _makelogrevset(repo, pats, opts, revs):
@@ -2473,14 +2474,15 @@ def _makelogrevset(repo, pats, opts, rev
             continue
         if op not in _opt2logrevset:
             continue
-        revop, andor = _opt2logrevset[op]
+        revop, listop = _opt2logrevset[op]
         if '%(val)' not in revop:
             expr.append(revop)
         else:
-            if not isinstance(val, list):
+            if not listop:
                 e = revop % {'val': val}
             else:
-                e = '(' + andor.join((revop % {'val': v}) for v in val) + ')'
+                e = [revop % {'val': v} for v in val]
+                e = revsetlang.formatspec(listop, e)
             expr.append(e)
 
     if expr:
diff --git a/tests/test-glog.t b/tests/test-glog.t
--- a/tests/test-glog.t
+++ b/tests/test-glog.t
@@ -1500,12 +1500,14 @@ glog always reorders nodes which explain
       (func
         (symbol 'branch')
         (string 'default'))
-      (func
-        (symbol 'branch')
-        (string 'branch'))
-      (func
-        (symbol 'branch')
-        (string 'branch'))))
+      (or
+        (list
+          (func
+            (symbol 'branch')
+            (string 'branch'))
+          (func
+            (symbol 'branch')
+            (string 'branch'))))))
   <filteredset
     <spanset- 0:37>,
     <addset
@@ -1571,26 +1573,25 @@ glog always reorders nodes which explain
   [255]
   $ testlog --prune 31 --prune 32
   []
-  (and
-    (not
-      (func
-        (symbol 'ancestors')
-        (string '31')))
-    (not
-      (func
-        (symbol 'ancestors')
-        (string '32'))))
+  (not
+    (or
+      (list
+        (func
+          (symbol 'ancestors')
+          (string '31'))
+        (func
+          (symbol 'ancestors')
+          (string '32')))))
   <filteredset
-    <filteredset
-      <spanset- 0:37>,
-      <not
+    <spanset- 0:37>,
+    <not
+      <addset
         <filteredset
           <spanset- 0:37>,
-          <generatorsetdesc+>>>>,
-    <not
-      <filteredset
-        <spanset- 0:37>,
-        <generatorsetdesc+>>>>
+          <generatorsetdesc+>>,
+        <filteredset
+          <spanset- 0:37>,
+          <generatorsetdesc+>>>>>
 
 Dedicated repo for --follow and paths filtering. The g is crafted to
 have 2 filelog topological heads in a linear changeset graph.


More information about the Mercurial-devel mailing list