diff -r e1643a0455c8 -r 36b62a522814 mercurial/templatekw.py --- a/mercurial/templatekw.py Mon Feb 18 18:44:21 2019 -0500 +++ b/mercurial/templatekw.py Mon Feb 18 23:43:40 2019 -0500 @@ -559,8 +559,11 @@ """Integer. The repository-local changeset negative revision number, which counts in the opposite direction.""" ctx = context.resource(mapping, 'ctx') + rev = ctx.rev() + if rev is None or rev < 0: # wdir() or nullrev? + return None repo = context.resource(mapping, 'repo') - return scmutil.intrev(ctx) - len(repo) + return rev - len(repo) @templatekeyword('node', requires={'ctx'}) def shownode(context, mapping):