revset query builder for hglib

Matt Mackall mpm at selenic.com
Mon Jul 25 14:33:34 CDT 2011


On Mon, 2011-07-25 at 13:15 -0500, Kevin Bullock wrote:
> 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.

Let me restate the argument more explicitly:

We MUST have access to raw expressions because the library will not be
bound to particular versions of Mercurial.

We also MUST be able to conveniently do proper escaping (see my
revset.formatspec code) so that we don't repeat decades of SQL query
bugs / security holes.

Having a native-language query builder is only valuable insofar as it
prevents people from making some mistakes by virtue of having some
limited Python-level compile-time (or editor-time!) syntax checking and
proper quoting. But because this is Python, most errors (ie spelling and
type errors) will STILL be run-time errors.

Allowing mixing raw expressions WITH the query builder negates its
advantages, because you can now trivially construct invalid statements
again.

If you go further: 'I suppose the operators should probably accept
strings on the rhs too'

...then it becomes -really- easy to construct invalid expressions.



I don't really care if we have a query builder in hglib. But people
shouldn't lose sight of the fact that they're just syntactical icing and
will never be able to completely replace raw statements. We should get
support for raw statements right -first-.

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list