Mercurial > hg-stable
changeset 28394:dcb4209bd30d
revset: replace extpredicate by revsetpredicate of registrar
This patch consists of changes below (these can't be applied
separately).
- replace revset.extpredicate by registrar.revsetpredicate in
extensions
- remove setup() on an instance named as revsetpredicate in
uisetup()/extsetup() of each extensions
registrar.revsetpredicate doesn't have setup() API.
- put new entry for revsetpredicate into extraloaders in dispatch
This causes implicit loading predicate functions at loading
extension.
This loading mechanism requires that an extension has an instance
named as revsetpredicate, and this is reason why
largefiles/__init__.py is also changed in this patch.
Before this patch, test-revset.t tests that all decorated revset
predicates are loaded by explicit setup() at once ("all or nothing").
Now, test-revset.t tests that any revset predicate isn't loaded at
failure of loading extension, because loading itself is executed by
dispatch and it can't be controlled on extension side.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Tue, 08 Mar 2016 23:04:53 +0900 |
parents | ac11ba7c2e56 |
children | 0383f7a5e86c |
files | hgext/largefiles/__init__.py hgext/largefiles/overrides.py hgext/largefiles/uisetup.py hgext/mq.py hgext/rebase.py hgext/transplant.py mercurial/dispatch.py tests/test-revset.t |
diffstat | 8 files changed, 18 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/largefiles/__init__.py Tue Mar 08 23:04:53 2016 +0900 +++ b/hgext/largefiles/__init__.py Tue Mar 08 23:04:53 2016 +0900 @@ -111,6 +111,7 @@ import proto import reposetup import uisetup as uisetupmod +import overrides # Note for extension authors: ONLY specify testedwith = 'internal' for # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should @@ -130,3 +131,4 @@ uisetupmod.uisetup(ui) cmdtable = lfcommands.cmdtable +revsetpredicate = overrides.revsetpredicate
--- a/hgext/largefiles/overrides.py Tue Mar 08 23:04:53 2016 +0900 +++ b/hgext/largefiles/overrides.py Tue Mar 08 23:04:53 2016 +0900 @@ -12,7 +12,7 @@ import copy from mercurial import hg, util, cmdutil, scmutil, match as match_, \ - archival, pathutil, revset, error + archival, pathutil, registrar, revset, error from mercurial.i18n import _ import lfutil @@ -801,7 +801,7 @@ ui.status(_("%d largefiles cached\n") % numcached) return result -revsetpredicate = revset.extpredicate() +revsetpredicate = registrar.revsetpredicate() @revsetpredicate('pulled()') def pulledrevsetsymbol(repo, subset, x):
--- a/hgext/largefiles/uisetup.py Tue Mar 08 23:04:53 2016 +0900 +++ b/hgext/largefiles/uisetup.py Tue Mar 08 23:04:53 2016 +0900 @@ -171,5 +171,3 @@ if name == 'transplant': extensions.wrapcommand(getattr(module, 'cmdtable'), 'transplant', overrides.overridetransplant) - - overrides.revsetpredicate.setup()
--- a/hgext/mq.py Tue Mar 08 23:04:53 2016 +0900 +++ b/hgext/mq.py Tue Mar 08 23:04:53 2016 +0900 @@ -70,6 +70,7 @@ from mercurial import patch as patchmod from mercurial import lock as lockmod from mercurial import localrepo +from mercurial import registrar from mercurial import subrepo import os, re, errno, shutil @@ -3536,7 +3537,7 @@ # i18n: column positioning for "hg summary" ui.note(_("mq: (empty queue)\n")) -revsetpredicate = revset.extpredicate() +revsetpredicate = registrar.revsetpredicate() @revsetpredicate('mq()') def revsetmq(repo, subset, x): @@ -3575,8 +3576,6 @@ if extmodule.__file__ != __file__: dotable(getattr(extmodule, 'cmdtable', {})) - revsetpredicate.setup() - colortable = {'qguard.negative': 'red', 'qguard.positive': 'yellow', 'qguard.unguarded': 'green',
--- a/hgext/rebase.py Tue Mar 08 23:04:53 2016 +0900 +++ b/hgext/rebase.py Tue Mar 08 23:04:53 2016 +0900 @@ -16,7 +16,7 @@ from mercurial import hg, util, repair, merge, cmdutil, commands, bookmarks from mercurial import extensions, patch, scmutil, phases, obsolete, error -from mercurial import copies, destutil, repoview, revset +from mercurial import copies, destutil, repoview, registrar, revset from mercurial.commands import templateopts from mercurial.node import nullrev, nullid, hex, short from mercurial.lock import release @@ -76,7 +76,7 @@ return destutil.destmerge(repo, action='rebase', sourceset=sourceset, onheadcheck=False) -revsetpredicate = revset.extpredicate() +revsetpredicate = registrar.revsetpredicate() @revsetpredicate('_destrebase') def _revsetdestrebase(repo, subset, x): @@ -1325,4 +1325,3 @@ ['rebasestate', _('hg rebase --continue')]) # ensure rebased rev are not hidden extensions.wrapfunction(repoview, '_getdynamicblockers', _rebasedvisible) - revsetpredicate.setup()
--- a/hgext/transplant.py Tue Mar 08 23:04:53 2016 +0900 +++ b/hgext/transplant.py Tue Mar 08 23:04:53 2016 +0900 @@ -19,7 +19,7 @@ from mercurial.node import short from mercurial import bundlerepo, hg, merge, match from mercurial import patch, revlog, scmutil, util, error, cmdutil -from mercurial import revset, templatekw, exchange +from mercurial import registrar, revset, templatekw, exchange class TransplantError(error.Abort): pass @@ -694,7 +694,7 @@ if cleanupfn: cleanupfn() -revsetpredicate = revset.extpredicate() +revsetpredicate = registrar.revsetpredicate() @revsetpredicate('transplanted([set])') def revsettransplanted(repo, subset, x): @@ -714,7 +714,6 @@ return n and revlog.hex(n) or '' def extsetup(ui): - revsetpredicate.setup() templatekw.keywords['transplanted'] = kwtransplanted cmdutil.unfinishedstates.append( ['transplant/journal', True, False, _('transplant in progress'),
--- a/mercurial/dispatch.py Tue Mar 08 23:04:53 2016 +0900 +++ b/mercurial/dispatch.py Tue Mar 08 23:04:53 2016 +0900 @@ -33,6 +33,7 @@ fancyopts, hg, hook, + revset, ui as uimod, util, ) @@ -752,6 +753,7 @@ # extraobj) arguments extraloaders = [ ('cmdtable', commands, 'loadcmdtable'), + ('revsetpredicate', revset, 'loadpredicate'), ] def _dispatch(req):
--- a/tests/test-revset.t Tue Mar 08 23:04:53 2016 +0900 +++ b/tests/test-revset.t Tue Mar 08 23:04:53 2016 +0900 @@ -2191,28 +2191,21 @@ $ cd .. -Test registrar.delayregistrar via revset.extpredicate - -'extpredicate' decorator shouldn't register any functions until -'setup()' on it. +Test that revset predicate of extension isn't loaded at failure of +loading it $ cd repo $ cat <<EOF > $TESTTMP/custompredicate.py - > from mercurial import revset + > from mercurial import error, registrar, revset > - > revsetpredicate = revset.extpredicate() + > revsetpredicate = registrar.revsetpredicate() > > @revsetpredicate('custom1()') > def custom1(repo, subset, x): > return revset.baseset([1]) - > @revsetpredicate('custom2()') - > def custom2(repo, subset, x): - > return revset.baseset([2]) > - > def uisetup(ui): - > if ui.configbool('custompredicate', 'enabled'): - > revsetpredicate.setup() + > raise error.Abort('intentional failure of loading extension') > EOF $ cat <<EOF > .hg/hgrc > [extensions] @@ -2220,13 +2213,8 @@ > EOF $ hg debugrevspec "custom1()" + *** failed to import extension custompredicate from $TESTTMP/custompredicate.py: intentional failure of loading extension hg: parse error: unknown identifier: custom1 [255] - $ hg debugrevspec "custom2()" - hg: parse error: unknown identifier: custom2 - [255] - $ hg debugrevspec "custom1() or custom2()" --config custompredicate.enabled=true - 1 - 2 $ cd ..