[PATCH 2 of 6 STABLE] graphlog: explicitely join multivalue parameters
Patrick Mezard
patrick at mezard.eu
Sat Feb 18 19:57:39 UTC 2012
# HG changeset patch
# User Patrick Mezard <patrick at mezard.eu>
# Date 1329594705 -3600
# Branch stable
# Node ID 8fd124b5231f470c654afbd8c4fe207adfd44b6a
# Parent 5f0e7395d1135cb2fe60e16bc1a18fd4d8936ae2
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.
diff --git a/hgext/graphlog.py b/hgext/graphlog.py
--- a/hgext/graphlog.py
+++ b/hgext/graphlog.py
@@ -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)
diff --git a/tests/test-glog.t b/tests/test-glog.t
--- a/tests/test-glog.t
+++ b/tests/test-glog.t
@@ -1401,7 +1401,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]
More information about the Mercurial-devel
mailing list