revset query builder for hglib

Matt Mackall mpm at selenic.com
Mon Jul 25 12:31:33 CDT 2011


On Mon, 2011-07-25 at 19:57 +0300, Idan Kamara wrote:
> On Mon, Jul 25, 2011 at 6:24 PM, Kevin Bullock <
> kbullock+mercurial at ringworld.org> wrote:
> > On Jul 23, 2011, at 11:50 AM, Matt Mackall wrote:
> >
> >> On Sat, 2011-07-23 at 10:54 +0200, Isaac Jurado wrote:
> >>> On Fri, Jul 22, 2011 at 8:15 PM, Idan Kamara <idankk86 at gmail.com> wrote:
> >>>> I'd like to implement some kind of revset query builder for hglib,
> here's
> >>>> what I had in mind:
> >>>
> >>> Isn't that similar to this?
> >>>
> >>> http://www.selenic.com/pipermail/mercurial-devel/2011-July/033276.html
> >>
> >> Yes and no.
> >>
> >> It has the notable advantage that it's parsed by Python's compiler (and
> >> probably your editor's syntax highlighter) so mistakes get caught
> >> sooner.
> >>
> >> The downsides are:
> >>
> >> - it's not as compact
> >> - it can't be perfectly one to one with revset grammar
> >> - newly-added revset predicates require updating python-hglib
> >
> > The last one could be solved by letting the query builder operations also
> take strings:
> >
> >>>> rs.branch('default') & 'somenewpredicate()'
> >
> > since a query builder eventually has to compile to a string to send over
> the wire anyway.
> 
> 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

(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