revset query builder for hglib

Kevin Bullock kbullock+mercurial at ringworld.org
Mon Jul 25 18:15:45 UTC 2011


On Jul 25, 2011, at 12:31 PM, Matt Mackall wrote:

> On Mon, 2011-07-25 at 19:57 +0300, Idan Kamara wrote:
>> Indeed. There's a 'raw' function just for this:
>> `rs.raw('somenewpredicate()')`:
>> 
>> https://bitbucket.org/idank/python-hglib/changeset/61abd57c8a1f#chg_hglib/revset.py_newline9
>> 
>> I suppose the operators should probably accept strings on the rhs too,
>> it seems it might be useful like that (as you demonstrated).
> 
> As soon as you do that, you lose most of the benefit of Python-level
> syntax-checking. For instance, assume that '+' is mapped onto the revset
> equivalent (aka 'or'). Someone might naively try to do:
> 
> rs.branch(foo) + '^' -> 'branch("foo") + ^' # invalid expression

You mean confusing string concatenation with set union? I'm not sure that's enough to negate the benefit of being able to use raw expressions.

Explicitly using rs.raw(...) instead of bare strings would be fine too though:

rs.branch(foo) + rs.raw('something()')

which should be enough of a hint that you can't do:

rs.branch(foo) + rs.raw('^')

pacem in terris / mir / shanti / salaam / heiwa
Kevin R. Bullock

> (I use '^' here as an example as there's obviously no native Python way
> to represent the '^' postfix operator except as a function call)
> 
> -- 
> Mathematics is the supreme nostalgia of our time.
> 
> 




More information about the Mercurial-devel mailing list