[PATCH V2] templatekw: add a {negrev} keyword

Yuya Nishihara yuya at tcha.org
Mon Feb 18 08:29:35 EST 2019


On Fri, 15 Feb 2019 15:00:12 -0500, Jordi GutiƩrrez Hermoso wrote:
> # HG changeset patch
> # User Jordi GutiƩrrez Hermoso <jordigh at octave.org>
> # Date 1550259811 18000
> #      Fri Feb 15 14:43:31 2019 -0500
> # Node ID 2aa9472715119f26f2e688dd9130f717113ec518
> # Parent  a22321f2b1ee18ea09a70fee9e524d2f0298aaaa
> templatekw: add a {negrev} keyword

The word "negative revision" isn't correct, but I can't think of any better
name, and I like the feature. Queued, thanks.

Any naming idea is welcome.

> --- a/mercurial/templatekw.py
> +++ b/mercurial/templatekw.py
> @@ -777,6 +777,14 @@ def showrev(context, mapping):
>      ctx = context.resource(mapping, 'ctx')
>      return scmutil.intrev(ctx)
>  
> + at templatekeyword('negrev', requires={'repo', 'ctx'})

Moved this so the functions are roughly sorted lexicographically.

> +def shownegrev(context, mapping):
> +    """Integer. The repository-local changeset negative revision number,
> +    which counts in the opposite direction."""
> +    ctx = context.resource(mapping, 'ctx')
> +    repo = context.resource(mapping, 'repo')
> +    return scmutil.intrev(ctx) - len(repo)

There are two weird cases:

 -r 'wdir()' => not negative
 -r null => unsupported negative integer (out of range)

Maybe return None for these?


More information about the Mercurial-devel mailing list