D5813: revset: add expect to check the size of a set

Yuya Nishihara yuya at tcha.org
Thu Feb 7 08:16:26 EST 2019


> +  $ hg log -r 'expectsize(0:2, 3)'
> +  changeset:   0:2785f51eece5
> +  branch:      a
> +  user:        test
> +  date:        Thu Jan 01 00:00:00 1970 +0000
> +  summary:     0

Nit: the test outputs look unnecessarily verbose. Use `log` (not `hg log`)
instead.

> + at predicate('expectsize(set[, size])', safe=True, takeorder=True)
> +def expectrevsetsize(repo, subset, x, order, n=None):
> +    """Abort if the revset doesn't expect given size"""
> +    args = getargsdict(x, 'expect', 'set size')
> +    size = args.get('size', n)
> +    if size is not None:
> +        try:
> +            # size is given as integer range on expectsize(<set>, <intrange>)

The helper function has been queued. Can you rewrite this to use the
getintrange helper?

> +        if len(rev) not in range(size[0], size[1]+1):

`range()` builds a list of integers on Python 2, which isn't what we want.
Python does support `not (x <= y <= z)` syntax, so you can just compare
integer bounds.

> + at predicate('one(set)', safe=True, takeorder=True)
> +def one(repo, subset, x, order):
> +    """An alias for expect(<set>, 1)"""
> +    return expectrevsetsize(repo, subset, x, order, n=1)

Can you remove `one()` from this patch?

I don't follow the original proposal, but I guess `one()` would be meant to
a user-defined alias (i.e. `revsetalias.one(x) = expectsize(x, 1)`).


More information about the Mercurial-devel mailing list