Browse Source

compat: update how we register gitnode template keyword

master
Kevin Bullock 3 years ago
parent
commit
2560e7e504
2 changed files with 37 additions and 6 deletions
  1. +25
    -6
      hggit/__init__.py
  2. +12
    -0
      hggit/compat.py

+ 25
- 6
hggit/__init__.py View File

@ -94,9 +94,11 @@ try:
command = registrar.command(cmdtable)
configitem = registrar.configitem(configtable)
compat.registerconfigs(configitem)
templatekeyword = registrar.templatekeyword()
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 @@ extensions.wrapfunction(hg, 'addbranchrevs', safebranchrevs)
def extsetup(ui):
templatekw.keywords.update({'gitnode': gitnodekw})
revset.symbols.update({
'fromgit': revset_fromgit, 'gitnode': revset_gitnode
})
@ -455,12 +456,30 @@ def revset_gitnode(repo, subset, x):
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
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)

+ 12
- 0
hggit/compat.py View File

@ -2,6 +2,7 @@ from mercurial import (
bookmarks,
context,
phases,
templatekw,
url,
util as hgutil,
)
@ -192,3 +193,14 @@ def config(ui, subtype, section, item):
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

Loading…
Cancel
Save