# HG changeset patch # User Augie Fackler # Date 2018-02-02 15:51:47 # Node ID ea02be8665ef7f85e30e1a8131765760cf4e700a # Parent 9445a31415019914b3c997282353c4cd5ae99f85 narrowtemplates: update to use registrar mechanism It's worth considering at this point if we should just move the two ellipsis functions to core tagged experimental or something, since they're not really narrowing-specific... Differential Revision: https://phab.mercurial-scm.org/D2009 diff --git a/hgext/narrow/__init__.py b/hgext/narrow/__init__.py --- a/hgext/narrow/__init__.py +++ b/hgext/narrow/__init__.py @@ -62,7 +62,6 @@ def uisetup(ui): narrowrevlog.setup() narrowbundle2.setup() narrowmerge.setup() - narrowtemplates.setup() narrowcommands.setup() narrowchangegroup.setup() narrowwirepeer.uisetup() @@ -91,3 +90,6 @@ def extsetup(ui): extensions.wrapfunction(verifymod.verifier, '__init__', _verifierinit) extensions.wrapfunction(hg, 'postshare', narrowrepo.wrappostshare) extensions.wrapfunction(hg, 'copystore', narrowrepo.unsharenarrowspec) + +templatekeyword = narrowtemplates.templatekeyword +revsetpredicate = narrowtemplates.revsetpredicate diff --git a/hgext/narrow/narrowtemplates.py b/hgext/narrow/narrowtemplates.py --- a/hgext/narrow/narrowtemplates.py +++ b/hgext/narrow/narrowtemplates.py @@ -8,17 +8,21 @@ from __future__ import absolute_import from mercurial import ( + registrar, revlog, - revset, - templatekw, util, ) +keywords = {} +templatekeyword = registrar.templatekeyword(keywords) +revsetpredicate = registrar.revsetpredicate() + def _isellipsis(repo, rev): if repo.changelog.flags(rev) & revlog.REVIDX_ELLIPSIS: return True return False +@templatekeyword('ellipsis') def ellipsis(repo, ctx, templ, **args): """:ellipsis: String. 'ellipsis' if the change is an ellipsis node, else ''.""" @@ -26,6 +30,7 @@ def ellipsis(repo, ctx, templ, **args): return 'ellipsis' return '' +@templatekeyword('outsidenarrow') def outsidenarrow(repo, ctx, templ, **args): """:outsidenarrow: String. 'outsidenarrow' if the change affects no tracked files, else ''.""" @@ -35,15 +40,9 @@ def outsidenarrow(repo, ctx, templ, **ar return 'outsidenarrow' return '' +@revsetpredicate('ellipsis') def ellipsisrevset(repo, subset, x): """``ellipsis()`` Changesets that are ellipsis nodes. """ return subset.filter(lambda r: _isellipsis(repo, r)) - -def setup(): - templatekw.keywords['ellipsis'] = ellipsis - templatekw.keywords['outsidenarrow'] = outsidenarrow - - revset.symbols['ellipsis'] = ellipsisrevset - revset.safesymbols.add('ellipsis')