# HG changeset patch # User Augie Fackler # Date 1541215459 14400 # Node ID 39e2f8f8f20576c97ef1d455bd70b1b7fe5b537f # Parent 40d8557d6aee5051238d820f97e4a4a4590e9c7b templatekw: make portable to hg48 diff --git a/hgsubversion/__init__.py b/hgsubversion/__init__.py --- a/hgsubversion/__init__.py +++ b/hgsubversion/__init__.py @@ -17,6 +17,7 @@ For more information and instructions, s testedwith = '3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8' +import inspect import os from mercurial import commands @@ -360,19 +361,41 @@ def _templatehelper(ctx, kw): else: raise hgerror.Abort('unrecognized hgsubversion keyword %s' % kw) -@templatekeyword('svnrev') -def svnrevkw(**args): - """:svnrev: String. Converted subversion revision number.""" - return _templatehelper(args['ctx'], 'svnrev') - -@templatekeyword('svnpath') -def svnpathkw(**args): - """:svnpath: String. Converted subversion revision project path.""" - return _templatehelper(args['ctx'], 'svnpath') - -@templatekeyword('svnuuid') -def svnuuidkw(**args): - """:svnuuid: String. Converted subversion revision repository identifier.""" - return _templatehelper(args['ctx'], 'svnuuid') +_ishg48 = 'requires' in inspect.getargspec( + getattr(templatekeyword, '_extrasetup', lambda: None)).args + +if _ishg48: + @templatekeyword('svnrev', requires={'ctx'}) + def svnrevkw(context, mapping): + """:svnrev: String. Converted subversion revision number.""" + ctx = context.resource(mapping, 'ctx') + return _templatehelper(ctx, 'svnrev') + + @templatekeyword('svnpath', requires={'ctx'}) + def svnpathkw(context, mapping): + """:svnpath: String. Converted subversion revision project path.""" + ctx = context.resource(mapping, 'ctx') + return _templatehelper(ctx, 'svnpath') + + @templatekeyword('svnuuid', requires={'ctx'}) + def svnuuidkw(context, mapping): + """:svnuuid: String. Converted subversion revision repository identifier.""" + ctx = context.resource(mapping, 'ctx') + return _templatehelper(ctx, 'svnuuid') +else: + @templatekeyword('svnrev') + def svnrevkw(**args): + """:svnrev: String. Converted subversion revision number.""" + return _templatehelper(args['ctx'], 'svnrev') + + @templatekeyword('svnpath') + def svnpathkw(**args): + """:svnpath: String. Converted subversion revision project path.""" + return _templatehelper(args['ctx'], 'svnpath') + + @templatekeyword('svnuuid') + def svnuuidkw(**args): + """:svnuuid: String. Converted subversion revision repository identifier.""" + return _templatehelper(args['ctx'], 'svnuuid') loadkeyword(templatekeyword)