graphlog: explicitely join multivalue parameters
authorPatrick Mezard <patrick@mezard.eu>
Wed, 22 Feb 2012 12:30:15 +0100
changeset 16147 5607d829bf17
parent 16146 267cebac84c3
child 16148 184cc3c3e0a6
graphlog: explicitely join multivalue parameters This will let use override the "join" value (and/or) depending on the option considered. The option revset arity is now deduced from the revset and the option value type, to simplify opt2revset definition.
hgext/graphlog.py
tests/test-glog.t
--- a/hgext/graphlog.py	Wed Feb 22 12:30:14 2012 +0100
+++ b/hgext/graphlog.py	Wed Feb 22 12:30:15 2012 +0100
@@ -249,18 +249,18 @@
     """Return revset str built of revisions, log options and file patterns.
     """
     opt2revset = {
-        'follow': (0, 'follow()'),
-        'no_merges': (0, 'not merge()'),
-        'only_merges': (0, 'merge()'),
-        'removed': (0, 'removes("*")'),
-        'date': (1, 'date($)'),
-        'branch': (2, 'branch($)'),
-        'exclude': (2, 'not file($)'),
-        'include': (2, 'file($)'),
-        'keyword': (2, 'keyword($)'),
-        'only_branch': (2, 'branch($)'),
-        'prune': (2, 'not ($ or ancestors($))'),
-        'user': (2, 'user($)'),
+        'follow':      ('follow()', None),
+        'no_merges':   ('not merge()', None),
+        'only_merges': ('merge()', None),
+        'removed':     ('removes("*")', None),
+        'date':        ('date($)', None),
+        'branch':      ('branch($)', ' and '),
+        'exclude':     ('not file($)', ' and '),
+        'include':     ('file($)', ' and '),
+        'keyword':     ('keyword($)', ' and '),
+        'only_branch': ('branch($)', ' and '),
+        'prune':       ('not ($ or ancestors($))', ' and '),
+        'user':        ('user($)', ' and '),
         }
     optrevset = []
     revset = []
@@ -272,15 +272,16 @@
             revset.extend(val)
         if op not in opt2revset:
             continue
-        arity, revop = opt2revset[op]
-        revop = revop.replace('$', '%(val)r')
-        if arity == 0:
+        revop, andor = opt2revset[op]
+        if '$' not in revop:
             optrevset.append(revop)
-        elif arity == 1:
-            optrevset.append(revop % {'val': val})
         else:
-            for f in val:
-                optrevset.append(revop % {'val': f})
+            revop = revop.replace('$', '%(val)r')
+            if not isinstance(val, list):
+                expr = revop % {'val': val}
+            else:
+                expr = '(' + andor.join((revop % {'val': v}) for v in val) + ')'
+            optrevset.append(expr)
 
     for path in pats:
         optrevset.append('file(%r)' % path)
--- a/tests/test-glog.t	Wed Feb 22 12:30:14 2012 +0100
+++ b/tests/test-glog.t	Wed Feb 22 12:30:15 2012 +0100
@@ -1419,7 +1419,7 @@
   abort: unknown revision 'something nice'!
   [255]
   $ hg log -G --print-revset -k 'something' -k 'nice'
-  ('group', ('and', ('func', ('symbol', 'keyword'), ('string', 'something')), ('func', ('symbol', 'keyword'), ('string', 'nice'))))
+  ('group', ('group', ('and', ('func', ('symbol', 'keyword'), ('string', 'something')), ('func', ('symbol', 'keyword'), ('string', 'nice')))))
   $ hg log -G --only-branch 'something nice'
   abort: unknown revision 'something nice'!
   [255]