Submitter | Katsunori FUJIWARA |
---|---|
Date | Jan. 5, 2016, 11:48 a.m. |
Message ID | <604903e68756b80dd147.1451994517@feefifofum> |
Download | mbox | patch |
Permalink | /patch/12529/ |
State | Changes Requested |
Delegated to: | Yuya Nishihara |
Headers | show |
Comments
On Tue, 05 Jan 2016 20:48:37 +0900, FUJIWARA Katsunori wrote: > # HG changeset patch > # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp> > # Date 1451994204 -32400 > # Tue Jan 05 20:43:24 2016 +0900 > # Node ID 604903e68756b80dd147f37cc642c019b8d5e50b > # Parent c6554052f10db3a9312b17c658bf8c579198a5d2 > revset: replace revset.extpredicate by registrar.revsetpredicate > diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py > --- a/mercurial/dispatch.py > +++ b/mercurial/dispatch.py > @@ -33,6 +33,7 @@ from . import ( > fancyopts, > hg, > hook, > + revset, > ui as uimod, > util, > ) > @@ -765,6 +766,7 @@ def _loadcmdtable(ui, name, cmdtable): > # obj) arguments > extraloaders = [ > ('cmdtable', None, None), # this is just a place holder for 'cmdtable' > + ('revsetpredicate', revset, 'loadpredicate'), > ] > > def _dispatch(req): > diff --git a/mercurial/registrar.py b/mercurial/registrar.py > --- a/mercurial/registrar.py > +++ b/mercurial/registrar.py > @@ -229,6 +229,12 @@ class revsetpredicate(funcregistrarbase) > > 'revsetpredicate' instance in example above can be used to > decorate multiple functions. > + > + Decorated functions are registered automatically at loading > + extension, if an instance named as 'revsetpredicate' is used for > + decorating in extension. > + > + Otherwise, explicit 'revset.loadpredicate()' is needed. > """ I think these changes will better fit to the patch 3. The patch 3 implements core function, and the patch 4 uses it. > $ cat <<EOF > $TESTTMP/custompredicate.py > - > from mercurial import revset > + > from mercurial import 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() > + > syntax error for intentional failure of loading this module Uh, the code won't be run at all on parsing failure. You can use "raise Exception" instead.
At Fri, 8 Jan 2016 00:19:25 +0900, Yuya Nishihara wrote: > > On Tue, 05 Jan 2016 20:48:37 +0900, FUJIWARA Katsunori wrote: > > # HG changeset patch > > # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp> > > # Date 1451994204 -32400 > > # Tue Jan 05 20:43:24 2016 +0900 > > # Node ID 604903e68756b80dd147f37cc642c019b8d5e50b > > # Parent c6554052f10db3a9312b17c658bf8c579198a5d2 > > revset: replace revset.extpredicate by registrar.revsetpredicate > > > diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py > > --- a/mercurial/dispatch.py > > +++ b/mercurial/dispatch.py > > @@ -33,6 +33,7 @@ from . import ( > > fancyopts, > > hg, > > hook, > > + revset, > > ui as uimod, > > util, > > ) > > @@ -765,6 +766,7 @@ def _loadcmdtable(ui, name, cmdtable): > > # obj) arguments > > extraloaders = [ > > ('cmdtable', None, None), # this is just a place holder for 'cmdtable' > > + ('revsetpredicate', revset, 'loadpredicate'), > > ] > > > > def _dispatch(req): > > diff --git a/mercurial/registrar.py b/mercurial/registrar.py > > --- a/mercurial/registrar.py > > +++ b/mercurial/registrar.py > > @@ -229,6 +229,12 @@ class revsetpredicate(funcregistrarbase) > > > > 'revsetpredicate' instance in example above can be used to > > decorate multiple functions. > > + > > + Decorated functions are registered automatically at loading > > + extension, if an instance named as 'revsetpredicate' is used for > > + decorating in extension. > > + > > + Otherwise, explicit 'revset.loadpredicate()' is needed. > > """ > > I think these changes will better fit to the patch 3. The patch 3 implements > core function, and the patch 4 uses it. I put this change into patch #4, because automatic loading itself isn't yet implemented at patch #3. But I don't have strong opinion to do so, and I'll put it into patch #3. > > $ cat <<EOF > $TESTTMP/custompredicate.py > > - > from mercurial import revset > > + > from mercurial import 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() > > + > syntax error for intentional failure of loading this module > > Uh, the code won't be run at all on parsing failure. You can use > "raise Exception" instead. I'll do so in revised series. ---------------------------------------------------------------------- [FUJIWARA Katsunori] foozy@lares.dti.ne.jp
Patch
diff --git a/hgext/largefiles/__init__.py b/hgext/largefiles/__init__.py --- a/hgext/largefiles/__init__.py +++ b/hgext/largefiles/__init__.py @@ -111,6 +111,7 @@ import lfcommands 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 @@ def uisetup(ui): uisetupmod.uisetup(ui) cmdtable = lfcommands.cmdtable +revsetpredicate = overrides.revsetpredicate diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py --- a/hgext/largefiles/overrides.py +++ b/hgext/largefiles/overrides.py @@ -12,7 +12,7 @@ import os 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 @@ -812,7 +812,7 @@ def overridepull(orig, ui, repo, source= ui.status(_("%d largefiles cached\n") % numcached) return result -revsetpredicate = revset.extpredicate() +revsetpredicate = registrar.revsetpredicate() @revsetpredicate('pulled()') def pulledrevsetsymbol(repo, subset, x): diff --git a/hgext/largefiles/uisetup.py b/hgext/largefiles/uisetup.py --- a/hgext/largefiles/uisetup.py +++ b/hgext/largefiles/uisetup.py @@ -169,5 +169,3 @@ def uisetup(ui): if name == 'transplant': extensions.wrapcommand(getattr(module, 'cmdtable'), 'transplant', overrides.overridetransplant) - - overrides.revsetpredicate.setup() diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -71,6 +71,7 @@ from mercurial import patch as patchmod from mercurial import lock as lockmod from mercurial import localrepo from mercurial import subrepo +from mercurial import registrar import os, re, errno, shutil seriesopts = [('s', 'summary', None, _('print first line of patch header'))] @@ -3558,7 +3559,7 @@ def summaryhook(ui, repo): # 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): @@ -3598,8 +3599,6 @@ def extsetup(ui): if extmodule.__file__ != __file__: dotable(getattr(extmodule, 'cmdtable', {})) - revsetpredicate.setup() - colortable = {'qguard.negative': 'red', 'qguard.positive': 'yellow', 'qguard.unguarded': 'green', diff --git a/hgext/rebase.py b/hgext/rebase.py --- a/hgext/rebase.py +++ b/hgext/rebase.py @@ -16,7 +16,7 @@ https://mercurial-scm.org/wiki/RebaseExt from mercurial import hg, util, repair, merge, cmdutil, commands, bookmarks from mercurial import extensions, patch, scmutil, phases, obsolete, error -from mercurial import copies, repoview, revset +from mercurial import copies, repoview, registrar, revset from mercurial.commands import templateopts from mercurial.node import nullrev, nullid, hex, short from mercurial.lock import release @@ -64,7 +64,7 @@ def _destrebase(repo): branch = repo[None].branch() return repo[branch].rev() -revsetpredicate = revset.extpredicate() +revsetpredicate = registrar.revsetpredicate() @revsetpredicate('_destrebase') def _revsetdestrebase(repo, subset, x): @@ -1241,4 +1241,3 @@ def uisetup(ui): _("use 'hg rebase --continue' or 'hg rebase --abort'")]) # ensure rebased rev are not hidden extensions.wrapfunction(repoview, '_getdynamicblockers', _rebasedvisible) - revsetpredicate.setup() diff --git a/hgext/transplant.py b/hgext/transplant.py --- a/hgext/transplant.py +++ b/hgext/transplant.py @@ -19,7 +19,7 @@ import os, tempfile 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 from mercurial import lock as lockmod class TransplantError(error.Abort): @@ -693,7 +693,7 @@ def _dotransplant(ui, repo, *revs, **opt if cleanupfn: cleanupfn() -revsetpredicate = revset.extpredicate() +revsetpredicate = registrar.revsetpredicate() @revsetpredicate('transplanted([set])') def revsettransplanted(repo, subset, x): @@ -713,7 +713,6 @@ def kwtransplanted(repo, ctx, **args): return n and revlog.hex(n) or '' def extsetup(ui): - revsetpredicate.setup() templatekw.keywords['transplanted'] = kwtransplanted cmdutil.unfinishedstates.append( ['series', True, False, _('transplant in progress'), diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -33,6 +33,7 @@ from . import ( fancyopts, hg, hook, + revset, ui as uimod, util, ) @@ -765,6 +766,7 @@ def _loadcmdtable(ui, name, cmdtable): # obj) arguments extraloaders = [ ('cmdtable', None, None), # this is just a place holder for 'cmdtable' + ('revsetpredicate', revset, 'loadpredicate'), ] def _dispatch(req): diff --git a/mercurial/registrar.py b/mercurial/registrar.py --- a/mercurial/registrar.py +++ b/mercurial/registrar.py @@ -229,6 +229,12 @@ class revsetpredicate(funcregistrarbase) 'revsetpredicate' instance in example above can be used to decorate multiple functions. + + Decorated functions are registered automatically at loading + extension, if an instance named as 'revsetpredicate' is used for + decorating in extension. + + Otherwise, explicit 'revset.loadpredicate()' is needed. """ getname = funcregistrarbase.parsefuncdecl formatdoc = "``%s``\n %s" diff --git a/tests/test-revset.t b/tests/test-revset.t --- a/tests/test-revset.t +++ b/tests/test-revset.t @@ -2190,28 +2190,21 @@ test error message of bad revset $ 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 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() + > syntax error for intentional failure of loading this module > EOF $ cat <<EOF > .hg/hgrc > [extensions] @@ -2219,13 +2212,8 @@ Test registrar.delayregistrar via revset > EOF $ hg debugrevspec "custom1()" + *** failed to import extension custompredicate from $TESTTMP/custompredicate.py: invalid syntax (custompredicate.py, line 9) 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 ..