RFC: revset relation operator

Augie Fackler raf at durin42.com
Mon Oct 12 09:07:27 CDT 2015


On Sun, Oct 11, 2015 at 05:45:24PM -0500, Matt Mackall wrote:
> It would be nice if we had a convenience syntax for finding things
> related to a given changeset. Currently, we have a couple of these for
> parents, ancestors, and descendants.
>
>  foo^  # first parent
>  foo^2 # second parent
>  foo^^ # first parent of first parent
>  foo~2 # same
>  ::foo # ancestors, inclusive
>  foo:: # descendants, inclusize
>
> But we have nothing directly equivalent to parents(), nor any shorthand
> for children(), successors(), origin(), destination(), or any other type
> of relation we may add. We'd also like a way to specify next, previous,
> all, all exclusive, last, etc.
>
> So my proposal[1] is to add a bracketed postfix (one of {}, [], or <>,
> but perhaps {} is the least bad) that looks like this:
>
>  foo{1}     # children(foo)
>  foo{2}     # children(children(foo))
>  foo{}      # defaults to 1, so children(foo)
>  foo{0}     # synonym for foo
>  foo{-1}    # parents(foo) (both of 'em)
>  foo{-}     # same
>  foo{*}     # foo:: - foo (exclusive)
>  foo{**}    # foo:: (inclusive)
>  foo{-*}    # ::foo - foo
>  foo{$}     # heads(foo::) aka "the last children"
>  foo{-4}::foo # last five changesets in a branch
>
> This makes a lot of our most common expressions shorter. To talk about
> other types of relations, we use a suffix character:
>
>  foo{1g}    # immediate grafts of foo
>  foo{-g}    # origin for grafts
>  foo{o}     # successor(foo)
>  foo{$o}    # final successor of foo

Neat. The one-character suffix thing gives me a little pause as
possibly-not-entirely-self-documenting. Maybe it could be whole [a-z]
words, and we could allow unambiguous prefixes?

>
> Note a consistent direction in the sign used regardless of relation:
> past is negative, future is positive. Operations can be chained:
>
>  foo{-}{}   # foo and its siblings
>  foo{$o}{}  # first children of final successor
>
> We might also add a long-hand method:
>
>  related(foo, "$", "o")
>
> This lets you build revset aliases of various sorts more conveniently
> and we can transform the short expressions into this form internally.
>
> All the bracket choices have problems:
>
>  {}: used by git very differently, might need shell quoting
>  []: used differently by languages, might need shell quoting
>  <>: might need shell quoting, can have ugly side-effects
>
> The little sublanguage in the brackets might present some new wrinkles
> for our parser, which doesn't like most of the characters there anyway.
>
> [1] largely inspired by one from Durham and a discussion at the last
> sprint
> --
> Mathematics is the supreme nostalgia of our time.
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list