[PATCH 3 of 3 RFC] revset: add an 'all' argument to ancestor() to return

Sean Farley sean at farley.io
Sun May 27 08:00:34 EDT 2018


Sean Farley <sean at farley.io> writes:

> # HG changeset patch
> # User Sean Farley <sean at farley.io>
> # Date 1527357855 -7200
> #      Sat May 26 20:04:15 2018 +0200
> # Node ID 9fa3f81f4685ca73393f57253f2f05a0d758c022
> # Parent  000e9442997b1c61ae02a27e657ffb34d170502b
> # EXP-Topic gca-revset
> revset: add an 'all' argument to ancestor() to return
>
> Currently, I'm not sure if this should be an option or a new revset
> method.
>
> diff --git a/mercurial/revset.py b/mercurial/revset.py
> index de543df..ad88cd2 100644
> --- a/mercurial/revset.py
> +++ b/mercurial/revset.py
> @@ -299,25 +299,42 @@ def adds(repo, subset, x):
>      """
>      # i18n: "adds" is a keyword
>      pat = getstring(x, _("adds requires a pattern"))
>      return checkstatus(repo, subset, pat, 1)
>  
> - at predicate('ancestor(*changeset)', safe=True, weight=0.5)
> + at predicate('ancestor(*changeset[, all])', safe=True, weight=0.5)
>  def ancestor(repo, subset, x):
>      """A greatest common ancestor of the changesets.
>  
>      Accepts 0 or more changesets.
>      Will return empty list when passed no args.
>      Greatest common ancestor of a single changeset is that changeset.
> +
> +    If `all` is passed in, then all greatest common ancestors are returned
> +    (e.g. consesus bid merge finding multiple common ancestors from criss cross
> +    merges).
> +
>      """
>      # i18n: "ancestor" is a keyword
>      l = getlist(x)
>      rl = fullreposet(repo)
>      anc = None
> +    allcommon = False
> +
> +    args = getargsdict(x, 'ancestor', 'set all')
> +    if 'all' in args:
> +        allcommon = getboolean(args['all'], _("all expects a boolean"))
>  
>      # (getset(repo, rl, i) for i in l) generates a list of lists
>      for revs in (getset(repo, rl, i) for i in l):
> +        if allcommon and len(revs) > 1:
> +            # for now error if more than two
> +            if len(revs) > 2:
> +                msg = _("currently returning all greatest common ancestors "
> +                        "only works two revs")
> +                raise error.Abort(msg)

I found this a bit awkward, so comments are welcomed. To fix the
limitation of only two revs being passed, we'd need to refactor some of
the code in changelog to return that information.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20180527/968a5ba3/attachment.sig>


More information about the Mercurial-devel mailing list