diff --git a/hggit/__init__.py b/hggit/__init__.py index 143b7511eadbea7507d847c805241a6db290ffe7_aGdnaXQvX19pbml0X18ucHk=..8d00fde45adbc6c3c0ccab8e362b5f5c36c171e6_aGdnaXQvX19pbml0X18ucHk= 100644 --- a/hggit/__init__.py +++ b/hggit/__init__.py @@ -94,6 +94,7 @@ command = registrar.command(cmdtable) configitem = registrar.configitem(configtable) compat.registerconfigs(configitem) + templatekeyword = registrar.templatekeyword() except (ImportError, AttributeError): command = cmdutil.command(cmdtable) @@ -97,6 +98,7 @@ except (ImportError, AttributeError): command = cmdutil.command(cmdtable) + templatekeyword = compat.templatekeyword() # support for `hg clone git://github.com/defunkt/facebox.git` # also hg clone git+ssh://git@github.com/schacon/simplegit.git @@ -207,7 +209,6 @@ def extsetup(ui): - templatekw.keywords.update({'gitnode': gitnodekw}) revset.symbols.update({ 'fromgit': revset_fromgit, 'gitnode': revset_gitnode }) @@ -455,12 +456,8 @@ raise LookupError(rev, git.map_file, _('ambiguous identifier')) -def gitnodekw(**args): - """:gitnode: String. The Git changeset identification hash, as a 40 hexadecimal -digit string.""" - node = args['ctx'] - repo = args['repo'] +def _gitnodekw(node, repo): gitnode = repo.githandler.map_git_get(node.hex()) if gitnode is None: gitnode = '' return gitnode @@ -463,4 +460,26 @@ gitnode = repo.githandler.map_git_get(node.hex()) if gitnode is None: gitnode = '' return gitnode + + +if (hgutil.safehasattr(templatekw, 'templatekeyword') and + hgutil.safehasattr(templatekw.templatekeyword._table['node'], + '_requires')): + @templatekeyword('gitnode', requires={'ctx', 'repo'}) + def gitnodekw(context, mapping): + """:gitnode: String. The Git changeset identification hash, as a + 40 hexadecimal digit string.""" + node = context.resource(mapping, 'ctx') + repo = context.resource(mapping, 'repo') + return _gitnodekw(node, repo) + +else: + # COMPAT: hg < 4.6 - templatekeyword API changed + @templatekeyword('gitnode') + def gitnodekw(**args): + """:gitnode: String. The Git changeset identification hash, as a + 40 hexadecimal digit string.""" + node = args['ctx'] + repo = args['repo'] + return _gitnodekw(node, repo) diff --git a/hggit/compat.py b/hggit/compat.py index 143b7511eadbea7507d847c805241a6db290ffe7_aGdnaXQvY29tcGF0LnB5..8d00fde45adbc6c3c0ccab8e362b5f5c36c171e6_aGdnaXQvY29tcGF0LnB5 100644 --- a/hggit/compat.py +++ b/hggit/compat.py @@ -2,6 +2,7 @@ bookmarks, context, phases, + templatekw, url, util as hgutil, ) @@ -192,3 +193,14 @@ if hasconfigitems: return getconfig(section, item) return getconfig(section, item, CONFIG_DEFAULTS[section][item]) + + +class templatekeyword(object): + def __init__(self): + self._table = {} + + def __call__(self, name): + def decorate(func): + templatekw.keywords.update({name: func}) + return func + return decorate