2018-06-15 04:40:53 +03:00
|
|
|
#require no-fsmonitor
|
|
|
|
|
2010-09-03 13:19:50 +04:00
|
|
|
Test basic extension support
|
|
|
|
|
|
|
|
$ cat > foobar.py <<EOF
|
|
|
|
> import os
|
2016-01-09 17:07:20 +03:00
|
|
|
> from mercurial import commands, registrar
|
2014-05-05 09:48:07 +04:00
|
|
|
> cmdtable = {}
|
2016-01-09 17:07:20 +03:00
|
|
|
> command = registrar.command(cmdtable)
|
2017-06-17 14:48:20 +03:00
|
|
|
> configtable = {}
|
|
|
|
> configitem = registrar.configitem(configtable)
|
|
|
|
> configitem('tests', 'foo', default="Foo")
|
2010-09-03 13:19:50 +04:00
|
|
|
> def uisetup(ui):
|
|
|
|
> ui.write("uisetup called\\n")
|
2016-03-15 12:51:42 +03:00
|
|
|
> ui.flush()
|
2010-09-03 13:19:50 +04:00
|
|
|
> def reposetup(ui, repo):
|
|
|
|
> ui.write("reposetup called for %s\\n" % os.path.basename(repo.root))
|
|
|
|
> ui.write("ui %s= repo.ui\\n" % (ui == repo.ui and "=" or "!"))
|
2016-03-15 12:51:42 +03:00
|
|
|
> ui.flush()
|
2017-06-25 05:50:05 +03:00
|
|
|
> @command(b'foo', [], 'hg foo')
|
2010-09-03 13:19:50 +04:00
|
|
|
> def foo(ui, *args, **kwargs):
|
2017-06-17 14:48:20 +03:00
|
|
|
> foo = ui.config('tests', 'foo')
|
|
|
|
> ui.write(foo)
|
|
|
|
> ui.write("\\n")
|
2017-06-25 05:50:05 +03:00
|
|
|
> @command(b'bar', [], 'hg bar', norepo=True)
|
2010-09-03 13:19:50 +04:00
|
|
|
> def bar(ui, *args, **kwargs):
|
|
|
|
> ui.write("Bar\\n")
|
|
|
|
> EOF
|
|
|
|
$ abspath=`pwd`/foobar.py
|
|
|
|
|
|
|
|
$ mkdir barfoo
|
|
|
|
$ cp foobar.py barfoo/__init__.py
|
|
|
|
$ barfoopath=`pwd`/barfoo
|
|
|
|
|
|
|
|
$ hg init a
|
|
|
|
$ cd a
|
|
|
|
$ echo foo > file
|
|
|
|
$ hg add file
|
|
|
|
$ hg commit -m 'add file'
|
|
|
|
|
|
|
|
$ echo '[extensions]' >> $HGRCPATH
|
|
|
|
$ echo "foobar = $abspath" >> $HGRCPATH
|
|
|
|
$ hg foo
|
|
|
|
uisetup called
|
|
|
|
reposetup called for a
|
|
|
|
ui == repo.ui
|
2017-10-17 21:07:18 +03:00
|
|
|
reposetup called for a (chg !)
|
|
|
|
ui == repo.ui (chg !)
|
2010-09-03 13:19:50 +04:00
|
|
|
Foo
|
|
|
|
|
|
|
|
$ cd ..
|
|
|
|
$ hg clone a b
|
2017-10-17 21:07:18 +03:00
|
|
|
uisetup called (no-chg !)
|
2010-09-03 13:19:50 +04:00
|
|
|
reposetup called for a
|
|
|
|
ui == repo.ui
|
|
|
|
reposetup called for b
|
|
|
|
ui == repo.ui
|
|
|
|
updating to branch default
|
|
|
|
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
|
|
|
|
|
|
|
|
$ hg bar
|
2017-10-17 21:07:18 +03:00
|
|
|
uisetup called (no-chg !)
|
2010-09-03 13:19:50 +04:00
|
|
|
Bar
|
|
|
|
$ echo 'foobar = !' >> $HGRCPATH
|
|
|
|
|
|
|
|
module/__init__.py-style
|
|
|
|
|
|
|
|
$ echo "barfoo = $barfoopath" >> $HGRCPATH
|
|
|
|
$ cd a
|
|
|
|
$ hg foo
|
|
|
|
uisetup called
|
|
|
|
reposetup called for a
|
|
|
|
ui == repo.ui
|
2017-10-17 21:07:18 +03:00
|
|
|
reposetup called for a (chg !)
|
|
|
|
ui == repo.ui (chg !)
|
2010-09-03 13:19:50 +04:00
|
|
|
Foo
|
|
|
|
$ echo 'barfoo = !' >> $HGRCPATH
|
|
|
|
|
|
|
|
Check that extensions are loaded in phases:
|
|
|
|
|
|
|
|
$ cat > foo.py <<EOF
|
|
|
|
> import os
|
|
|
|
> name = os.path.basename(__file__).rsplit('.', 1)[0]
|
2017-06-15 21:22:25 +03:00
|
|
|
> print("1) %s imported" % name)
|
2010-09-03 13:19:50 +04:00
|
|
|
> def uisetup(ui):
|
2017-06-15 21:22:25 +03:00
|
|
|
> print("2) %s uisetup" % name)
|
2010-09-03 13:19:50 +04:00
|
|
|
> def extsetup():
|
2017-06-15 21:22:25 +03:00
|
|
|
> print("3) %s extsetup" % name)
|
2010-09-03 13:19:50 +04:00
|
|
|
> def reposetup(ui, repo):
|
2017-06-15 21:22:25 +03:00
|
|
|
> print("4) %s reposetup" % name)
|
extensions: register functions always at loading extension (issue5601)
Before this patch, functions defined in extensions are registered via
extra loaders only in _dispatch(). Therefore, loading extensions in
other code paths like below omits registration of functions.
- WSGI service
- operation across repositories (e.g. subrepo)
- test-duplicateoptions.py, using extensions.loadall() directly
To register functions always at loading new extension, this patch
moves implementation for extra loading from dispatch._dispatch() to
extensions.loadall().
AFAIK, only commands module causes cyclic dependency between
extensions module, but this patch imports all related modules just
before extra loading in loadall(), in order to centralize them.
This patch makes extensions.py depend on many other modules, even
though extensions.py itself doesn't. It should be avoided if possible,
but I don't have any better idea. Some other places like below aren't
reasonable for extra loading, IMHO.
- specific function in newly added module:
existing callers of extensions.loadall() should invoke it, too
- hg.repository() or so:
no-repo commands aren't covered by this.
BTW, this patch removes _loaded.add(name) on relocation, because
dispatch._loaded is used only for extraloaders (for similar reason,
"exts" variable is removed, too).
2017-06-23 20:39:20 +03:00
|
|
|
>
|
|
|
|
> # custom predicate to check registration of functions at loading
|
|
|
|
> from mercurial import (
|
|
|
|
> registrar,
|
|
|
|
> smartset,
|
|
|
|
> )
|
|
|
|
> revsetpredicate = registrar.revsetpredicate()
|
|
|
|
> @revsetpredicate(name, safe=True) # safe=True for query via hgweb
|
|
|
|
> def custompredicate(repo, subset, x):
|
|
|
|
> return smartset.baseset([r for r in subset if r in {0}])
|
2010-09-03 13:19:50 +04:00
|
|
|
> EOF
|
|
|
|
|
|
|
|
$ cp foo.py bar.py
|
|
|
|
$ echo 'foo = foo.py' >> $HGRCPATH
|
|
|
|
$ echo 'bar = bar.py' >> $HGRCPATH
|
|
|
|
|
extensions: register functions always at loading extension (issue5601)
Before this patch, functions defined in extensions are registered via
extra loaders only in _dispatch(). Therefore, loading extensions in
other code paths like below omits registration of functions.
- WSGI service
- operation across repositories (e.g. subrepo)
- test-duplicateoptions.py, using extensions.loadall() directly
To register functions always at loading new extension, this patch
moves implementation for extra loading from dispatch._dispatch() to
extensions.loadall().
AFAIK, only commands module causes cyclic dependency between
extensions module, but this patch imports all related modules just
before extra loading in loadall(), in order to centralize them.
This patch makes extensions.py depend on many other modules, even
though extensions.py itself doesn't. It should be avoided if possible,
but I don't have any better idea. Some other places like below aren't
reasonable for extra loading, IMHO.
- specific function in newly added module:
existing callers of extensions.loadall() should invoke it, too
- hg.repository() or so:
no-repo commands aren't covered by this.
BTW, this patch removes _loaded.add(name) on relocation, because
dispatch._loaded is used only for extraloaders (for similar reason,
"exts" variable is removed, too).
2017-06-23 20:39:20 +03:00
|
|
|
Check normal command's load order of extensions and registration of functions
|
2010-09-03 13:19:50 +04:00
|
|
|
|
extensions: register functions always at loading extension (issue5601)
Before this patch, functions defined in extensions are registered via
extra loaders only in _dispatch(). Therefore, loading extensions in
other code paths like below omits registration of functions.
- WSGI service
- operation across repositories (e.g. subrepo)
- test-duplicateoptions.py, using extensions.loadall() directly
To register functions always at loading new extension, this patch
moves implementation for extra loading from dispatch._dispatch() to
extensions.loadall().
AFAIK, only commands module causes cyclic dependency between
extensions module, but this patch imports all related modules just
before extra loading in loadall(), in order to centralize them.
This patch makes extensions.py depend on many other modules, even
though extensions.py itself doesn't. It should be avoided if possible,
but I don't have any better idea. Some other places like below aren't
reasonable for extra loading, IMHO.
- specific function in newly added module:
existing callers of extensions.loadall() should invoke it, too
- hg.repository() or so:
no-repo commands aren't covered by this.
BTW, this patch removes _loaded.add(name) on relocation, because
dispatch._loaded is used only for extraloaders (for similar reason,
"exts" variable is removed, too).
2017-06-23 20:39:20 +03:00
|
|
|
$ hg log -r "foo() and bar()" -q
|
2010-09-03 13:19:50 +04:00
|
|
|
1) foo imported
|
|
|
|
1) bar imported
|
|
|
|
2) foo uisetup
|
|
|
|
2) bar uisetup
|
|
|
|
3) foo extsetup
|
|
|
|
3) bar extsetup
|
|
|
|
4) foo reposetup
|
|
|
|
4) bar reposetup
|
extensions: register functions always at loading extension (issue5601)
Before this patch, functions defined in extensions are registered via
extra loaders only in _dispatch(). Therefore, loading extensions in
other code paths like below omits registration of functions.
- WSGI service
- operation across repositories (e.g. subrepo)
- test-duplicateoptions.py, using extensions.loadall() directly
To register functions always at loading new extension, this patch
moves implementation for extra loading from dispatch._dispatch() to
extensions.loadall().
AFAIK, only commands module causes cyclic dependency between
extensions module, but this patch imports all related modules just
before extra loading in loadall(), in order to centralize them.
This patch makes extensions.py depend on many other modules, even
though extensions.py itself doesn't. It should be avoided if possible,
but I don't have any better idea. Some other places like below aren't
reasonable for extra loading, IMHO.
- specific function in newly added module:
existing callers of extensions.loadall() should invoke it, too
- hg.repository() or so:
no-repo commands aren't covered by this.
BTW, this patch removes _loaded.add(name) on relocation, because
dispatch._loaded is used only for extraloaders (for similar reason,
"exts" variable is removed, too).
2017-06-23 20:39:20 +03:00
|
|
|
0:c24b9ac61126
|
2010-09-03 13:19:50 +04:00
|
|
|
|
extensions: register functions always at loading extension (issue5601)
Before this patch, functions defined in extensions are registered via
extra loaders only in _dispatch(). Therefore, loading extensions in
other code paths like below omits registration of functions.
- WSGI service
- operation across repositories (e.g. subrepo)
- test-duplicateoptions.py, using extensions.loadall() directly
To register functions always at loading new extension, this patch
moves implementation for extra loading from dispatch._dispatch() to
extensions.loadall().
AFAIK, only commands module causes cyclic dependency between
extensions module, but this patch imports all related modules just
before extra loading in loadall(), in order to centralize them.
This patch makes extensions.py depend on many other modules, even
though extensions.py itself doesn't. It should be avoided if possible,
but I don't have any better idea. Some other places like below aren't
reasonable for extra loading, IMHO.
- specific function in newly added module:
existing callers of extensions.loadall() should invoke it, too
- hg.repository() or so:
no-repo commands aren't covered by this.
BTW, this patch removes _loaded.add(name) on relocation, because
dispatch._loaded is used only for extraloaders (for similar reason,
"exts" variable is removed, too).
2017-06-23 20:39:20 +03:00
|
|
|
Check hgweb's load order of extensions and registration of functions
|
2010-09-03 13:19:50 +04:00
|
|
|
|
|
|
|
$ cat > hgweb.cgi <<EOF
|
2017-06-15 21:27:52 +03:00
|
|
|
> #!$PYTHON
|
2010-09-03 13:19:50 +04:00
|
|
|
> from mercurial import demandimport; demandimport.enable()
|
|
|
|
> from mercurial.hgweb import hgweb
|
|
|
|
> from mercurial.hgweb import wsgicgi
|
|
|
|
> application = hgweb('.', 'test repo')
|
|
|
|
> wsgicgi.launch(application)
|
|
|
|
> EOF
|
2017-06-26 20:24:38 +03:00
|
|
|
$ . "$TESTDIR/cgienv"
|
2010-09-03 13:19:50 +04:00
|
|
|
|
2017-07-05 19:10:11 +03:00
|
|
|
$ PATH_INFO='/' SCRIPT_NAME='' $PYTHON hgweb.cgi \
|
2010-09-03 13:19:50 +04:00
|
|
|
> | grep '^[0-9]) ' # ignores HTML output
|
|
|
|
1) foo imported
|
|
|
|
1) bar imported
|
|
|
|
2) foo uisetup
|
|
|
|
2) bar uisetup
|
|
|
|
3) foo extsetup
|
|
|
|
3) bar extsetup
|
|
|
|
4) foo reposetup
|
|
|
|
4) bar reposetup
|
|
|
|
|
extensions: register functions always at loading extension (issue5601)
Before this patch, functions defined in extensions are registered via
extra loaders only in _dispatch(). Therefore, loading extensions in
other code paths like below omits registration of functions.
- WSGI service
- operation across repositories (e.g. subrepo)
- test-duplicateoptions.py, using extensions.loadall() directly
To register functions always at loading new extension, this patch
moves implementation for extra loading from dispatch._dispatch() to
extensions.loadall().
AFAIK, only commands module causes cyclic dependency between
extensions module, but this patch imports all related modules just
before extra loading in loadall(), in order to centralize them.
This patch makes extensions.py depend on many other modules, even
though extensions.py itself doesn't. It should be avoided if possible,
but I don't have any better idea. Some other places like below aren't
reasonable for extra loading, IMHO.
- specific function in newly added module:
existing callers of extensions.loadall() should invoke it, too
- hg.repository() or so:
no-repo commands aren't covered by this.
BTW, this patch removes _loaded.add(name) on relocation, because
dispatch._loaded is used only for extraloaders (for similar reason,
"exts" variable is removed, too).
2017-06-23 20:39:20 +03:00
|
|
|
(check that revset predicate foo() and bar() are available)
|
|
|
|
|
2017-06-26 20:24:37 +03:00
|
|
|
#if msys
|
|
|
|
$ PATH_INFO='//shortlog'
|
|
|
|
#else
|
|
|
|
$ PATH_INFO='/shortlog'
|
|
|
|
#endif
|
|
|
|
$ export PATH_INFO
|
2017-07-06 22:33:48 +03:00
|
|
|
$ SCRIPT_NAME='' QUERY_STRING='rev=foo() and bar()' $PYTHON hgweb.cgi \
|
extensions: register functions always at loading extension (issue5601)
Before this patch, functions defined in extensions are registered via
extra loaders only in _dispatch(). Therefore, loading extensions in
other code paths like below omits registration of functions.
- WSGI service
- operation across repositories (e.g. subrepo)
- test-duplicateoptions.py, using extensions.loadall() directly
To register functions always at loading new extension, this patch
moves implementation for extra loading from dispatch._dispatch() to
extensions.loadall().
AFAIK, only commands module causes cyclic dependency between
extensions module, but this patch imports all related modules just
before extra loading in loadall(), in order to centralize them.
This patch makes extensions.py depend on many other modules, even
though extensions.py itself doesn't. It should be avoided if possible,
but I don't have any better idea. Some other places like below aren't
reasonable for extra loading, IMHO.
- specific function in newly added module:
existing callers of extensions.loadall() should invoke it, too
- hg.repository() or so:
no-repo commands aren't covered by this.
BTW, this patch removes _loaded.add(name) on relocation, because
dispatch._loaded is used only for extraloaders (for similar reason,
"exts" variable is removed, too).
2017-06-23 20:39:20 +03:00
|
|
|
> | grep '<a href="/rev/[0-9a-z]*">'
|
|
|
|
<a href="/rev/c24b9ac61126">add file</a>
|
|
|
|
|
2010-09-03 13:19:50 +04:00
|
|
|
$ echo 'foo = !' >> $HGRCPATH
|
|
|
|
$ echo 'bar = !' >> $HGRCPATH
|
|
|
|
|
2013-10-04 20:02:22 +04:00
|
|
|
Check "from __future__ import absolute_import" support for external libraries
|
|
|
|
|
2013-11-10 11:48:24 +04:00
|
|
|
#if windows
|
|
|
|
$ PATHSEP=";"
|
|
|
|
#else
|
|
|
|
$ PATHSEP=":"
|
|
|
|
#endif
|
|
|
|
$ export PATHSEP
|
|
|
|
|
2013-10-04 20:02:22 +04:00
|
|
|
$ mkdir $TESTTMP/libroot
|
|
|
|
$ echo "s = 'libroot/ambig.py'" > $TESTTMP/libroot/ambig.py
|
|
|
|
$ mkdir $TESTTMP/libroot/mod
|
|
|
|
$ touch $TESTTMP/libroot/mod/__init__.py
|
|
|
|
$ echo "s = 'libroot/mod/ambig.py'" > $TESTTMP/libroot/mod/ambig.py
|
|
|
|
|
|
|
|
$ cat > $TESTTMP/libroot/mod/ambigabs.py <<EOF
|
|
|
|
> from __future__ import absolute_import
|
|
|
|
> import ambig # should load "libroot/ambig.py"
|
|
|
|
> s = ambig.s
|
|
|
|
> EOF
|
|
|
|
$ cat > loadabs.py <<EOF
|
|
|
|
> import mod.ambigabs as ambigabs
|
|
|
|
> def extsetup():
|
2017-06-15 21:22:25 +03:00
|
|
|
> print('ambigabs.s=%s' % ambigabs.s)
|
2013-10-04 20:02:22 +04:00
|
|
|
> EOF
|
2013-11-10 11:48:24 +04:00
|
|
|
$ (PYTHONPATH=${PYTHONPATH}${PATHSEP}${TESTTMP}/libroot; hg --config extensions.loadabs=loadabs.py root)
|
2013-10-04 20:02:22 +04:00
|
|
|
ambigabs.s=libroot/ambig.py
|
2017-12-11 06:50:57 +03:00
|
|
|
$TESTTMP/a
|
2013-10-04 20:02:22 +04:00
|
|
|
|
|
|
|
#if no-py3k
|
|
|
|
$ cat > $TESTTMP/libroot/mod/ambigrel.py <<EOF
|
|
|
|
> import ambig # should load "libroot/mod/ambig.py"
|
|
|
|
> s = ambig.s
|
|
|
|
> EOF
|
|
|
|
$ cat > loadrel.py <<EOF
|
|
|
|
> import mod.ambigrel as ambigrel
|
|
|
|
> def extsetup():
|
2017-06-15 21:22:25 +03:00
|
|
|
> print('ambigrel.s=%s' % ambigrel.s)
|
2013-10-04 20:02:22 +04:00
|
|
|
> EOF
|
2013-11-10 11:48:24 +04:00
|
|
|
$ (PYTHONPATH=${PYTHONPATH}${PATHSEP}${TESTTMP}/libroot; hg --config extensions.loadrel=loadrel.py root)
|
2013-10-04 20:02:22 +04:00
|
|
|
ambigrel.s=libroot/mod/ambig.py
|
2017-12-11 06:50:57 +03:00
|
|
|
$TESTTMP/a
|
2013-10-04 20:02:22 +04:00
|
|
|
#endif
|
|
|
|
|
demandimport: allow extensions to import own modules by absolute name
Before this patch, python modules of each extensions can't import
another one in own extension by absolute name, because root modules of
each extensions are loaded with "hgext_" prefix.
For example, "import extroot.bar" in "extroot/foo.py" of "extroot"
extension fails, even though "import bar" in it succeeds.
Installing extensions into site-packages of python library path can
avoid this problem, but this solution is not reasonable in some cases:
using binary package of Mercurial on Windows, for example.
This patch retries to import with "hgext_" prefix after ImportError,
if the module in the extension may try to import another one in own
extension.
This patch doesn't change some "_import()"/"_origimport()" invocations
below, because ordinary extensions shouldn't cause such invocations.
- invocation of "_import()" when root module imports sub-module by
absolute path without "fromlist"
for example, "import a.b" in "a.__init__.py".
extensions are loaded with "hgext_" prefix, and this causes
execution of another (= fixed by this patch) code path.
- invocation of "_origimport()" when "level != -1" with "fromlist"
for example, importing after "from __future__ import
absolute_import" (level == 0), or "from . import b" or "from .a
import b" (0 < level),
for portability between python versions and environments,
extensions shouldn't cause "level != -1".
2013-10-04 20:02:22 +04:00
|
|
|
Check absolute/relative import of extension specific modules
|
|
|
|
|
|
|
|
$ mkdir $TESTTMP/extroot
|
|
|
|
$ cat > $TESTTMP/extroot/bar.py <<EOF
|
|
|
|
> s = 'this is extroot.bar'
|
|
|
|
> EOF
|
|
|
|
$ mkdir $TESTTMP/extroot/sub1
|
|
|
|
$ cat > $TESTTMP/extroot/sub1/__init__.py <<EOF
|
|
|
|
> s = 'this is extroot.sub1.__init__'
|
|
|
|
> EOF
|
|
|
|
$ cat > $TESTTMP/extroot/sub1/baz.py <<EOF
|
|
|
|
> s = 'this is extroot.sub1.baz'
|
|
|
|
> EOF
|
|
|
|
$ cat > $TESTTMP/extroot/__init__.py <<EOF
|
|
|
|
> s = 'this is extroot.__init__'
|
|
|
|
> import foo
|
|
|
|
> def extsetup(ui):
|
|
|
|
> ui.write('(extroot) ', foo.func(), '\n')
|
2016-03-15 12:51:42 +03:00
|
|
|
> ui.flush()
|
demandimport: allow extensions to import own modules by absolute name
Before this patch, python modules of each extensions can't import
another one in own extension by absolute name, because root modules of
each extensions are loaded with "hgext_" prefix.
For example, "import extroot.bar" in "extroot/foo.py" of "extroot"
extension fails, even though "import bar" in it succeeds.
Installing extensions into site-packages of python library path can
avoid this problem, but this solution is not reasonable in some cases:
using binary package of Mercurial on Windows, for example.
This patch retries to import with "hgext_" prefix after ImportError,
if the module in the extension may try to import another one in own
extension.
This patch doesn't change some "_import()"/"_origimport()" invocations
below, because ordinary extensions shouldn't cause such invocations.
- invocation of "_import()" when root module imports sub-module by
absolute path without "fromlist"
for example, "import a.b" in "a.__init__.py".
extensions are loaded with "hgext_" prefix, and this causes
execution of another (= fixed by this patch) code path.
- invocation of "_origimport()" when "level != -1" with "fromlist"
for example, importing after "from __future__ import
absolute_import" (level == 0), or "from . import b" or "from .a
import b" (0 < level),
for portability between python versions and environments,
extensions shouldn't cause "level != -1".
2013-10-04 20:02:22 +04:00
|
|
|
> EOF
|
|
|
|
|
|
|
|
$ cat > $TESTTMP/extroot/foo.py <<EOF
|
|
|
|
> # test absolute import
|
|
|
|
> buf = []
|
|
|
|
> def func():
|
|
|
|
> # "not locals" case
|
|
|
|
> import extroot.bar
|
|
|
|
> buf.append('import extroot.bar in func(): %s' % extroot.bar.s)
|
|
|
|
> return '\n(extroot) '.join(buf)
|
|
|
|
> # "fromlist == ('*',)" case
|
|
|
|
> from extroot.bar import *
|
|
|
|
> buf.append('from extroot.bar import *: %s' % s)
|
|
|
|
> # "not fromlist" and "if '.' in name" case
|
|
|
|
> import extroot.sub1.baz
|
|
|
|
> buf.append('import extroot.sub1.baz: %s' % extroot.sub1.baz.s)
|
|
|
|
> # "not fromlist" and NOT "if '.' in name" case
|
|
|
|
> import extroot
|
|
|
|
> buf.append('import extroot: %s' % extroot.s)
|
|
|
|
> # NOT "not fromlist" and NOT "level != -1" case
|
|
|
|
> from extroot.bar import s
|
|
|
|
> buf.append('from extroot.bar import s: %s' % s)
|
|
|
|
> EOF
|
2015-12-18 12:47:21 +03:00
|
|
|
$ (PYTHONPATH=${PYTHONPATH}${PATHSEP}${TESTTMP}; hg --config extensions.extroot=$TESTTMP/extroot root)
|
demandimport: allow extensions to import own modules by absolute name
Before this patch, python modules of each extensions can't import
another one in own extension by absolute name, because root modules of
each extensions are loaded with "hgext_" prefix.
For example, "import extroot.bar" in "extroot/foo.py" of "extroot"
extension fails, even though "import bar" in it succeeds.
Installing extensions into site-packages of python library path can
avoid this problem, but this solution is not reasonable in some cases:
using binary package of Mercurial on Windows, for example.
This patch retries to import with "hgext_" prefix after ImportError,
if the module in the extension may try to import another one in own
extension.
This patch doesn't change some "_import()"/"_origimport()" invocations
below, because ordinary extensions shouldn't cause such invocations.
- invocation of "_import()" when root module imports sub-module by
absolute path without "fromlist"
for example, "import a.b" in "a.__init__.py".
extensions are loaded with "hgext_" prefix, and this causes
execution of another (= fixed by this patch) code path.
- invocation of "_origimport()" when "level != -1" with "fromlist"
for example, importing after "from __future__ import
absolute_import" (level == 0), or "from . import b" or "from .a
import b" (0 < level),
for portability between python versions and environments,
extensions shouldn't cause "level != -1".
2013-10-04 20:02:22 +04:00
|
|
|
(extroot) from extroot.bar import *: this is extroot.bar
|
|
|
|
(extroot) import extroot.sub1.baz: this is extroot.sub1.baz
|
|
|
|
(extroot) import extroot: this is extroot.__init__
|
|
|
|
(extroot) from extroot.bar import s: this is extroot.bar
|
|
|
|
(extroot) import extroot.bar in func(): this is extroot.bar
|
2017-12-11 06:50:57 +03:00
|
|
|
$TESTTMP/a
|
demandimport: allow extensions to import own modules by absolute name
Before this patch, python modules of each extensions can't import
another one in own extension by absolute name, because root modules of
each extensions are loaded with "hgext_" prefix.
For example, "import extroot.bar" in "extroot/foo.py" of "extroot"
extension fails, even though "import bar" in it succeeds.
Installing extensions into site-packages of python library path can
avoid this problem, but this solution is not reasonable in some cases:
using binary package of Mercurial on Windows, for example.
This patch retries to import with "hgext_" prefix after ImportError,
if the module in the extension may try to import another one in own
extension.
This patch doesn't change some "_import()"/"_origimport()" invocations
below, because ordinary extensions shouldn't cause such invocations.
- invocation of "_import()" when root module imports sub-module by
absolute path without "fromlist"
for example, "import a.b" in "a.__init__.py".
extensions are loaded with "hgext_" prefix, and this causes
execution of another (= fixed by this patch) code path.
- invocation of "_origimport()" when "level != -1" with "fromlist"
for example, importing after "from __future__ import
absolute_import" (level == 0), or "from . import b" or "from .a
import b" (0 < level),
for portability between python versions and environments,
extensions shouldn't cause "level != -1".
2013-10-04 20:02:22 +04:00
|
|
|
|
|
|
|
#if no-py3k
|
2013-11-10 11:48:24 +04:00
|
|
|
$ rm "$TESTTMP"/extroot/foo.*
|
2017-08-02 16:04:02 +03:00
|
|
|
$ rm -Rf "$TESTTMP/extroot/__pycache__"
|
demandimport: allow extensions to import own modules by absolute name
Before this patch, python modules of each extensions can't import
another one in own extension by absolute name, because root modules of
each extensions are loaded with "hgext_" prefix.
For example, "import extroot.bar" in "extroot/foo.py" of "extroot"
extension fails, even though "import bar" in it succeeds.
Installing extensions into site-packages of python library path can
avoid this problem, but this solution is not reasonable in some cases:
using binary package of Mercurial on Windows, for example.
This patch retries to import with "hgext_" prefix after ImportError,
if the module in the extension may try to import another one in own
extension.
This patch doesn't change some "_import()"/"_origimport()" invocations
below, because ordinary extensions shouldn't cause such invocations.
- invocation of "_import()" when root module imports sub-module by
absolute path without "fromlist"
for example, "import a.b" in "a.__init__.py".
extensions are loaded with "hgext_" prefix, and this causes
execution of another (= fixed by this patch) code path.
- invocation of "_origimport()" when "level != -1" with "fromlist"
for example, importing after "from __future__ import
absolute_import" (level == 0), or "from . import b" or "from .a
import b" (0 < level),
for portability between python versions and environments,
extensions shouldn't cause "level != -1".
2013-10-04 20:02:22 +04:00
|
|
|
$ cat > $TESTTMP/extroot/foo.py <<EOF
|
|
|
|
> # test relative import
|
|
|
|
> buf = []
|
|
|
|
> def func():
|
|
|
|
> # "not locals" case
|
|
|
|
> import bar
|
|
|
|
> buf.append('import bar in func(): %s' % bar.s)
|
|
|
|
> return '\n(extroot) '.join(buf)
|
|
|
|
> # "fromlist == ('*',)" case
|
|
|
|
> from bar import *
|
|
|
|
> buf.append('from bar import *: %s' % s)
|
|
|
|
> # "not fromlist" and "if '.' in name" case
|
|
|
|
> import sub1.baz
|
|
|
|
> buf.append('import sub1.baz: %s' % sub1.baz.s)
|
|
|
|
> # "not fromlist" and NOT "if '.' in name" case
|
|
|
|
> import sub1
|
|
|
|
> buf.append('import sub1: %s' % sub1.s)
|
|
|
|
> # NOT "not fromlist" and NOT "level != -1" case
|
|
|
|
> from bar import s
|
|
|
|
> buf.append('from bar import s: %s' % s)
|
|
|
|
> EOF
|
|
|
|
$ hg --config extensions.extroot=$TESTTMP/extroot root
|
|
|
|
(extroot) from bar import *: this is extroot.bar
|
|
|
|
(extroot) import sub1.baz: this is extroot.sub1.baz
|
|
|
|
(extroot) import sub1: this is extroot.sub1.__init__
|
|
|
|
(extroot) from bar import s: this is extroot.bar
|
|
|
|
(extroot) import bar in func(): this is extroot.bar
|
2017-12-11 06:50:57 +03:00
|
|
|
$TESTTMP/a
|
demandimport: allow extensions to import own modules by absolute name
Before this patch, python modules of each extensions can't import
another one in own extension by absolute name, because root modules of
each extensions are loaded with "hgext_" prefix.
For example, "import extroot.bar" in "extroot/foo.py" of "extroot"
extension fails, even though "import bar" in it succeeds.
Installing extensions into site-packages of python library path can
avoid this problem, but this solution is not reasonable in some cases:
using binary package of Mercurial on Windows, for example.
This patch retries to import with "hgext_" prefix after ImportError,
if the module in the extension may try to import another one in own
extension.
This patch doesn't change some "_import()"/"_origimport()" invocations
below, because ordinary extensions shouldn't cause such invocations.
- invocation of "_import()" when root module imports sub-module by
absolute path without "fromlist"
for example, "import a.b" in "a.__init__.py".
extensions are loaded with "hgext_" prefix, and this causes
execution of another (= fixed by this patch) code path.
- invocation of "_origimport()" when "level != -1" with "fromlist"
for example, importing after "from __future__ import
absolute_import" (level == 0), or "from . import b" or "from .a
import b" (0 < level),
for portability between python versions and environments,
extensions shouldn't cause "level != -1".
2013-10-04 20:02:22 +04:00
|
|
|
#endif
|
|
|
|
|
2017-07-16 11:47:10 +03:00
|
|
|
#if demandimport
|
demandimport: delay loading for "from a import b" with absolute_import
Before this patch, "from a import b" doesn't delay loading module "b",
if absolute_import is enabled, even though "from . import b" does.
For example:
- it is assumed that extension X has "from P import M" for module M
under package P with absolute_import feature
- if importing module M is already delayed before loading extension
X, loading module M in extension X is delayed until actually
referring
util, cmdutil, scmutil or so of Mercurial itself should be
imported by "from . import M" style before loading extension X
- otherwise, module M is loaded immediately at loading extension X,
even if extension X itself isn't used at that "hg" command invocation
Some minor modules (e.g. filemerge or so) of Mercurial itself
aren't imported by "from . import M" style before loading
extension X. And of course, external libraries aren't, too.
This might cause startup performance problem of hg command, because
many bundled extensions already enable absolute_import feature.
To delay loading module for "from a import b" with absolute_import
feature, this patch does below in "from a (or .a) import b" with
absolute_import case:
1. import root module of "name" by system built-in __import__
(referred as _origimport)
2. recurse down the module chain for hierarchical "name"
This logic can be shared with non absolute_import
case. Therefore, this patch also centralizes it into chainmodules().
3. and fall through to process elements in "fromlist" for the leaf
module of "name"
Processing elements in "fromlist" is executed in the code path
after "if _pypy: .... else: ..." clause. Therefore, this patch
replaces "if _pypy:" with "elif _pypy:" to share it.
At faecf59a4184 introducing original "work around" for "from a import
b" case, elements in "fromlist" were imported with "level=level". But
"level" might be grater than 1 (e.g. level=2 in "from .. import b"
case) at demandimport() invocation, and importing direct sub-module in
"fromlist" with level grater than 1 causes unexpected result.
IMHO, this seems main reason of "errors for unknown reason" described
in faecf59a4184, and we don't have to worry about it, because this
issue was already fixed by 2711f50242cf.
This is reason why this patch removes "errors for unknown reasons"
comment.
2016-06-18 20:17:33 +03:00
|
|
|
|
2016-10-18 00:16:55 +03:00
|
|
|
Examine whether module loading is delayed until actual referring, even
|
demandimport: delay loading for "from a import b" with absolute_import
Before this patch, "from a import b" doesn't delay loading module "b",
if absolute_import is enabled, even though "from . import b" does.
For example:
- it is assumed that extension X has "from P import M" for module M
under package P with absolute_import feature
- if importing module M is already delayed before loading extension
X, loading module M in extension X is delayed until actually
referring
util, cmdutil, scmutil or so of Mercurial itself should be
imported by "from . import M" style before loading extension X
- otherwise, module M is loaded immediately at loading extension X,
even if extension X itself isn't used at that "hg" command invocation
Some minor modules (e.g. filemerge or so) of Mercurial itself
aren't imported by "from . import M" style before loading
extension X. And of course, external libraries aren't, too.
This might cause startup performance problem of hg command, because
many bundled extensions already enable absolute_import feature.
To delay loading module for "from a import b" with absolute_import
feature, this patch does below in "from a (or .a) import b" with
absolute_import case:
1. import root module of "name" by system built-in __import__
(referred as _origimport)
2. recurse down the module chain for hierarchical "name"
This logic can be shared with non absolute_import
case. Therefore, this patch also centralizes it into chainmodules().
3. and fall through to process elements in "fromlist" for the leaf
module of "name"
Processing elements in "fromlist" is executed in the code path
after "if _pypy: .... else: ..." clause. Therefore, this patch
replaces "if _pypy:" with "elif _pypy:" to share it.
At faecf59a4184 introducing original "work around" for "from a import
b" case, elements in "fromlist" were imported with "level=level". But
"level" might be grater than 1 (e.g. level=2 in "from .. import b"
case) at demandimport() invocation, and importing direct sub-module in
"fromlist" with level grater than 1 causes unexpected result.
IMHO, this seems main reason of "errors for unknown reason" described
in faecf59a4184, and we don't have to worry about it, because this
issue was already fixed by 2711f50242cf.
This is reason why this patch removes "errors for unknown reasons"
comment.
2016-06-18 20:17:33 +03:00
|
|
|
though module is imported with "absolute_import" feature.
|
|
|
|
|
2016-10-18 00:16:55 +03:00
|
|
|
Files below in each packages are used for described purpose:
|
demandimport: delay loading for "from a import b" with absolute_import
Before this patch, "from a import b" doesn't delay loading module "b",
if absolute_import is enabled, even though "from . import b" does.
For example:
- it is assumed that extension X has "from P import M" for module M
under package P with absolute_import feature
- if importing module M is already delayed before loading extension
X, loading module M in extension X is delayed until actually
referring
util, cmdutil, scmutil or so of Mercurial itself should be
imported by "from . import M" style before loading extension X
- otherwise, module M is loaded immediately at loading extension X,
even if extension X itself isn't used at that "hg" command invocation
Some minor modules (e.g. filemerge or so) of Mercurial itself
aren't imported by "from . import M" style before loading
extension X. And of course, external libraries aren't, too.
This might cause startup performance problem of hg command, because
many bundled extensions already enable absolute_import feature.
To delay loading module for "from a import b" with absolute_import
feature, this patch does below in "from a (or .a) import b" with
absolute_import case:
1. import root module of "name" by system built-in __import__
(referred as _origimport)
2. recurse down the module chain for hierarchical "name"
This logic can be shared with non absolute_import
case. Therefore, this patch also centralizes it into chainmodules().
3. and fall through to process elements in "fromlist" for the leaf
module of "name"
Processing elements in "fromlist" is executed in the code path
after "if _pypy: .... else: ..." clause. Therefore, this patch
replaces "if _pypy:" with "elif _pypy:" to share it.
At faecf59a4184 introducing original "work around" for "from a import
b" case, elements in "fromlist" were imported with "level=level". But
"level" might be grater than 1 (e.g. level=2 in "from .. import b"
case) at demandimport() invocation, and importing direct sub-module in
"fromlist" with level grater than 1 causes unexpected result.
IMHO, this seems main reason of "errors for unknown reason" described
in faecf59a4184, and we don't have to worry about it, because this
issue was already fixed by 2711f50242cf.
This is reason why this patch removes "errors for unknown reasons"
comment.
2016-06-18 20:17:33 +03:00
|
|
|
|
|
|
|
- "called": examine whether "from MODULE import ATTR" works correctly
|
|
|
|
- "unused": examine whether loading is delayed correctly
|
|
|
|
- "used": examine whether "from PACKAGE import MODULE" works correctly
|
|
|
|
|
|
|
|
Package hierarchy is needed to examine whether demand importing works
|
|
|
|
as expected for "from SUB.PACK.AGE import MODULE".
|
|
|
|
|
|
|
|
Setup "external library" to be imported with "absolute_import"
|
|
|
|
feature.
|
|
|
|
|
|
|
|
$ mkdir -p $TESTTMP/extlibroot/lsub1/lsub2
|
|
|
|
$ touch $TESTTMP/extlibroot/__init__.py
|
|
|
|
$ touch $TESTTMP/extlibroot/lsub1/__init__.py
|
|
|
|
$ touch $TESTTMP/extlibroot/lsub1/lsub2/__init__.py
|
|
|
|
|
|
|
|
$ cat > $TESTTMP/extlibroot/lsub1/lsub2/called.py <<EOF
|
|
|
|
> def func():
|
|
|
|
> return "this is extlibroot.lsub1.lsub2.called.func()"
|
|
|
|
> EOF
|
|
|
|
$ cat > $TESTTMP/extlibroot/lsub1/lsub2/unused.py <<EOF
|
|
|
|
> raise Exception("extlibroot.lsub1.lsub2.unused is loaded unintentionally")
|
|
|
|
> EOF
|
|
|
|
$ cat > $TESTTMP/extlibroot/lsub1/lsub2/used.py <<EOF
|
|
|
|
> detail = "this is extlibroot.lsub1.lsub2.used"
|
|
|
|
> EOF
|
|
|
|
|
|
|
|
Setup sub-package of "external library", which causes instantiation of
|
|
|
|
demandmod in "recurse down the module chain" code path. Relative
|
|
|
|
importing with "absolute_import" feature isn't tested, because "level
|
|
|
|
>=1 " doesn't cause instantiation of demandmod.
|
|
|
|
|
|
|
|
$ mkdir -p $TESTTMP/extlibroot/recursedown/abs
|
|
|
|
$ cat > $TESTTMP/extlibroot/recursedown/abs/used.py <<EOF
|
|
|
|
> detail = "this is extlibroot.recursedown.abs.used"
|
|
|
|
> EOF
|
|
|
|
$ cat > $TESTTMP/extlibroot/recursedown/abs/__init__.py <<EOF
|
|
|
|
> from __future__ import absolute_import
|
|
|
|
> from extlibroot.recursedown.abs.used import detail
|
|
|
|
> EOF
|
|
|
|
|
|
|
|
$ mkdir -p $TESTTMP/extlibroot/recursedown/legacy
|
|
|
|
$ cat > $TESTTMP/extlibroot/recursedown/legacy/used.py <<EOF
|
|
|
|
> detail = "this is extlibroot.recursedown.legacy.used"
|
|
|
|
> EOF
|
|
|
|
$ cat > $TESTTMP/extlibroot/recursedown/legacy/__init__.py <<EOF
|
|
|
|
> # legacy style (level == -1) import
|
|
|
|
> from extlibroot.recursedown.legacy.used import detail
|
|
|
|
> EOF
|
|
|
|
|
|
|
|
$ cat > $TESTTMP/extlibroot/recursedown/__init__.py <<EOF
|
|
|
|
> from __future__ import absolute_import
|
|
|
|
> from extlibroot.recursedown.abs import detail as absdetail
|
|
|
|
> from .legacy import detail as legacydetail
|
|
|
|
> EOF
|
|
|
|
|
2017-07-16 11:38:39 +03:00
|
|
|
Setup package that re-exports an attribute of its submodule as the same
|
|
|
|
name. This leaves 'shadowing.used' pointing to 'used.detail', but still
|
|
|
|
the submodule 'used' should be somehow accessible. (issue5617)
|
|
|
|
|
|
|
|
$ mkdir -p $TESTTMP/extlibroot/shadowing
|
|
|
|
$ cat > $TESTTMP/extlibroot/shadowing/used.py <<EOF
|
|
|
|
> detail = "this is extlibroot.shadowing.used"
|
|
|
|
> EOF
|
|
|
|
$ cat > $TESTTMP/extlibroot/shadowing/proxied.py <<EOF
|
|
|
|
> from __future__ import absolute_import
|
|
|
|
> from extlibroot.shadowing.used import detail
|
|
|
|
> EOF
|
|
|
|
$ cat > $TESTTMP/extlibroot/shadowing/__init__.py <<EOF
|
|
|
|
> from __future__ import absolute_import
|
|
|
|
> from .used import detail as used
|
|
|
|
> EOF
|
|
|
|
|
demandimport: delay loading for "from a import b" with absolute_import
Before this patch, "from a import b" doesn't delay loading module "b",
if absolute_import is enabled, even though "from . import b" does.
For example:
- it is assumed that extension X has "from P import M" for module M
under package P with absolute_import feature
- if importing module M is already delayed before loading extension
X, loading module M in extension X is delayed until actually
referring
util, cmdutil, scmutil or so of Mercurial itself should be
imported by "from . import M" style before loading extension X
- otherwise, module M is loaded immediately at loading extension X,
even if extension X itself isn't used at that "hg" command invocation
Some minor modules (e.g. filemerge or so) of Mercurial itself
aren't imported by "from . import M" style before loading
extension X. And of course, external libraries aren't, too.
This might cause startup performance problem of hg command, because
many bundled extensions already enable absolute_import feature.
To delay loading module for "from a import b" with absolute_import
feature, this patch does below in "from a (or .a) import b" with
absolute_import case:
1. import root module of "name" by system built-in __import__
(referred as _origimport)
2. recurse down the module chain for hierarchical "name"
This logic can be shared with non absolute_import
case. Therefore, this patch also centralizes it into chainmodules().
3. and fall through to process elements in "fromlist" for the leaf
module of "name"
Processing elements in "fromlist" is executed in the code path
after "if _pypy: .... else: ..." clause. Therefore, this patch
replaces "if _pypy:" with "elif _pypy:" to share it.
At faecf59a4184 introducing original "work around" for "from a import
b" case, elements in "fromlist" were imported with "level=level". But
"level" might be grater than 1 (e.g. level=2 in "from .. import b"
case) at demandimport() invocation, and importing direct sub-module in
"fromlist" with level grater than 1 causes unexpected result.
IMHO, this seems main reason of "errors for unknown reason" described
in faecf59a4184, and we don't have to worry about it, because this
issue was already fixed by 2711f50242cf.
This is reason why this patch removes "errors for unknown reasons"
comment.
2016-06-18 20:17:33 +03:00
|
|
|
Setup extension local modules to be imported with "absolute_import"
|
|
|
|
feature.
|
|
|
|
|
|
|
|
$ mkdir -p $TESTTMP/absextroot/xsub1/xsub2
|
|
|
|
$ touch $TESTTMP/absextroot/xsub1/__init__.py
|
|
|
|
$ touch $TESTTMP/absextroot/xsub1/xsub2/__init__.py
|
|
|
|
|
|
|
|
$ cat > $TESTTMP/absextroot/xsub1/xsub2/called.py <<EOF
|
|
|
|
> def func():
|
|
|
|
> return "this is absextroot.xsub1.xsub2.called.func()"
|
|
|
|
> EOF
|
|
|
|
$ cat > $TESTTMP/absextroot/xsub1/xsub2/unused.py <<EOF
|
|
|
|
> raise Exception("absextroot.xsub1.xsub2.unused is loaded unintentionally")
|
|
|
|
> EOF
|
|
|
|
$ cat > $TESTTMP/absextroot/xsub1/xsub2/used.py <<EOF
|
|
|
|
> detail = "this is absextroot.xsub1.xsub2.used"
|
|
|
|
> EOF
|
|
|
|
|
|
|
|
Setup extension local modules to examine whether demand importing
|
|
|
|
works as expected in "level > 1" case.
|
|
|
|
|
|
|
|
$ cat > $TESTTMP/absextroot/relimportee.py <<EOF
|
|
|
|
> detail = "this is absextroot.relimportee"
|
|
|
|
> EOF
|
|
|
|
$ cat > $TESTTMP/absextroot/xsub1/xsub2/relimporter.py <<EOF
|
|
|
|
> from __future__ import absolute_import
|
|
|
|
> from ... import relimportee
|
|
|
|
> detail = "this relimporter imports %r" % (relimportee.detail)
|
|
|
|
> EOF
|
|
|
|
|
|
|
|
Setup modules, which actually import extension local modules at
|
|
|
|
runtime.
|
|
|
|
|
|
|
|
$ cat > $TESTTMP/absextroot/absolute.py << EOF
|
|
|
|
> from __future__ import absolute_import
|
|
|
|
>
|
|
|
|
> # import extension local modules absolutely (level = 0)
|
|
|
|
> from absextroot.xsub1.xsub2 import used, unused
|
|
|
|
> from absextroot.xsub1.xsub2.called import func
|
|
|
|
>
|
|
|
|
> def getresult():
|
|
|
|
> result = []
|
|
|
|
> result.append(used.detail)
|
|
|
|
> result.append(func())
|
|
|
|
> return result
|
|
|
|
> EOF
|
|
|
|
|
|
|
|
$ cat > $TESTTMP/absextroot/relative.py << EOF
|
|
|
|
> from __future__ import absolute_import
|
|
|
|
>
|
|
|
|
> # import extension local modules relatively (level == 1)
|
|
|
|
> from .xsub1.xsub2 import used, unused
|
|
|
|
> from .xsub1.xsub2.called import func
|
|
|
|
>
|
|
|
|
> # import a module, which implies "importing with level > 1"
|
|
|
|
> from .xsub1.xsub2 import relimporter
|
|
|
|
>
|
|
|
|
> def getresult():
|
|
|
|
> result = []
|
|
|
|
> result.append(used.detail)
|
|
|
|
> result.append(func())
|
|
|
|
> result.append(relimporter.detail)
|
|
|
|
> return result
|
|
|
|
> EOF
|
|
|
|
|
|
|
|
Setup main procedure of extension.
|
|
|
|
|
|
|
|
$ cat > $TESTTMP/absextroot/__init__.py <<EOF
|
|
|
|
> from __future__ import absolute_import
|
2016-01-09 17:07:20 +03:00
|
|
|
> from mercurial import registrar
|
demandimport: delay loading for "from a import b" with absolute_import
Before this patch, "from a import b" doesn't delay loading module "b",
if absolute_import is enabled, even though "from . import b" does.
For example:
- it is assumed that extension X has "from P import M" for module M
under package P with absolute_import feature
- if importing module M is already delayed before loading extension
X, loading module M in extension X is delayed until actually
referring
util, cmdutil, scmutil or so of Mercurial itself should be
imported by "from . import M" style before loading extension X
- otherwise, module M is loaded immediately at loading extension X,
even if extension X itself isn't used at that "hg" command invocation
Some minor modules (e.g. filemerge or so) of Mercurial itself
aren't imported by "from . import M" style before loading
extension X. And of course, external libraries aren't, too.
This might cause startup performance problem of hg command, because
many bundled extensions already enable absolute_import feature.
To delay loading module for "from a import b" with absolute_import
feature, this patch does below in "from a (or .a) import b" with
absolute_import case:
1. import root module of "name" by system built-in __import__
(referred as _origimport)
2. recurse down the module chain for hierarchical "name"
This logic can be shared with non absolute_import
case. Therefore, this patch also centralizes it into chainmodules().
3. and fall through to process elements in "fromlist" for the leaf
module of "name"
Processing elements in "fromlist" is executed in the code path
after "if _pypy: .... else: ..." clause. Therefore, this patch
replaces "if _pypy:" with "elif _pypy:" to share it.
At faecf59a4184 introducing original "work around" for "from a import
b" case, elements in "fromlist" were imported with "level=level". But
"level" might be grater than 1 (e.g. level=2 in "from .. import b"
case) at demandimport() invocation, and importing direct sub-module in
"fromlist" with level grater than 1 causes unexpected result.
IMHO, this seems main reason of "errors for unknown reason" described
in faecf59a4184, and we don't have to worry about it, because this
issue was already fixed by 2711f50242cf.
This is reason why this patch removes "errors for unknown reasons"
comment.
2016-06-18 20:17:33 +03:00
|
|
|
> cmdtable = {}
|
2016-01-09 17:07:20 +03:00
|
|
|
> command = registrar.command(cmdtable)
|
demandimport: delay loading for "from a import b" with absolute_import
Before this patch, "from a import b" doesn't delay loading module "b",
if absolute_import is enabled, even though "from . import b" does.
For example:
- it is assumed that extension X has "from P import M" for module M
under package P with absolute_import feature
- if importing module M is already delayed before loading extension
X, loading module M in extension X is delayed until actually
referring
util, cmdutil, scmutil or so of Mercurial itself should be
imported by "from . import M" style before loading extension X
- otherwise, module M is loaded immediately at loading extension X,
even if extension X itself isn't used at that "hg" command invocation
Some minor modules (e.g. filemerge or so) of Mercurial itself
aren't imported by "from . import M" style before loading
extension X. And of course, external libraries aren't, too.
This might cause startup performance problem of hg command, because
many bundled extensions already enable absolute_import feature.
To delay loading module for "from a import b" with absolute_import
feature, this patch does below in "from a (or .a) import b" with
absolute_import case:
1. import root module of "name" by system built-in __import__
(referred as _origimport)
2. recurse down the module chain for hierarchical "name"
This logic can be shared with non absolute_import
case. Therefore, this patch also centralizes it into chainmodules().
3. and fall through to process elements in "fromlist" for the leaf
module of "name"
Processing elements in "fromlist" is executed in the code path
after "if _pypy: .... else: ..." clause. Therefore, this patch
replaces "if _pypy:" with "elif _pypy:" to share it.
At faecf59a4184 introducing original "work around" for "from a import
b" case, elements in "fromlist" were imported with "level=level". But
"level" might be grater than 1 (e.g. level=2 in "from .. import b"
case) at demandimport() invocation, and importing direct sub-module in
"fromlist" with level grater than 1 causes unexpected result.
IMHO, this seems main reason of "errors for unknown reason" described
in faecf59a4184, and we don't have to worry about it, because this
issue was already fixed by 2711f50242cf.
This is reason why this patch removes "errors for unknown reasons"
comment.
2016-06-18 20:17:33 +03:00
|
|
|
>
|
|
|
|
> # "absolute" and "relative" shouldn't be imported before actual
|
|
|
|
> # command execution, because (1) they import same modules, and (2)
|
|
|
|
> # preceding import (= instantiate "demandmod" object instead of
|
|
|
|
> # real "module" object) might hide problem of succeeding import.
|
|
|
|
>
|
2017-06-25 05:50:05 +03:00
|
|
|
> @command(b'showabsolute', [], norepo=True)
|
demandimport: delay loading for "from a import b" with absolute_import
Before this patch, "from a import b" doesn't delay loading module "b",
if absolute_import is enabled, even though "from . import b" does.
For example:
- it is assumed that extension X has "from P import M" for module M
under package P with absolute_import feature
- if importing module M is already delayed before loading extension
X, loading module M in extension X is delayed until actually
referring
util, cmdutil, scmutil or so of Mercurial itself should be
imported by "from . import M" style before loading extension X
- otherwise, module M is loaded immediately at loading extension X,
even if extension X itself isn't used at that "hg" command invocation
Some minor modules (e.g. filemerge or so) of Mercurial itself
aren't imported by "from . import M" style before loading
extension X. And of course, external libraries aren't, too.
This might cause startup performance problem of hg command, because
many bundled extensions already enable absolute_import feature.
To delay loading module for "from a import b" with absolute_import
feature, this patch does below in "from a (or .a) import b" with
absolute_import case:
1. import root module of "name" by system built-in __import__
(referred as _origimport)
2. recurse down the module chain for hierarchical "name"
This logic can be shared with non absolute_import
case. Therefore, this patch also centralizes it into chainmodules().
3. and fall through to process elements in "fromlist" for the leaf
module of "name"
Processing elements in "fromlist" is executed in the code path
after "if _pypy: .... else: ..." clause. Therefore, this patch
replaces "if _pypy:" with "elif _pypy:" to share it.
At faecf59a4184 introducing original "work around" for "from a import
b" case, elements in "fromlist" were imported with "level=level". But
"level" might be grater than 1 (e.g. level=2 in "from .. import b"
case) at demandimport() invocation, and importing direct sub-module in
"fromlist" with level grater than 1 causes unexpected result.
IMHO, this seems main reason of "errors for unknown reason" described
in faecf59a4184, and we don't have to worry about it, because this
issue was already fixed by 2711f50242cf.
This is reason why this patch removes "errors for unknown reasons"
comment.
2016-06-18 20:17:33 +03:00
|
|
|
> def showabsolute(ui, *args, **opts):
|
|
|
|
> from absextroot import absolute
|
|
|
|
> ui.write('ABS: %s\n' % '\nABS: '.join(absolute.getresult()))
|
|
|
|
>
|
2017-06-25 05:50:05 +03:00
|
|
|
> @command(b'showrelative', [], norepo=True)
|
demandimport: delay loading for "from a import b" with absolute_import
Before this patch, "from a import b" doesn't delay loading module "b",
if absolute_import is enabled, even though "from . import b" does.
For example:
- it is assumed that extension X has "from P import M" for module M
under package P with absolute_import feature
- if importing module M is already delayed before loading extension
X, loading module M in extension X is delayed until actually
referring
util, cmdutil, scmutil or so of Mercurial itself should be
imported by "from . import M" style before loading extension X
- otherwise, module M is loaded immediately at loading extension X,
even if extension X itself isn't used at that "hg" command invocation
Some minor modules (e.g. filemerge or so) of Mercurial itself
aren't imported by "from . import M" style before loading
extension X. And of course, external libraries aren't, too.
This might cause startup performance problem of hg command, because
many bundled extensions already enable absolute_import feature.
To delay loading module for "from a import b" with absolute_import
feature, this patch does below in "from a (or .a) import b" with
absolute_import case:
1. import root module of "name" by system built-in __import__
(referred as _origimport)
2. recurse down the module chain for hierarchical "name"
This logic can be shared with non absolute_import
case. Therefore, this patch also centralizes it into chainmodules().
3. and fall through to process elements in "fromlist" for the leaf
module of "name"
Processing elements in "fromlist" is executed in the code path
after "if _pypy: .... else: ..." clause. Therefore, this patch
replaces "if _pypy:" with "elif _pypy:" to share it.
At faecf59a4184 introducing original "work around" for "from a import
b" case, elements in "fromlist" were imported with "level=level". But
"level" might be grater than 1 (e.g. level=2 in "from .. import b"
case) at demandimport() invocation, and importing direct sub-module in
"fromlist" with level grater than 1 causes unexpected result.
IMHO, this seems main reason of "errors for unknown reason" described
in faecf59a4184, and we don't have to worry about it, because this
issue was already fixed by 2711f50242cf.
This is reason why this patch removes "errors for unknown reasons"
comment.
2016-06-18 20:17:33 +03:00
|
|
|
> def showrelative(ui, *args, **opts):
|
|
|
|
> from . import relative
|
|
|
|
> ui.write('REL: %s\n' % '\nREL: '.join(relative.getresult()))
|
|
|
|
>
|
|
|
|
> # import modules from external library
|
|
|
|
> from extlibroot.lsub1.lsub2 import used as lused, unused as lunused
|
|
|
|
> from extlibroot.lsub1.lsub2.called import func as lfunc
|
|
|
|
> from extlibroot.recursedown import absdetail, legacydetail
|
2017-07-16 11:38:39 +03:00
|
|
|
> from extlibroot.shadowing import proxied
|
demandimport: delay loading for "from a import b" with absolute_import
Before this patch, "from a import b" doesn't delay loading module "b",
if absolute_import is enabled, even though "from . import b" does.
For example:
- it is assumed that extension X has "from P import M" for module M
under package P with absolute_import feature
- if importing module M is already delayed before loading extension
X, loading module M in extension X is delayed until actually
referring
util, cmdutil, scmutil or so of Mercurial itself should be
imported by "from . import M" style before loading extension X
- otherwise, module M is loaded immediately at loading extension X,
even if extension X itself isn't used at that "hg" command invocation
Some minor modules (e.g. filemerge or so) of Mercurial itself
aren't imported by "from . import M" style before loading
extension X. And of course, external libraries aren't, too.
This might cause startup performance problem of hg command, because
many bundled extensions already enable absolute_import feature.
To delay loading module for "from a import b" with absolute_import
feature, this patch does below in "from a (or .a) import b" with
absolute_import case:
1. import root module of "name" by system built-in __import__
(referred as _origimport)
2. recurse down the module chain for hierarchical "name"
This logic can be shared with non absolute_import
case. Therefore, this patch also centralizes it into chainmodules().
3. and fall through to process elements in "fromlist" for the leaf
module of "name"
Processing elements in "fromlist" is executed in the code path
after "if _pypy: .... else: ..." clause. Therefore, this patch
replaces "if _pypy:" with "elif _pypy:" to share it.
At faecf59a4184 introducing original "work around" for "from a import
b" case, elements in "fromlist" were imported with "level=level". But
"level" might be grater than 1 (e.g. level=2 in "from .. import b"
case) at demandimport() invocation, and importing direct sub-module in
"fromlist" with level grater than 1 causes unexpected result.
IMHO, this seems main reason of "errors for unknown reason" described
in faecf59a4184, and we don't have to worry about it, because this
issue was already fixed by 2711f50242cf.
This is reason why this patch removes "errors for unknown reasons"
comment.
2016-06-18 20:17:33 +03:00
|
|
|
>
|
|
|
|
> def uisetup(ui):
|
|
|
|
> result = []
|
|
|
|
> result.append(lused.detail)
|
|
|
|
> result.append(lfunc())
|
|
|
|
> result.append(absdetail)
|
|
|
|
> result.append(legacydetail)
|
2017-07-16 11:38:39 +03:00
|
|
|
> result.append(proxied.detail)
|
demandimport: delay loading for "from a import b" with absolute_import
Before this patch, "from a import b" doesn't delay loading module "b",
if absolute_import is enabled, even though "from . import b" does.
For example:
- it is assumed that extension X has "from P import M" for module M
under package P with absolute_import feature
- if importing module M is already delayed before loading extension
X, loading module M in extension X is delayed until actually
referring
util, cmdutil, scmutil or so of Mercurial itself should be
imported by "from . import M" style before loading extension X
- otherwise, module M is loaded immediately at loading extension X,
even if extension X itself isn't used at that "hg" command invocation
Some minor modules (e.g. filemerge or so) of Mercurial itself
aren't imported by "from . import M" style before loading
extension X. And of course, external libraries aren't, too.
This might cause startup performance problem of hg command, because
many bundled extensions already enable absolute_import feature.
To delay loading module for "from a import b" with absolute_import
feature, this patch does below in "from a (or .a) import b" with
absolute_import case:
1. import root module of "name" by system built-in __import__
(referred as _origimport)
2. recurse down the module chain for hierarchical "name"
This logic can be shared with non absolute_import
case. Therefore, this patch also centralizes it into chainmodules().
3. and fall through to process elements in "fromlist" for the leaf
module of "name"
Processing elements in "fromlist" is executed in the code path
after "if _pypy: .... else: ..." clause. Therefore, this patch
replaces "if _pypy:" with "elif _pypy:" to share it.
At faecf59a4184 introducing original "work around" for "from a import
b" case, elements in "fromlist" were imported with "level=level". But
"level" might be grater than 1 (e.g. level=2 in "from .. import b"
case) at demandimport() invocation, and importing direct sub-module in
"fromlist" with level grater than 1 causes unexpected result.
IMHO, this seems main reason of "errors for unknown reason" described
in faecf59a4184, and we don't have to worry about it, because this
issue was already fixed by 2711f50242cf.
This is reason why this patch removes "errors for unknown reasons"
comment.
2016-06-18 20:17:33 +03:00
|
|
|
> ui.write('LIB: %s\n' % '\nLIB: '.join(result))
|
|
|
|
> EOF
|
|
|
|
|
|
|
|
Examine module importing.
|
|
|
|
|
|
|
|
$ (PYTHONPATH=${PYTHONPATH}${PATHSEP}${TESTTMP}; hg --config extensions.absextroot=$TESTTMP/absextroot showabsolute)
|
|
|
|
LIB: this is extlibroot.lsub1.lsub2.used
|
|
|
|
LIB: this is extlibroot.lsub1.lsub2.called.func()
|
|
|
|
LIB: this is extlibroot.recursedown.abs.used
|
|
|
|
LIB: this is extlibroot.recursedown.legacy.used
|
2017-07-16 11:38:39 +03:00
|
|
|
LIB: this is extlibroot.shadowing.used
|
demandimport: delay loading for "from a import b" with absolute_import
Before this patch, "from a import b" doesn't delay loading module "b",
if absolute_import is enabled, even though "from . import b" does.
For example:
- it is assumed that extension X has "from P import M" for module M
under package P with absolute_import feature
- if importing module M is already delayed before loading extension
X, loading module M in extension X is delayed until actually
referring
util, cmdutil, scmutil or so of Mercurial itself should be
imported by "from . import M" style before loading extension X
- otherwise, module M is loaded immediately at loading extension X,
even if extension X itself isn't used at that "hg" command invocation
Some minor modules (e.g. filemerge or so) of Mercurial itself
aren't imported by "from . import M" style before loading
extension X. And of course, external libraries aren't, too.
This might cause startup performance problem of hg command, because
many bundled extensions already enable absolute_import feature.
To delay loading module for "from a import b" with absolute_import
feature, this patch does below in "from a (or .a) import b" with
absolute_import case:
1. import root module of "name" by system built-in __import__
(referred as _origimport)
2. recurse down the module chain for hierarchical "name"
This logic can be shared with non absolute_import
case. Therefore, this patch also centralizes it into chainmodules().
3. and fall through to process elements in "fromlist" for the leaf
module of "name"
Processing elements in "fromlist" is executed in the code path
after "if _pypy: .... else: ..." clause. Therefore, this patch
replaces "if _pypy:" with "elif _pypy:" to share it.
At faecf59a4184 introducing original "work around" for "from a import
b" case, elements in "fromlist" were imported with "level=level". But
"level" might be grater than 1 (e.g. level=2 in "from .. import b"
case) at demandimport() invocation, and importing direct sub-module in
"fromlist" with level grater than 1 causes unexpected result.
IMHO, this seems main reason of "errors for unknown reason" described
in faecf59a4184, and we don't have to worry about it, because this
issue was already fixed by 2711f50242cf.
This is reason why this patch removes "errors for unknown reasons"
comment.
2016-06-18 20:17:33 +03:00
|
|
|
ABS: this is absextroot.xsub1.xsub2.used
|
|
|
|
ABS: this is absextroot.xsub1.xsub2.called.func()
|
|
|
|
|
|
|
|
$ (PYTHONPATH=${PYTHONPATH}${PATHSEP}${TESTTMP}; hg --config extensions.absextroot=$TESTTMP/absextroot showrelative)
|
|
|
|
LIB: this is extlibroot.lsub1.lsub2.used
|
|
|
|
LIB: this is extlibroot.lsub1.lsub2.called.func()
|
|
|
|
LIB: this is extlibroot.recursedown.abs.used
|
|
|
|
LIB: this is extlibroot.recursedown.legacy.used
|
2017-07-16 11:38:39 +03:00
|
|
|
LIB: this is extlibroot.shadowing.used
|
demandimport: delay loading for "from a import b" with absolute_import
Before this patch, "from a import b" doesn't delay loading module "b",
if absolute_import is enabled, even though "from . import b" does.
For example:
- it is assumed that extension X has "from P import M" for module M
under package P with absolute_import feature
- if importing module M is already delayed before loading extension
X, loading module M in extension X is delayed until actually
referring
util, cmdutil, scmutil or so of Mercurial itself should be
imported by "from . import M" style before loading extension X
- otherwise, module M is loaded immediately at loading extension X,
even if extension X itself isn't used at that "hg" command invocation
Some minor modules (e.g. filemerge or so) of Mercurial itself
aren't imported by "from . import M" style before loading
extension X. And of course, external libraries aren't, too.
This might cause startup performance problem of hg command, because
many bundled extensions already enable absolute_import feature.
To delay loading module for "from a import b" with absolute_import
feature, this patch does below in "from a (or .a) import b" with
absolute_import case:
1. import root module of "name" by system built-in __import__
(referred as _origimport)
2. recurse down the module chain for hierarchical "name"
This logic can be shared with non absolute_import
case. Therefore, this patch also centralizes it into chainmodules().
3. and fall through to process elements in "fromlist" for the leaf
module of "name"
Processing elements in "fromlist" is executed in the code path
after "if _pypy: .... else: ..." clause. Therefore, this patch
replaces "if _pypy:" with "elif _pypy:" to share it.
At faecf59a4184 introducing original "work around" for "from a import
b" case, elements in "fromlist" were imported with "level=level". But
"level" might be grater than 1 (e.g. level=2 in "from .. import b"
case) at demandimport() invocation, and importing direct sub-module in
"fromlist" with level grater than 1 causes unexpected result.
IMHO, this seems main reason of "errors for unknown reason" described
in faecf59a4184, and we don't have to worry about it, because this
issue was already fixed by 2711f50242cf.
This is reason why this patch removes "errors for unknown reasons"
comment.
2016-06-18 20:17:33 +03:00
|
|
|
REL: this is absextroot.xsub1.xsub2.used
|
|
|
|
REL: this is absextroot.xsub1.xsub2.called.func()
|
|
|
|
REL: this relimporter imports 'this is absextroot.relimportee'
|
|
|
|
|
2016-08-06 16:24:33 +03:00
|
|
|
Examine whether sub-module is imported relatively as expected.
|
|
|
|
|
|
|
|
See also issue5208 for detail about example case on Python 3.x.
|
|
|
|
|
|
|
|
$ f -q $TESTTMP/extlibroot/lsub1/lsub2/notexist.py
|
|
|
|
$TESTTMP/extlibroot/lsub1/lsub2/notexist.py: file not found
|
|
|
|
|
|
|
|
$ cat > $TESTTMP/notexist.py <<EOF
|
|
|
|
> text = 'notexist.py at root is loaded unintentionally\n'
|
|
|
|
> EOF
|
|
|
|
|
|
|
|
$ cat > $TESTTMP/checkrelativity.py <<EOF
|
2016-01-09 17:07:20 +03:00
|
|
|
> from mercurial import registrar
|
2016-08-06 16:24:33 +03:00
|
|
|
> cmdtable = {}
|
2016-01-09 17:07:20 +03:00
|
|
|
> command = registrar.command(cmdtable)
|
2016-08-06 16:24:33 +03:00
|
|
|
>
|
|
|
|
> # demand import avoids failure of importing notexist here
|
|
|
|
> import extlibroot.lsub1.lsub2.notexist
|
|
|
|
>
|
2017-06-25 05:50:05 +03:00
|
|
|
> @command(b'checkrelativity', [], norepo=True)
|
2016-08-06 16:24:33 +03:00
|
|
|
> def checkrelativity(ui, *args, **opts):
|
|
|
|
> try:
|
|
|
|
> ui.write(extlibroot.lsub1.lsub2.notexist.text)
|
|
|
|
> return 1 # unintentional success
|
|
|
|
> except ImportError:
|
|
|
|
> pass # intentional failure
|
|
|
|
> EOF
|
|
|
|
|
|
|
|
$ (PYTHONPATH=${PYTHONPATH}${PATHSEP}${TESTTMP}; hg --config extensions.checkrelativity=$TESTTMP/checkrelativity.py checkrelativity)
|
|
|
|
|
2017-10-17 20:25:32 +03:00
|
|
|
#endif
|
|
|
|
|
2017-08-27 02:00:07 +03:00
|
|
|
Make sure a broken uisetup doesn't globally break hg:
|
|
|
|
$ cat > $TESTTMP/baduisetup.py <<EOF
|
|
|
|
> def uisetup(ui):
|
2017-10-17 19:46:31 +03:00
|
|
|
> 1/0
|
2017-08-27 02:00:07 +03:00
|
|
|
> EOF
|
|
|
|
|
|
|
|
Even though the extension fails during uisetup, hg is still basically usable:
|
|
|
|
$ hg --config extensions.baduisetup=$TESTTMP/baduisetup.py version
|
|
|
|
Traceback (most recent call last):
|
|
|
|
File "*/mercurial/extensions.py", line *, in _runuisetup (glob)
|
|
|
|
uisetup(ui)
|
2017-10-17 19:46:31 +03:00
|
|
|
File "$TESTTMP/baduisetup.py", line 2, in uisetup
|
|
|
|
1/0
|
|
|
|
ZeroDivisionError: integer division or modulo by zero
|
|
|
|
*** failed to set up extension baduisetup: integer division or modulo by zero
|
2017-08-27 02:00:07 +03:00
|
|
|
Mercurial Distributed SCM (version *) (glob)
|
|
|
|
(see https://mercurial-scm.org for more information)
|
|
|
|
|
|
|
|
Copyright (C) 2005-2017 Matt Mackall and others
|
|
|
|
This is free software; see the source for copying conditions. There is NO
|
|
|
|
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
2010-09-03 13:19:50 +04:00
|
|
|
$ cd ..
|
|
|
|
|
2012-06-21 01:41:21 +04:00
|
|
|
hide outer repo
|
|
|
|
$ hg init
|
|
|
|
|
2010-09-03 13:19:50 +04:00
|
|
|
$ cat > empty.py <<EOF
|
|
|
|
> '''empty cmdtable
|
|
|
|
> '''
|
|
|
|
> cmdtable = {}
|
|
|
|
> EOF
|
|
|
|
$ emptypath=`pwd`/empty.py
|
|
|
|
$ echo "empty = $emptypath" >> $HGRCPATH
|
|
|
|
$ hg help empty
|
|
|
|
empty extension - empty cmdtable
|
|
|
|
|
|
|
|
no commands defined
|
|
|
|
|
2014-07-09 06:57:54 +04:00
|
|
|
|
2010-09-03 13:19:50 +04:00
|
|
|
$ echo 'empty = !' >> $HGRCPATH
|
|
|
|
|
|
|
|
$ cat > debugextension.py <<EOF
|
|
|
|
> '''only debugcommands
|
|
|
|
> '''
|
2016-01-09 17:07:20 +03:00
|
|
|
> from mercurial import registrar
|
2014-05-05 09:48:07 +04:00
|
|
|
> cmdtable = {}
|
2016-01-09 17:07:20 +03:00
|
|
|
> command = registrar.command(cmdtable)
|
2017-06-25 05:50:05 +03:00
|
|
|
> @command(b'debugfoobar', [], 'hg debugfoobar')
|
2010-09-03 13:19:50 +04:00
|
|
|
> def debugfoobar(ui, repo, *args, **opts):
|
|
|
|
> "yet another debug command"
|
|
|
|
> pass
|
2017-06-25 05:50:05 +03:00
|
|
|
> @command(b'foo', [], 'hg foo')
|
2010-09-03 13:19:50 +04:00
|
|
|
> def foo(ui, repo, *args, **opts):
|
|
|
|
> """yet another foo command
|
|
|
|
> This command has been DEPRECATED since forever.
|
|
|
|
> """
|
|
|
|
> pass
|
|
|
|
> EOF
|
|
|
|
$ debugpath=`pwd`/debugextension.py
|
|
|
|
$ echo "debugextension = $debugpath" >> $HGRCPATH
|
|
|
|
|
|
|
|
$ hg help debugextension
|
2015-09-10 17:53:07 +03:00
|
|
|
hg debugextensions
|
2010-09-03 13:19:50 +04:00
|
|
|
|
2015-09-10 17:53:07 +03:00
|
|
|
show information about active extensions
|
|
|
|
|
2018-10-15 19:35:15 +03:00
|
|
|
Options:
|
2015-09-10 17:53:07 +03:00
|
|
|
|
2018-01-23 23:08:47 +03:00
|
|
|
--excludedefault exclude extensions marked as default-on
|
|
|
|
|
2015-09-10 17:53:07 +03:00
|
|
|
(some details hidden, use --verbose to show complete help)
|
2010-09-03 13:19:50 +04:00
|
|
|
|
2014-07-09 06:57:54 +04:00
|
|
|
|
2010-09-03 13:19:50 +04:00
|
|
|
$ hg --verbose help debugextension
|
2015-09-10 17:53:07 +03:00
|
|
|
hg debugextensions
|
2010-09-03 13:19:50 +04:00
|
|
|
|
2015-09-10 17:53:07 +03:00
|
|
|
show information about active extensions
|
|
|
|
|
2018-10-15 19:35:15 +03:00
|
|
|
Options:
|
2010-09-03 13:19:50 +04:00
|
|
|
|
2018-01-23 23:08:47 +03:00
|
|
|
--excludedefault exclude extensions marked as default-on
|
2015-09-10 17:53:07 +03:00
|
|
|
-T --template TEMPLATE display with template (EXPERIMENTAL)
|
2010-09-03 13:19:50 +04:00
|
|
|
|
2018-10-15 19:35:15 +03:00
|
|
|
Global options ([+] can be repeated):
|
2011-09-21 22:00:48 +04:00
|
|
|
|
2018-03-20 02:20:55 +03:00
|
|
|
-R --repository REPO repository root directory or name of overlay bundle
|
|
|
|
file
|
|
|
|
--cwd DIR change working directory
|
|
|
|
-y --noninteractive do not prompt, automatically pick the first choice
|
|
|
|
for all prompts
|
|
|
|
-q --quiet suppress output
|
|
|
|
-v --verbose enable additional output
|
|
|
|
--color TYPE when to colorize (boolean, always, auto, never, or
|
|
|
|
debug)
|
|
|
|
--config CONFIG [+] set/override config option (use
|
|
|
|
'section.name=value')
|
|
|
|
--configfile FILE [+] enables the given config file
|
|
|
|
--debug enable debugging output
|
|
|
|
--debugger start debugger
|
|
|
|
--encoding ENCODE set the charset encoding (default: ascii)
|
|
|
|
--encodingmode MODE set the charset encoding mode (default: strict)
|
|
|
|
--traceback always print a traceback on exception
|
|
|
|
--time time how long the command takes
|
|
|
|
--profile print command execution profile
|
|
|
|
--version output version information and exit
|
|
|
|
-h --help display help and exit
|
|
|
|
--hidden consider hidden changesets
|
|
|
|
--pager TYPE when to paginate (boolean, always, auto, or never)
|
|
|
|
(default: auto)
|
2010-09-03 13:19:50 +04:00
|
|
|
|
2014-07-09 06:57:54 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-09-03 13:19:50 +04:00
|
|
|
$ hg --debug help debugextension
|
2015-09-10 17:53:07 +03:00
|
|
|
hg debugextensions
|
2010-09-03 13:19:50 +04:00
|
|
|
|
2015-09-10 17:53:07 +03:00
|
|
|
show information about active extensions
|
|
|
|
|
2018-10-15 19:35:15 +03:00
|
|
|
Options:
|
2010-09-03 13:19:50 +04:00
|
|
|
|
2018-01-23 23:08:47 +03:00
|
|
|
--excludedefault exclude extensions marked as default-on
|
2015-09-10 17:53:07 +03:00
|
|
|
-T --template TEMPLATE display with template (EXPERIMENTAL)
|
2010-09-03 13:19:50 +04:00
|
|
|
|
2018-10-15 19:35:15 +03:00
|
|
|
Global options ([+] can be repeated):
|
2011-09-21 22:00:48 +04:00
|
|
|
|
2018-03-20 02:20:55 +03:00
|
|
|
-R --repository REPO repository root directory or name of overlay bundle
|
|
|
|
file
|
|
|
|
--cwd DIR change working directory
|
|
|
|
-y --noninteractive do not prompt, automatically pick the first choice
|
|
|
|
for all prompts
|
|
|
|
-q --quiet suppress output
|
|
|
|
-v --verbose enable additional output
|
|
|
|
--color TYPE when to colorize (boolean, always, auto, never, or
|
|
|
|
debug)
|
|
|
|
--config CONFIG [+] set/override config option (use
|
|
|
|
'section.name=value')
|
|
|
|
--configfile FILE [+] enables the given config file
|
|
|
|
--debug enable debugging output
|
|
|
|
--debugger start debugger
|
|
|
|
--encoding ENCODE set the charset encoding (default: ascii)
|
|
|
|
--encodingmode MODE set the charset encoding mode (default: strict)
|
|
|
|
--traceback always print a traceback on exception
|
|
|
|
--time time how long the command takes
|
|
|
|
--profile print command execution profile
|
|
|
|
--version output version information and exit
|
|
|
|
-h --help display help and exit
|
|
|
|
--hidden consider hidden changesets
|
|
|
|
--pager TYPE when to paginate (boolean, always, auto, or never)
|
|
|
|
(default: auto)
|
2014-07-09 06:57:54 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-09-03 13:19:50 +04:00
|
|
|
$ echo 'debugextension = !' >> $HGRCPATH
|
2015-11-30 23:45:07 +03:00
|
|
|
|
2010-01-20 21:24:20 +03:00
|
|
|
Extension module help vs command help:
|
|
|
|
|
|
|
|
$ echo 'extdiff =' >> $HGRCPATH
|
|
|
|
$ hg help extdiff
|
|
|
|
hg extdiff [OPT]... [FILE]...
|
|
|
|
|
|
|
|
use external program to diff repository (or selected files)
|
|
|
|
|
|
|
|
Show differences between revisions for the specified files, using an
|
|
|
|
external program. The default program used is diff, with default options
|
|
|
|
"-Npru".
|
|
|
|
|
|
|
|
To select a different program, use the -p/--program option. The program
|
|
|
|
will be passed the names of two directories to compare. To pass additional
|
|
|
|
options to the program, use -o/--option. These will be passed before the
|
|
|
|
names of the directories to compare.
|
|
|
|
|
|
|
|
When two revision arguments are given, then changes are shown between
|
|
|
|
those revisions. If only one revision is specified then that revision is
|
|
|
|
compared to the working directory, and, when no revisions are specified,
|
|
|
|
the working directory files are compared to its parent.
|
|
|
|
|
2016-09-21 02:47:46 +03:00
|
|
|
(use 'hg help -e extdiff' to show help for the extdiff extension)
|
2011-05-10 15:19:05 +04:00
|
|
|
|
2018-10-15 19:35:15 +03:00
|
|
|
Options ([+] can be repeated):
|
2010-01-20 21:24:20 +03:00
|
|
|
|
2011-09-21 22:00:48 +04:00
|
|
|
-p --program CMD comparison program to run
|
|
|
|
-o --option OPT [+] pass option to comparison program
|
|
|
|
-r --rev REV [+] revision
|
|
|
|
-c --change REV change made by revision
|
help: backout 6f89f03ad369 (mark boolean flags with [no-] in help) for now
The ability to negate any boolean flags itself is great, but I think we are not
ready to expose the help side of it yet.
First, while there exist a handful of such flags whose default value can be
changed (eg: git diff, patchwork confirmation), there is only a few of them. The
users who benefit the most from this change are alias users and large
installation that can deploy extension to change behavior (eg: facebook
tweakdefault). So the majority of user who will be affected by a large change
to command help that is not yet relevant to them. (I expect this to become
relevant when ui.progressive start to exists).
Below is an example of the impact of the new help on 'hg help diff':
-r --rev REV [+] revision
-c --change REV change made by revision
-a --[no-]text treat all files as text
-g --[no-]git use git extended diff format
--[no-]nodates omit dates from diff headers
--[no-]noprefix omit a/ and b/ prefixes from filenames
-p --[no-]show-function show which function each change is in
--[no-]reverse produce a diff that undoes the changes
-w --[no-]ignore-all-space ignore white space when comparing lines
-b --[no-]ignore-space-change ignore changes in the amount of white space
-B --[no-]ignore-blank-lines ignore changes whose lines are all blank
-U --unified NUM number of lines of context to show
--[no-]stat output diffstat-style summary of changes
--root DIR produce diffs relative to subdirectory
-I --include PATTERN [+] include names matching the given patterns
-X --exclude PATTERN [+] exclude names matching the given patterns
-S --[no-]subrepos recurse into subrepositories
Another issue with the current state of help, the default value for the
flag is not conveyed to the user. For example in the 'backout' help, there is
no real distinction between "--[no-]backup" (default to True) and "--[no-]keep"
(default) to False:
--[no-]backup no backups
--[no-]keep do not modify working directory during strip
In addition, I've discussed with Augie Fackler and the last batch of the work on
this have burned him out quite some. Therefore he is not intending to perform
any more work on this topic. Quoting him, he would rather see the help part
backed out than spending more time on it.
I do not think we are ready to expose this to users in 4.0 (freeze in a week),
especially because we cannot expect quick improvement on these aspect as this
topic no longer have an owner. We should be able to reintroduce that change in
the future when someone get back on it and the main issues are solves:
* Introduction of ui.progressive makes it relevant for a majority of user,
* Current default value are efficiently conveyed to the user.
(In addition, the excerpt from diff help show that we still have some issue with
some negative option like '--nodates' so further improvement are probably
welcome there.)
2016-10-09 04:11:18 +03:00
|
|
|
--patch compare patches for two revisions
|
2011-09-21 22:00:48 +04:00
|
|
|
-I --include PATTERN [+] include names matching the given patterns
|
|
|
|
-X --exclude PATTERN [+] exclude names matching the given patterns
|
help: backout 6f89f03ad369 (mark boolean flags with [no-] in help) for now
The ability to negate any boolean flags itself is great, but I think we are not
ready to expose the help side of it yet.
First, while there exist a handful of such flags whose default value can be
changed (eg: git diff, patchwork confirmation), there is only a few of them. The
users who benefit the most from this change are alias users and large
installation that can deploy extension to change behavior (eg: facebook
tweakdefault). So the majority of user who will be affected by a large change
to command help that is not yet relevant to them. (I expect this to become
relevant when ui.progressive start to exists).
Below is an example of the impact of the new help on 'hg help diff':
-r --rev REV [+] revision
-c --change REV change made by revision
-a --[no-]text treat all files as text
-g --[no-]git use git extended diff format
--[no-]nodates omit dates from diff headers
--[no-]noprefix omit a/ and b/ prefixes from filenames
-p --[no-]show-function show which function each change is in
--[no-]reverse produce a diff that undoes the changes
-w --[no-]ignore-all-space ignore white space when comparing lines
-b --[no-]ignore-space-change ignore changes in the amount of white space
-B --[no-]ignore-blank-lines ignore changes whose lines are all blank
-U --unified NUM number of lines of context to show
--[no-]stat output diffstat-style summary of changes
--root DIR produce diffs relative to subdirectory
-I --include PATTERN [+] include names matching the given patterns
-X --exclude PATTERN [+] exclude names matching the given patterns
-S --[no-]subrepos recurse into subrepositories
Another issue with the current state of help, the default value for the
flag is not conveyed to the user. For example in the 'backout' help, there is
no real distinction between "--[no-]backup" (default to True) and "--[no-]keep"
(default) to False:
--[no-]backup no backups
--[no-]keep do not modify working directory during strip
In addition, I've discussed with Augie Fackler and the last batch of the work on
this have burned him out quite some. Therefore he is not intending to perform
any more work on this topic. Quoting him, he would rather see the help part
backed out than spending more time on it.
I do not think we are ready to expose this to users in 4.0 (freeze in a week),
especially because we cannot expect quick improvement on these aspect as this
topic no longer have an owner. We should be able to reintroduce that change in
the future when someone get back on it and the main issues are solves:
* Introduction of ui.progressive makes it relevant for a majority of user,
* Current default value are efficiently conveyed to the user.
(In addition, the excerpt from diff help show that we still have some issue with
some negative option like '--nodates' so further improvement are probably
welcome there.)
2016-10-09 04:11:18 +03:00
|
|
|
-S --subrepos recurse into subrepositories
|
2010-01-20 21:24:20 +03:00
|
|
|
|
2014-08-12 12:01:37 +04:00
|
|
|
(some details hidden, use --verbose to show complete help)
|
2010-01-20 21:24:20 +03:00
|
|
|
|
2014-07-09 06:57:54 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-20 21:24:20 +03:00
|
|
|
$ hg help --extension extdiff
|
|
|
|
extdiff extension - command to allow external programs to compare revisions
|
|
|
|
|
|
|
|
The extdiff Mercurial extension allows you to use external programs to compare
|
|
|
|
revisions, or revision with working directory. The external diff programs are
|
|
|
|
called with a configurable set of options and two non-option arguments: paths
|
|
|
|
to directories containing snapshots of files to compare.
|
|
|
|
|
2011-05-15 21:00:22 +04:00
|
|
|
The extdiff extension also allows you to configure new diff commands, so you
|
2016-01-12 09:03:36 +03:00
|
|
|
do not need to type 'hg extdiff -p kdiff3' always.
|
2010-01-20 21:24:20 +03:00
|
|
|
|
|
|
|
[extdiff]
|
|
|
|
# add new command that runs GNU diff(1) in 'context diff' mode
|
|
|
|
cdiff = gdiff -Nprc5
|
|
|
|
## or the old way:
|
|
|
|
#cmd.cdiff = gdiff
|
|
|
|
#opts.cdiff = -Nprc5
|
|
|
|
|
2014-11-01 04:34:55 +03:00
|
|
|
# add new command called meld, runs meld (no need to name twice). If
|
|
|
|
# the meld executable is not available, the meld tool in [merge-tools]
|
|
|
|
# will be used, if available
|
2010-01-20 21:24:20 +03:00
|
|
|
meld =
|
|
|
|
|
|
|
|
# add new command called vimdiff, runs gvimdiff with DirDiff plugin
|
|
|
|
# (see http://www.vim.org/scripts/script.php?script_id=102) Non
|
|
|
|
# English user, be sure to put "let g:DirDiffDynamicDiffText = 1" in
|
|
|
|
# your .vimrc
|
2012-03-12 12:39:30 +04:00
|
|
|
vimdiff = gvim -f "+next" \
|
|
|
|
"+execute 'DirDiff' fnameescape(argv(0)) fnameescape(argv(1))"
|
2010-01-20 21:24:20 +03:00
|
|
|
|
|
|
|
Tool arguments can include variables that are expanded at runtime:
|
|
|
|
|
|
|
|
$parent1, $plabel1 - filename, descriptive label of first parent
|
|
|
|
$child, $clabel - filename, descriptive label of child revision
|
|
|
|
$parent2, $plabel2 - filename, descriptive label of second parent
|
|
|
|
$root - repository root
|
|
|
|
$parent is an alias for $parent1.
|
|
|
|
|
|
|
|
The extdiff extension will look in your [diff-tools] and [merge-tools]
|
|
|
|
sections for diff tool arguments, when none are specified in [extdiff].
|
|
|
|
|
|
|
|
[extdiff]
|
|
|
|
kdiff3 =
|
|
|
|
|
|
|
|
[diff-tools]
|
|
|
|
kdiff3.diffargs=--L1 '$plabel1' --L2 '$clabel' $parent $child
|
|
|
|
|
2016-01-12 09:03:36 +03:00
|
|
|
You can use -I/-X and list of file or directory names like normal 'hg diff'
|
2010-01-20 21:24:20 +03:00
|
|
|
command. The extdiff extension makes snapshots of only needed files, so
|
|
|
|
running the external diff program will actually be pretty fast (at least
|
|
|
|
faster than having to compare the entire tree).
|
|
|
|
|
2018-10-15 19:35:15 +03:00
|
|
|
Commands:
|
2010-01-20 21:24:20 +03:00
|
|
|
|
help: format command and option list help using RST
This patch changes the function which generates help text about commands and
options to use RST formatting. Tables describing options have been formatted
using RST table markup for some time already, so their appearance does not
change. Command lists, however, change appearance.
To format non-verbose command lists, RST field list markup was chosen, because
it resembles the old format:
<http://docutils.sourceforge.net/docs/user/rst/quickref.html#field-lists>
In the old (hand-coded) format of non-verbose command lists, the left column is
12 characters wide. Our minirst implementation formats field lists with a left
column 14 characters wide, so this patch changes the appearance of help output
correspondingly:
<http://markmail.org/message/krl4cxopsnii7s6z?q=mercurial+reinert+from:%22Olav+Reinert%22&page=2>
The minirst markup most closely resembling the old verbose command lists is
definition lists. But using it would cause a blank line to be inserted between
each command definition, making the output excessively long, and no more
useful than before. To avoid this, I chose to use field lists also for verbose
command help, resulting in output like this example:
add add the specified files on the next commit
annotate, blame
show changeset information by line for each file
clone make a copy of an existing repository
commit, ci commit the specified files or all outstanding changes
diff diff repository (or selected files)
export dump the header and diffs for one or more changesets
forget forget the specified files on the next commit
init create a new repository in the given directory
log, history show revision history of entire repository or files
merge merge working directory with another revision
phase set or show the current phase name
pull pull changes from the specified source
push push changes to the specified destination
qdiff diff of the current patch and subsequent modifications
qinit init a new queue repository (DEPRECATED)
qnew create a new patch
qpop pop the current patch off the stack
qpush push the next patch onto the stack
qrefresh update the current patch
remove, rm remove the specified files on the next commit
serve start stand-alone webserver
status, st show changed files in the working directory
summary, sum summarize working directory state
update, up, checkout, co
update working directory (or switch revisions)
This change is a move towards generating all help text as a list of strings
marked up with RST.
2012-06-02 13:25:40 +04:00
|
|
|
extdiff use external program to diff repository (or selected files)
|
2010-01-20 21:24:20 +03:00
|
|
|
|
2014-07-09 06:57:54 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-20 21:24:20 +03:00
|
|
|
$ echo 'extdiff = !' >> $HGRCPATH
|
|
|
|
|
2011-05-10 16:42:53 +04:00
|
|
|
Test help topic with same name as extension
|
|
|
|
|
|
|
|
$ cat > multirevs.py <<EOF
|
2016-01-09 17:07:20 +03:00
|
|
|
> from mercurial import commands, registrar
|
2014-05-05 09:48:07 +04:00
|
|
|
> cmdtable = {}
|
2016-01-09 17:07:20 +03:00
|
|
|
> command = registrar.command(cmdtable)
|
2011-05-10 16:42:53 +04:00
|
|
|
> """multirevs extension
|
|
|
|
> Big multi-line module docstring."""
|
2017-06-25 05:50:05 +03:00
|
|
|
> @command(b'multirevs', [], 'ARG', norepo=True)
|
2011-05-10 16:42:53 +04:00
|
|
|
> def multirevs(ui, repo, arg, *args, **opts):
|
|
|
|
> """multirevs command"""
|
|
|
|
> pass
|
|
|
|
> EOF
|
|
|
|
$ echo "multirevs = multirevs.py" >> $HGRCPATH
|
|
|
|
|
2016-12-16 20:48:14 +03:00
|
|
|
$ hg help multirevs | tail
|
2017-11-01 06:09:29 +03:00
|
|
|
used):
|
2011-05-10 16:42:53 +04:00
|
|
|
|
2017-01-12 10:13:00 +03:00
|
|
|
hg update :@
|
2011-05-10 16:42:53 +04:00
|
|
|
|
2017-01-12 10:13:00 +03:00
|
|
|
- Show diff between tags 1.3 and 1.5 (this works because the first and the
|
|
|
|
last revisions of the revset are used):
|
2011-05-10 16:42:53 +04:00
|
|
|
|
2017-01-12 10:13:00 +03:00
|
|
|
hg diff -r 1.3::1.5
|
2011-05-10 16:42:53 +04:00
|
|
|
|
2016-09-21 02:47:46 +03:00
|
|
|
use 'hg help -c multirevs' to see help for the multirevs command
|
2011-05-10 16:42:53 +04:00
|
|
|
|
2014-07-09 06:57:54 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-05-10 16:42:53 +04:00
|
|
|
$ hg help -c multirevs
|
|
|
|
hg multirevs ARG
|
|
|
|
|
|
|
|
multirevs command
|
|
|
|
|
2014-08-12 12:01:37 +04:00
|
|
|
(some details hidden, use --verbose to show complete help)
|
2011-05-10 16:42:53 +04:00
|
|
|
|
2014-07-09 06:57:54 +04:00
|
|
|
|
|
|
|
|
2011-05-10 16:42:53 +04:00
|
|
|
$ hg multirevs
|
|
|
|
hg multirevs: invalid arguments
|
|
|
|
hg multirevs ARG
|
|
|
|
|
|
|
|
multirevs command
|
|
|
|
|
2016-09-21 02:47:46 +03:00
|
|
|
(use 'hg multirevs -h' to show more help)
|
2011-05-10 16:42:53 +04:00
|
|
|
[255]
|
|
|
|
|
2014-07-09 06:57:54 +04:00
|
|
|
|
|
|
|
|
2011-05-10 16:42:53 +04:00
|
|
|
$ echo "multirevs = !" >> $HGRCPATH
|
|
|
|
|
2010-09-24 12:13:49 +04:00
|
|
|
Issue811: Problem loading extensions twice (by site and by user)
|
2010-09-03 13:19:50 +04:00
|
|
|
|
2014-11-04 17:41:46 +03:00
|
|
|
$ cat <<EOF >> $HGRCPATH
|
|
|
|
> strip =
|
2018-07-30 18:46:11 +03:00
|
|
|
> hgext.strip =
|
|
|
|
> hgext/strip =
|
2014-11-04 17:41:46 +03:00
|
|
|
> EOF
|
2010-09-03 13:19:50 +04:00
|
|
|
|
2018-01-23 23:08:38 +03:00
|
|
|
$ hg debugextensions | egrep -v "(default)"
|
2015-09-10 17:53:07 +03:00
|
|
|
strip
|
2010-09-03 13:19:50 +04:00
|
|
|
|
2014-12-22 05:20:50 +03:00
|
|
|
For extensions, which name matches one of its commands, help
|
|
|
|
message should ask '-v -e' to get list of built-in aliases
|
|
|
|
along with extension help itself
|
|
|
|
|
|
|
|
$ mkdir $TESTTMP/d
|
|
|
|
$ cat > $TESTTMP/d/dodo.py <<EOF
|
|
|
|
> """
|
|
|
|
> This is an awesome 'dodo' extension. It does nothing and
|
|
|
|
> writes 'Foo foo'
|
|
|
|
> """
|
2016-01-09 17:07:20 +03:00
|
|
|
> from mercurial import commands, registrar
|
2014-12-22 05:20:50 +03:00
|
|
|
> cmdtable = {}
|
2016-01-09 17:07:20 +03:00
|
|
|
> command = registrar.command(cmdtable)
|
2017-06-25 05:50:05 +03:00
|
|
|
> @command(b'dodo', [], 'hg dodo')
|
2014-12-22 05:20:50 +03:00
|
|
|
> def dodo(ui, *args, **kwargs):
|
|
|
|
> """Does nothing"""
|
|
|
|
> ui.write("I do nothing. Yay\\n")
|
2017-06-25 05:50:05 +03:00
|
|
|
> @command(b'foofoo', [], 'hg foofoo')
|
2014-12-22 05:20:50 +03:00
|
|
|
> def foofoo(ui, *args, **kwargs):
|
|
|
|
> """Writes 'Foo foo'"""
|
|
|
|
> ui.write("Foo foo\\n")
|
|
|
|
> EOF
|
|
|
|
$ dodopath=$TESTTMP/d/dodo.py
|
|
|
|
|
|
|
|
$ echo "dodo = $dodopath" >> $HGRCPATH
|
|
|
|
|
2018-10-15 19:35:15 +03:00
|
|
|
Make sure that '-e' prints help for the extension.
|
2014-12-22 05:20:50 +03:00
|
|
|
$ hg help -e dodo
|
|
|
|
dodo extension -
|
|
|
|
|
|
|
|
This is an awesome 'dodo' extension. It does nothing and writes 'Foo foo'
|
|
|
|
|
2018-10-15 19:35:15 +03:00
|
|
|
Commands:
|
2014-12-22 05:20:50 +03:00
|
|
|
|
|
|
|
dodo Does nothing
|
|
|
|
foofoo Writes 'Foo foo'
|
|
|
|
|
2018-10-15 19:35:15 +03:00
|
|
|
Make sure that '-v -e' prints help for the extension.
|
2014-12-22 05:20:50 +03:00
|
|
|
$ hg help -v -e dodo
|
|
|
|
dodo extension -
|
|
|
|
|
|
|
|
This is an awesome 'dodo' extension. It does nothing and writes 'Foo foo'
|
|
|
|
|
2018-10-15 19:35:15 +03:00
|
|
|
Commands:
|
2014-12-22 05:20:50 +03:00
|
|
|
|
|
|
|
dodo Does nothing
|
|
|
|
foofoo Writes 'Foo foo'
|
|
|
|
|
2018-10-15 19:35:15 +03:00
|
|
|
Make sure that single '-v' option shows help and global options for the 'dodo' command
|
2014-12-22 05:20:50 +03:00
|
|
|
$ hg help -v dodo
|
|
|
|
hg dodo
|
|
|
|
|
|
|
|
Does nothing
|
|
|
|
|
2016-09-21 02:47:46 +03:00
|
|
|
(use 'hg help -e dodo' to show help for the dodo extension)
|
2014-12-22 05:20:50 +03:00
|
|
|
|
2018-10-15 19:35:15 +03:00
|
|
|
Global options ([+] can be repeated):
|
2014-12-22 05:20:50 +03:00
|
|
|
|
2018-03-20 02:20:55 +03:00
|
|
|
-R --repository REPO repository root directory or name of overlay bundle
|
|
|
|
file
|
|
|
|
--cwd DIR change working directory
|
|
|
|
-y --noninteractive do not prompt, automatically pick the first choice
|
|
|
|
for all prompts
|
|
|
|
-q --quiet suppress output
|
|
|
|
-v --verbose enable additional output
|
|
|
|
--color TYPE when to colorize (boolean, always, auto, never, or
|
|
|
|
debug)
|
|
|
|
--config CONFIG [+] set/override config option (use
|
|
|
|
'section.name=value')
|
|
|
|
--configfile FILE [+] enables the given config file
|
|
|
|
--debug enable debugging output
|
|
|
|
--debugger start debugger
|
|
|
|
--encoding ENCODE set the charset encoding (default: ascii)
|
|
|
|
--encodingmode MODE set the charset encoding mode (default: strict)
|
|
|
|
--traceback always print a traceback on exception
|
|
|
|
--time time how long the command takes
|
|
|
|
--profile print command execution profile
|
|
|
|
--version output version information and exit
|
|
|
|
-h --help display help and exit
|
|
|
|
--hidden consider hidden changesets
|
|
|
|
--pager TYPE when to paginate (boolean, always, auto, or never)
|
|
|
|
(default: auto)
|
2014-12-22 05:20:50 +03:00
|
|
|
|
|
|
|
In case when extension name doesn't match any of its commands,
|
|
|
|
help message should ask for '-v' to get list of built-in aliases
|
|
|
|
along with extension help
|
|
|
|
$ cat > $TESTTMP/d/dudu.py <<EOF
|
|
|
|
> """
|
|
|
|
> This is an awesome 'dudu' extension. It does something and
|
|
|
|
> also writes 'Beep beep'
|
|
|
|
> """
|
2016-01-09 17:07:20 +03:00
|
|
|
> from mercurial import commands, registrar
|
2014-12-22 05:20:50 +03:00
|
|
|
> cmdtable = {}
|
2016-01-09 17:07:20 +03:00
|
|
|
> command = registrar.command(cmdtable)
|
2017-06-25 05:50:05 +03:00
|
|
|
> @command(b'something', [], 'hg something')
|
2014-12-22 05:20:50 +03:00
|
|
|
> def something(ui, *args, **kwargs):
|
|
|
|
> """Does something"""
|
|
|
|
> ui.write("I do something. Yaaay\\n")
|
2017-06-25 05:50:05 +03:00
|
|
|
> @command(b'beep', [], 'hg beep')
|
2014-12-22 05:20:50 +03:00
|
|
|
> def beep(ui, *args, **kwargs):
|
|
|
|
> """Writes 'Beep beep'"""
|
|
|
|
> ui.write("Beep beep\\n")
|
|
|
|
> EOF
|
|
|
|
$ dudupath=$TESTTMP/d/dudu.py
|
|
|
|
|
|
|
|
$ echo "dudu = $dudupath" >> $HGRCPATH
|
|
|
|
|
|
|
|
$ hg help -e dudu
|
|
|
|
dudu extension -
|
|
|
|
|
|
|
|
This is an awesome 'dudu' extension. It does something and also writes 'Beep
|
|
|
|
beep'
|
|
|
|
|
2018-10-15 19:35:15 +03:00
|
|
|
Commands:
|
2014-12-22 05:20:50 +03:00
|
|
|
|
|
|
|
beep Writes 'Beep beep'
|
|
|
|
something Does something
|
|
|
|
|
|
|
|
In case when extension name doesn't match any of its commands,
|
|
|
|
help options '-v' and '-v -e' should be equivalent
|
|
|
|
$ hg help -v dudu
|
|
|
|
dudu extension -
|
|
|
|
|
|
|
|
This is an awesome 'dudu' extension. It does something and also writes 'Beep
|
|
|
|
beep'
|
|
|
|
|
2018-10-15 19:35:15 +03:00
|
|
|
Commands:
|
2014-12-22 05:20:50 +03:00
|
|
|
|
|
|
|
beep Writes 'Beep beep'
|
|
|
|
something Does something
|
|
|
|
|
|
|
|
$ hg help -v -e dudu
|
|
|
|
dudu extension -
|
|
|
|
|
|
|
|
This is an awesome 'dudu' extension. It does something and also writes 'Beep
|
|
|
|
beep'
|
|
|
|
|
2018-10-15 19:35:15 +03:00
|
|
|
Commands:
|
2014-12-22 05:20:50 +03:00
|
|
|
|
|
|
|
beep Writes 'Beep beep'
|
|
|
|
something Does something
|
|
|
|
|
2010-09-03 13:19:50 +04:00
|
|
|
Disabled extension commands:
|
|
|
|
|
2013-09-21 16:33:29 +04:00
|
|
|
$ ORGHGRCPATH=$HGRCPATH
|
2010-09-03 13:19:50 +04:00
|
|
|
$ HGRCPATH=
|
|
|
|
$ export HGRCPATH
|
|
|
|
$ hg help email
|
|
|
|
'email' is provided by the following extension:
|
|
|
|
|
2012-01-11 21:08:25 +04:00
|
|
|
patchbomb command to send changesets as (a series of) patch emails
|
2010-09-03 13:19:50 +04:00
|
|
|
|
2016-09-21 02:47:46 +03:00
|
|
|
(use 'hg help extensions' for information on enabling extensions)
|
2014-07-09 06:57:54 +04:00
|
|
|
|
|
|
|
|
2010-09-03 13:19:50 +04:00
|
|
|
$ hg churn
|
|
|
|
hg: unknown command 'churn'
|
|
|
|
'churn' is provided by the following extension:
|
|
|
|
|
2012-01-11 21:08:25 +04:00
|
|
|
churn command to display statistics about repository history
|
2010-09-03 13:19:50 +04:00
|
|
|
|
2016-09-21 02:47:46 +03:00
|
|
|
(use 'hg help extensions' for information on enabling extensions)
|
2010-09-17 02:51:32 +04:00
|
|
|
[255]
|
2010-09-03 13:19:50 +04:00
|
|
|
|
2014-07-09 06:57:54 +04:00
|
|
|
|
|
|
|
|
2010-09-03 13:19:50 +04:00
|
|
|
Disabled extensions:
|
|
|
|
|
|
|
|
$ hg help churn
|
|
|
|
churn extension - command to display statistics about repository history
|
|
|
|
|
2016-09-21 02:47:46 +03:00
|
|
|
(use 'hg help extensions' for information on enabling extensions)
|
2014-07-09 06:57:54 +04:00
|
|
|
|
2010-09-03 13:19:50 +04:00
|
|
|
$ hg help patchbomb
|
|
|
|
patchbomb extension - command to send changesets as (a series of) patch emails
|
|
|
|
|
2016-11-06 04:24:31 +03:00
|
|
|
The series is started off with a "[PATCH 0 of N]" introduction, which
|
|
|
|
describes the series as a whole.
|
|
|
|
|
|
|
|
Each patch email has a Subject line of "[PATCH M of N] ...", using the first
|
|
|
|
line of the changeset description as the subject text. The message contains
|
|
|
|
two or three body parts:
|
|
|
|
|
|
|
|
- The changeset description.
|
|
|
|
- [Optional] The result of running diffstat on the patch.
|
|
|
|
- The patch itself, as generated by 'hg export'.
|
|
|
|
|
|
|
|
Each message refers to the first in the series using the In-Reply-To and
|
|
|
|
References headers, so they will show up as a sequence in threaded mail and
|
|
|
|
news readers, and in mail archives.
|
|
|
|
|
|
|
|
To configure other defaults, add a section like this to your configuration
|
|
|
|
file:
|
|
|
|
|
|
|
|
[email]
|
|
|
|
from = My Name <my@email>
|
|
|
|
to = recipient1, recipient2, ...
|
|
|
|
cc = cc1, cc2, ...
|
|
|
|
bcc = bcc1, bcc2, ...
|
|
|
|
reply-to = address1, address2, ...
|
|
|
|
|
|
|
|
Use "[patchbomb]" as configuration section name if you need to override global
|
|
|
|
"[email]" address settings.
|
|
|
|
|
|
|
|
Then you can use the 'hg email' command to mail a series of changesets as a
|
|
|
|
patchbomb.
|
|
|
|
|
|
|
|
You can also either configure the method option in the email section to be a
|
|
|
|
sendmail compatible mailer or fill out the [smtp] section so that the
|
|
|
|
patchbomb extension can automatically send patchbombs directly from the
|
|
|
|
commandline. See the [email] and [smtp] sections in hgrc(5) for details.
|
|
|
|
|
|
|
|
By default, 'hg email' will prompt for a "To" or "CC" header if you do not
|
|
|
|
supply one via configuration or the command line. You can override this to
|
|
|
|
never prompt by configuring an empty value:
|
|
|
|
|
|
|
|
[email]
|
|
|
|
cc =
|
|
|
|
|
|
|
|
You can control the default inclusion of an introduction message with the
|
|
|
|
"patchbomb.intro" configuration option. The configuration is always
|
|
|
|
overwritten by command line flags like --intro and --desc:
|
|
|
|
|
|
|
|
[patchbomb]
|
|
|
|
intro=auto # include introduction message if more than 1 patch (default)
|
|
|
|
intro=never # never include an introduction message
|
|
|
|
intro=always # always include an introduction message
|
|
|
|
|
2017-02-25 12:41:00 +03:00
|
|
|
You can specify a template for flags to be added in subject prefixes. Flags
|
|
|
|
specified by --flag option are exported as "{flags}" keyword:
|
|
|
|
|
|
|
|
[patchbomb]
|
|
|
|
flagtemplate = "{separate(' ',
|
|
|
|
ifeq(branch, 'default', '', branch|upper),
|
|
|
|
flags)}"
|
|
|
|
|
2016-11-06 04:24:31 +03:00
|
|
|
You can set patchbomb to always ask for confirmation by setting
|
|
|
|
"patchbomb.confirm" to true.
|
|
|
|
|
2016-09-21 02:47:46 +03:00
|
|
|
(use 'hg help extensions' for information on enabling extensions)
|
2010-09-03 13:19:50 +04:00
|
|
|
|
2014-07-09 06:57:54 +04:00
|
|
|
|
2010-09-03 13:19:50 +04:00
|
|
|
Broken disabled extension and command:
|
|
|
|
|
|
|
|
$ mkdir hgext
|
|
|
|
$ echo > hgext/__init__.py
|
|
|
|
$ cat > hgext/broken.py <<EOF
|
|
|
|
> "broken extension'
|
|
|
|
> EOF
|
|
|
|
$ cat > path.py <<EOF
|
|
|
|
> import os, sys
|
|
|
|
> sys.path.insert(0, os.environ['HGEXTPATH'])
|
|
|
|
> EOF
|
|
|
|
$ HGEXTPATH=`pwd`
|
|
|
|
$ export HGEXTPATH
|
|
|
|
|
2018-01-15 01:53:52 +03:00
|
|
|
$ hg --config extensions.path=./path.py help broken 2>&1 | grep -v "failed to import"
|
2010-09-03 13:19:50 +04:00
|
|
|
broken extension - (no help text available)
|
|
|
|
|
2016-09-21 02:47:46 +03:00
|
|
|
(use 'hg help extensions' for information on enabling extensions)
|
2010-09-03 13:19:50 +04:00
|
|
|
|
2014-07-09 06:57:54 +04:00
|
|
|
|
2010-12-26 02:43:49 +03:00
|
|
|
$ cat > hgext/forest.py <<EOF
|
|
|
|
> cmdtable = None
|
|
|
|
> EOF
|
2018-01-15 01:53:52 +03:00
|
|
|
$ hg --config extensions.path=./path.py help foo 2>&1 | grep -v "failed to import"
|
2017-12-11 06:50:57 +03:00
|
|
|
warning: error finding commands in $TESTTMP/hgext/forest.py
|
2014-04-17 03:55:40 +04:00
|
|
|
abort: no such help topic: foo
|
2016-09-21 02:47:46 +03:00
|
|
|
(try 'hg help --keyword foo')
|
2012-05-17 01:18:07 +04:00
|
|
|
|
|
|
|
$ cat > throw.py <<EOF
|
2016-01-09 17:07:20 +03:00
|
|
|
> from mercurial import commands, registrar, util
|
2012-05-17 01:18:07 +04:00
|
|
|
> cmdtable = {}
|
2016-01-09 17:07:20 +03:00
|
|
|
> command = registrar.command(cmdtable)
|
2012-05-17 01:18:07 +04:00
|
|
|
> class Bogon(Exception): pass
|
2017-06-25 05:50:05 +03:00
|
|
|
> @command(b'throw', [], 'hg throw', norepo=True)
|
2012-05-17 01:18:07 +04:00
|
|
|
> def throw(ui, **opts):
|
|
|
|
> """throws an exception"""
|
|
|
|
> raise Bogon()
|
|
|
|
> EOF
|
2015-01-16 06:47:06 +03:00
|
|
|
|
2012-05-17 01:18:07 +04:00
|
|
|
No declared supported version, extension complains:
|
|
|
|
$ hg --config extensions.throw=throw.py throw 2>&1 | egrep '^\*\*'
|
2018-01-15 01:53:52 +03:00
|
|
|
** Unknown exception encountered with possibly-broken third-party extension throw.
|
2012-05-17 01:18:07 +04:00
|
|
|
** Please disable throw and try your action again.
|
|
|
|
** If that fixes the bug please report it to the extension author.
|
|
|
|
** Python * (glob)
|
|
|
|
** Mercurial Distributed SCM * (glob)
|
2018-01-15 01:53:52 +03:00
|
|
|
** Extensions loaded: throw, * (glob)
|
2015-01-16 06:47:06 +03:00
|
|
|
|
2013-01-04 22:06:42 +04:00
|
|
|
empty declaration of supported version, extension complains:
|
|
|
|
$ echo "testedwith = ''" >> throw.py
|
|
|
|
$ hg --config extensions.throw=throw.py throw 2>&1 | egrep '^\*\*'
|
2018-01-15 01:53:52 +03:00
|
|
|
** Unknown exception encountered with possibly-broken third-party extension throw.
|
2013-01-04 22:06:42 +04:00
|
|
|
** Please disable throw and try your action again.
|
|
|
|
** If that fixes the bug please report it to the extension author.
|
|
|
|
** Python * (glob)
|
|
|
|
** Mercurial Distributed SCM (*) (glob)
|
2018-01-15 01:53:52 +03:00
|
|
|
** Extensions loaded: throw, * (glob)
|
2015-01-16 06:47:06 +03:00
|
|
|
|
2012-05-17 01:18:07 +04:00
|
|
|
If the extension specifies a buglink, show that:
|
|
|
|
$ echo 'buglink = "http://example.com/bts"' >> throw.py
|
|
|
|
$ rm -f throw.pyc throw.pyo
|
2017-08-02 16:04:02 +03:00
|
|
|
$ rm -Rf __pycache__
|
2012-05-17 01:18:07 +04:00
|
|
|
$ hg --config extensions.throw=throw.py throw 2>&1 | egrep '^\*\*'
|
2018-01-15 01:53:52 +03:00
|
|
|
** Unknown exception encountered with possibly-broken third-party extension throw.
|
2012-05-17 01:18:07 +04:00
|
|
|
** Please disable throw and try your action again.
|
|
|
|
** If that fixes the bug please report it to http://example.com/bts
|
|
|
|
** Python * (glob)
|
|
|
|
** Mercurial Distributed SCM (*) (glob)
|
2018-01-15 01:53:52 +03:00
|
|
|
** Extensions loaded: throw, * (glob)
|
2015-01-16 06:47:06 +03:00
|
|
|
|
2012-05-17 01:18:07 +04:00
|
|
|
If the extensions declare outdated versions, accuse the older extension first:
|
2012-07-19 18:50:52 +04:00
|
|
|
$ echo "from mercurial import util" >> older.py
|
|
|
|
$ echo "util.version = lambda:'2.2'" >> older.py
|
2012-05-17 01:18:07 +04:00
|
|
|
$ echo "testedwith = '1.9.3'" >> older.py
|
|
|
|
$ echo "testedwith = '2.1.1'" >> throw.py
|
|
|
|
$ rm -f throw.pyc throw.pyo
|
2017-08-02 16:04:02 +03:00
|
|
|
$ rm -Rf __pycache__
|
2012-05-17 01:18:07 +04:00
|
|
|
$ hg --config extensions.throw=throw.py --config extensions.older=older.py \
|
2018-01-15 01:53:52 +03:00
|
|
|
> throw 2>&1 | egrep '^\*\*' | grep -v 'possibly-broken' | grep -v 'Please disable'
|
2012-05-17 01:18:07 +04:00
|
|
|
** If that fixes the bug please report it to the extension author.
|
|
|
|
** Python * (glob)
|
2012-07-19 23:20:56 +04:00
|
|
|
** Mercurial Distributed SCM (version 2.2)
|
2018-01-15 01:53:52 +03:00
|
|
|
** Extensions loaded: throw, older, * (glob)
|
2015-01-16 06:47:06 +03:00
|
|
|
|
2012-07-19 23:20:56 +04:00
|
|
|
One extension only tested with older, one only with newer versions:
|
2015-01-16 07:03:48 +03:00
|
|
|
$ echo "util.version = lambda:'2.1'" >> older.py
|
2012-07-19 23:20:56 +04:00
|
|
|
$ rm -f older.pyc older.pyo
|
2017-08-02 16:04:02 +03:00
|
|
|
$ rm -Rf __pycache__
|
2012-07-19 23:20:56 +04:00
|
|
|
$ hg --config extensions.throw=throw.py --config extensions.older=older.py \
|
2018-01-15 01:53:52 +03:00
|
|
|
> throw 2>&1 | egrep '^\*\*' | grep -v 'possibly-broken' | grep -v 'Please disable'
|
2012-07-19 23:20:56 +04:00
|
|
|
** If that fixes the bug please report it to the extension author.
|
|
|
|
** Python * (glob)
|
2015-01-16 07:03:48 +03:00
|
|
|
** Mercurial Distributed SCM (version 2.1)
|
2018-01-15 01:53:52 +03:00
|
|
|
** Extensions loaded: throw, older, * (glob)
|
2015-01-16 06:47:06 +03:00
|
|
|
|
2012-07-19 23:20:56 +04:00
|
|
|
Older extension is tested with current version, the other only with newer:
|
|
|
|
$ echo "util.version = lambda:'1.9.3'" >> older.py
|
|
|
|
$ rm -f older.pyc older.pyo
|
2017-08-02 16:04:02 +03:00
|
|
|
$ rm -Rf __pycache__
|
2012-07-19 23:20:56 +04:00
|
|
|
$ hg --config extensions.throw=throw.py --config extensions.older=older.py \
|
2018-01-15 01:53:52 +03:00
|
|
|
> throw 2>&1 | egrep '^\*\*' | grep -v 'possibly-broken' | grep -v 'Please disable'
|
|
|
|
** If that fixes the bug please report it to the extension author.
|
2012-07-19 23:20:56 +04:00
|
|
|
** Python * (glob)
|
|
|
|
** Mercurial Distributed SCM (version 1.9.3)
|
2018-01-15 01:53:52 +03:00
|
|
|
** Extensions loaded: throw, older, * (glob)
|
2012-05-17 01:18:07 +04:00
|
|
|
|
2015-09-11 22:45:19 +03:00
|
|
|
Ability to point to a different point
|
|
|
|
$ hg --config extensions.throw=throw.py --config extensions.older=older.py \
|
|
|
|
> --config ui.supportcontact='Your Local Goat Lenders' throw 2>&1 | egrep '^\*\*'
|
|
|
|
** unknown exception encountered, please report by visiting
|
|
|
|
** Your Local Goat Lenders
|
|
|
|
** Python * (glob)
|
|
|
|
** Mercurial Distributed SCM (*) (glob)
|
2018-01-15 01:53:52 +03:00
|
|
|
** Extensions loaded: throw, older, * (glob)
|
2015-09-11 22:45:19 +03:00
|
|
|
|
2012-05-17 01:18:07 +04:00
|
|
|
Declare the version as supporting this hg version, show regular bts link:
|
2016-05-11 01:52:26 +03:00
|
|
|
$ hgver=`hg debuginstall -T '{hgver}'`
|
2012-05-17 01:18:07 +04:00
|
|
|
$ echo 'testedwith = """'"$hgver"'"""' >> throw.py
|
2015-03-10 21:01:10 +03:00
|
|
|
$ if [ -z "$hgver" ]; then
|
|
|
|
> echo "unable to fetch a mercurial version. Make sure __version__ is correct";
|
|
|
|
> fi
|
2012-05-17 01:18:07 +04:00
|
|
|
$ rm -f throw.pyc throw.pyo
|
2017-08-02 16:04:02 +03:00
|
|
|
$ rm -Rf __pycache__
|
2018-01-15 01:53:52 +03:00
|
|
|
$ hg --config extensions.throw=throw.py throw 2>&1 | egrep '^\*\*' | grep -v 'possibly-broken' | grep -v 'Please disable'
|
|
|
|
** If that fixes the bug please report it to the extension author.
|
2015-01-16 07:36:03 +03:00
|
|
|
** Python * (glob)
|
|
|
|
** Mercurial Distributed SCM (*) (glob)
|
2018-01-15 01:53:52 +03:00
|
|
|
** Extensions loaded: throw, * (glob)
|
2015-01-16 07:36:03 +03:00
|
|
|
|
|
|
|
Patch version is ignored during compatibility check
|
|
|
|
$ echo "testedwith = '3.2'" >> throw.py
|
|
|
|
$ echo "util.version = lambda:'3.2.2'" >> throw.py
|
|
|
|
$ rm -f throw.pyc throw.pyo
|
2017-08-02 16:04:02 +03:00
|
|
|
$ rm -Rf __pycache__
|
2018-01-15 01:53:52 +03:00
|
|
|
$ hg --config extensions.throw=throw.py throw 2>&1 | egrep '^\*\*' | grep -v 'possibly-broken' | grep -v 'Please disable'
|
|
|
|
** If that fixes the bug please report it to the extension author.
|
2012-05-17 01:18:07 +04:00
|
|
|
** Python * (glob)
|
|
|
|
** Mercurial Distributed SCM (*) (glob)
|
2018-01-15 01:53:52 +03:00
|
|
|
** Extensions loaded: throw, * (glob)
|
2013-09-21 16:33:29 +04:00
|
|
|
|
2014-07-09 06:57:54 +04:00
|
|
|
Test version number support in 'hg version':
|
|
|
|
$ echo '__version__ = (1, 2, 3)' >> throw.py
|
|
|
|
$ rm -f throw.pyc throw.pyo
|
2017-08-02 16:04:02 +03:00
|
|
|
$ rm -Rf __pycache__
|
2018-01-15 01:53:52 +03:00
|
|
|
$ hg version -v | grep -v external
|
2014-07-23 20:16:22 +04:00
|
|
|
Mercurial Distributed SCM (version *) (glob)
|
2015-09-30 23:43:49 +03:00
|
|
|
(see https://mercurial-scm.org for more information)
|
2014-07-23 20:16:22 +04:00
|
|
|
|
|
|
|
Copyright (C) 2005-* Matt Mackall and others (glob)
|
|
|
|
This is free software; see the source for copying conditions. There is NO
|
|
|
|
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
Enabled extensions:
|
|
|
|
|
|
|
|
|
2018-01-15 01:53:52 +03:00
|
|
|
$ hg version -v --config extensions.throw=throw.py | egrep '(^external|throw)'
|
|
|
|
throw\s* external 1.2.3 (re)
|
2014-07-09 06:57:54 +04:00
|
|
|
$ echo 'getversion = lambda: "1.twentythree"' >> throw.py
|
|
|
|
$ rm -f throw.pyc throw.pyo
|
2017-08-02 16:04:02 +03:00
|
|
|
$ rm -Rf __pycache__
|
2018-01-15 01:53:52 +03:00
|
|
|
$ hg version -v --config extensions.throw=throw.py --config extensions.strip= | egrep 'throw'
|
|
|
|
throw \s* external 1.twentythree (re)
|
2014-07-09 06:57:54 +04:00
|
|
|
|
2016-08-16 10:03:09 +03:00
|
|
|
$ hg version -q --config extensions.throw=throw.py
|
|
|
|
Mercurial Distributed SCM (version *) (glob)
|
|
|
|
|
2016-08-25 08:00:26 +03:00
|
|
|
Test JSON output of version:
|
|
|
|
|
|
|
|
$ hg version -Tjson
|
|
|
|
[
|
|
|
|
{
|
2018-01-15 01:53:52 +03:00
|
|
|
"extensions": [*], (glob)
|
2016-08-25 08:00:26 +03:00
|
|
|
"ver": "*" (glob)
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
$ hg version --config extensions.throw=throw.py -Tjson
|
|
|
|
[
|
|
|
|
{
|
2018-01-15 01:53:52 +03:00
|
|
|
"extensions": [{"bundled": false, "name": "throw", "ver": "1.twentythree"}, *], (glob)
|
2016-08-25 08:00:26 +03:00
|
|
|
"ver": "3.2.2"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2016-08-26 17:38:52 +03:00
|
|
|
$ hg version --config extensions.strip= -Tjson
|
2016-08-25 08:00:26 +03:00
|
|
|
[
|
|
|
|
{
|
2018-01-15 01:53:52 +03:00
|
|
|
"extensions": [{"bundled": true, "name": "strip", "ver": null}, *], (glob)
|
2016-08-25 08:00:26 +03:00
|
|
|
"ver": "*" (glob)
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
Test template output of version:
|
|
|
|
|
|
|
|
$ hg version --config extensions.throw=throw.py --config extensions.strip= \
|
2018-01-15 01:53:52 +03:00
|
|
|
> -T'{extensions % "{name} {pad(ver, 16)} ({if(bundled, "internal", "external")})\n"}' | egrep '(throw|strip)'
|
2016-08-25 08:00:26 +03:00
|
|
|
throw 1.twentythree (external)
|
|
|
|
strip (internal)
|
|
|
|
|
extensions: refuse to load extensions if minimum hg version not met
As the author of several 3rd party extensions, I frequently see bug
reports from users attempting to run my extension with an old version
of Mercurial that I no longer support in my extension. Oftentimes, the
extension will import just fine. But as soon as we run extsetup(),
reposetup(), or get into the guts of a wrapped function, we encounter
an exception and abort. Today, Mercurial will print a message about
extensions that don't have a "testedwith" declaring explicit
compatibility with the current version.
The existing mechanism is a good start. But it isn't as robust as I
would like. Specifically, Mercurial assumes compatibility by default.
This means extension authors must perform compatibility checking in
their extsetup() or we wait and see if we encounter an abort at
runtime. And, compatibility checking can involve a lot of code and
lots of error checking. It's a lot of effort for extension authors.
Oftentimes, extension authors know which versions of Mercurial there
extension works on and more importantly where it is broken.
This patch introduces a magic "minimumhgversion" attribute in
extensions. When found, the extension loading mechanism will compare
the declared version against the current Mercurial version. If the
extension explicitly states we require a newer Mercurial version, a
warning is printed and the extension isn't loaded beyond importing
the Python module. This causes a graceful failure while alerting
the user of the compatibility issue.
I would be receptive to the idea of making the failure more fatal.
However, care would need to be taken to not criple every hg command.
e.g. the user may use `hg config` to fix the hgrc and if we aborted
trying to run that, the user would effectively be locked out of `hg`!
A potential future improvement to this functionality would be to catch
ImportError for the extension/module and parse the source code for
"minimumhgversion = 'XXX'" and do similar checking. This way we could
give more information about why the extension failed to load.
2015-11-25 02:16:25 +03:00
|
|
|
Refuse to load extensions with minimum version requirements
|
|
|
|
|
|
|
|
$ cat > minversion1.py << EOF
|
|
|
|
> from mercurial import util
|
|
|
|
> util.version = lambda: '3.5.2'
|
|
|
|
> minimumhgversion = '3.6'
|
|
|
|
> EOF
|
|
|
|
$ hg --config extensions.minversion=minversion1.py version
|
|
|
|
(third party extension minversion requires version 3.6 or newer of Mercurial; disabling)
|
|
|
|
Mercurial Distributed SCM (version 3.5.2)
|
|
|
|
(see https://mercurial-scm.org for more information)
|
|
|
|
|
|
|
|
Copyright (C) 2005-* Matt Mackall and others (glob)
|
|
|
|
This is free software; see the source for copying conditions. There is NO
|
|
|
|
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
$ cat > minversion2.py << EOF
|
|
|
|
> from mercurial import util
|
|
|
|
> util.version = lambda: '3.6'
|
|
|
|
> minimumhgversion = '3.7'
|
|
|
|
> EOF
|
|
|
|
$ hg --config extensions.minversion=minversion2.py version 2>&1 | egrep '\(third'
|
|
|
|
(third party extension minversion requires version 3.7 or newer of Mercurial; disabling)
|
|
|
|
|
|
|
|
Can load version that is only off by point release
|
|
|
|
|
|
|
|
$ cat > minversion2.py << EOF
|
|
|
|
> from mercurial import util
|
|
|
|
> util.version = lambda: '3.6.1'
|
|
|
|
> minimumhgversion = '3.6'
|
|
|
|
> EOF
|
|
|
|
$ hg --config extensions.minversion=minversion3.py version 2>&1 | egrep '\(third'
|
|
|
|
[1]
|
|
|
|
|
|
|
|
Can load minimum version identical to current
|
|
|
|
|
|
|
|
$ cat > minversion3.py << EOF
|
|
|
|
> from mercurial import util
|
|
|
|
> util.version = lambda: '3.5'
|
|
|
|
> minimumhgversion = '3.5'
|
|
|
|
> EOF
|
|
|
|
$ hg --config extensions.minversion=minversion3.py version 2>&1 | egrep '\(third'
|
|
|
|
[1]
|
|
|
|
|
2013-09-21 16:33:29 +04:00
|
|
|
Restore HGRCPATH
|
|
|
|
|
|
|
|
$ HGRCPATH=$ORGHGRCPATH
|
|
|
|
$ export HGRCPATH
|
|
|
|
|
|
|
|
Commands handling multiple repositories at a time should invoke only
|
|
|
|
"reposetup()" of extensions enabling in the target repository.
|
|
|
|
|
|
|
|
$ mkdir reposetup-test
|
|
|
|
$ cd reposetup-test
|
|
|
|
|
|
|
|
$ cat > $TESTTMP/reposetuptest.py <<EOF
|
|
|
|
> from mercurial import extensions
|
|
|
|
> def reposetup(ui, repo):
|
|
|
|
> ui.write('reposetup() for %s\n' % (repo.root))
|
2016-03-15 12:51:42 +03:00
|
|
|
> ui.flush()
|
2013-09-21 16:33:29 +04:00
|
|
|
> EOF
|
|
|
|
$ hg init src
|
|
|
|
$ echo a > src/a
|
|
|
|
$ hg -R src commit -Am '#0 at src/a'
|
|
|
|
adding a
|
|
|
|
$ echo '[extensions]' >> src/.hg/hgrc
|
|
|
|
$ echo '# enable extension locally' >> src/.hg/hgrc
|
|
|
|
$ echo "reposetuptest = $TESTTMP/reposetuptest.py" >> src/.hg/hgrc
|
|
|
|
$ hg -R src status
|
2017-12-11 06:50:57 +03:00
|
|
|
reposetup() for $TESTTMP/reposetup-test/src
|
|
|
|
reposetup() for $TESTTMP/reposetup-test/src (chg !)
|
2013-09-21 16:33:29 +04:00
|
|
|
|
|
|
|
$ hg clone -U src clone-dst1
|
2017-12-11 06:50:57 +03:00
|
|
|
reposetup() for $TESTTMP/reposetup-test/src
|
2013-09-21 16:33:29 +04:00
|
|
|
$ hg init push-dst1
|
|
|
|
$ hg -q -R src push push-dst1
|
2017-12-11 06:50:57 +03:00
|
|
|
reposetup() for $TESTTMP/reposetup-test/src
|
2013-09-21 16:33:29 +04:00
|
|
|
$ hg init pull-src1
|
|
|
|
$ hg -q -R pull-src1 pull src
|
2017-12-11 06:50:57 +03:00
|
|
|
reposetup() for $TESTTMP/reposetup-test/src
|
2013-09-21 16:33:29 +04:00
|
|
|
|
2014-11-04 17:41:46 +03:00
|
|
|
$ cat <<EOF >> $HGRCPATH
|
|
|
|
> [extensions]
|
|
|
|
> # disable extension globally and explicitly
|
|
|
|
> reposetuptest = !
|
|
|
|
> EOF
|
2013-09-21 16:33:29 +04:00
|
|
|
$ hg clone -U src clone-dst2
|
2017-12-11 06:50:57 +03:00
|
|
|
reposetup() for $TESTTMP/reposetup-test/src
|
2013-09-21 16:33:29 +04:00
|
|
|
$ hg init push-dst2
|
|
|
|
$ hg -q -R src push push-dst2
|
2017-12-11 06:50:57 +03:00
|
|
|
reposetup() for $TESTTMP/reposetup-test/src
|
2013-09-21 16:33:29 +04:00
|
|
|
$ hg init pull-src2
|
|
|
|
$ hg -q -R pull-src2 pull src
|
2017-12-11 06:50:57 +03:00
|
|
|
reposetup() for $TESTTMP/reposetup-test/src
|
2013-09-21 16:33:29 +04:00
|
|
|
|
2014-11-04 17:41:46 +03:00
|
|
|
$ cat <<EOF >> $HGRCPATH
|
|
|
|
> [extensions]
|
|
|
|
> # enable extension globally
|
|
|
|
> reposetuptest = $TESTTMP/reposetuptest.py
|
|
|
|
> EOF
|
2013-09-21 16:33:29 +04:00
|
|
|
$ hg clone -U src clone-dst3
|
2017-12-11 06:50:57 +03:00
|
|
|
reposetup() for $TESTTMP/reposetup-test/src
|
|
|
|
reposetup() for $TESTTMP/reposetup-test/clone-dst3
|
2013-09-21 16:33:29 +04:00
|
|
|
$ hg init push-dst3
|
2017-12-11 06:50:57 +03:00
|
|
|
reposetup() for $TESTTMP/reposetup-test/push-dst3
|
2013-09-21 16:33:29 +04:00
|
|
|
$ hg -q -R src push push-dst3
|
2017-12-11 06:50:57 +03:00
|
|
|
reposetup() for $TESTTMP/reposetup-test/src
|
|
|
|
reposetup() for $TESTTMP/reposetup-test/push-dst3
|
2013-09-21 16:33:29 +04:00
|
|
|
$ hg init pull-src3
|
2017-12-11 06:50:57 +03:00
|
|
|
reposetup() for $TESTTMP/reposetup-test/pull-src3
|
2013-09-21 16:33:29 +04:00
|
|
|
$ hg -q -R pull-src3 pull src
|
2017-12-11 06:50:57 +03:00
|
|
|
reposetup() for $TESTTMP/reposetup-test/pull-src3
|
|
|
|
reposetup() for $TESTTMP/reposetup-test/src
|
2013-09-21 16:33:29 +04:00
|
|
|
|
|
|
|
$ echo '[extensions]' >> src/.hg/hgrc
|
|
|
|
$ echo '# disable extension locally' >> src/.hg/hgrc
|
|
|
|
$ echo 'reposetuptest = !' >> src/.hg/hgrc
|
|
|
|
$ hg clone -U src clone-dst4
|
2017-12-11 06:50:57 +03:00
|
|
|
reposetup() for $TESTTMP/reposetup-test/clone-dst4
|
2013-09-21 16:33:29 +04:00
|
|
|
$ hg init push-dst4
|
2017-12-11 06:50:57 +03:00
|
|
|
reposetup() for $TESTTMP/reposetup-test/push-dst4
|
2013-09-21 16:33:29 +04:00
|
|
|
$ hg -q -R src push push-dst4
|
2017-12-11 06:50:57 +03:00
|
|
|
reposetup() for $TESTTMP/reposetup-test/push-dst4
|
2013-09-21 16:33:29 +04:00
|
|
|
$ hg init pull-src4
|
2017-12-11 06:50:57 +03:00
|
|
|
reposetup() for $TESTTMP/reposetup-test/pull-src4
|
2013-09-21 16:33:29 +04:00
|
|
|
$ hg -q -R pull-src4 pull src
|
2017-12-11 06:50:57 +03:00
|
|
|
reposetup() for $TESTTMP/reposetup-test/pull-src4
|
2013-09-21 16:33:29 +04:00
|
|
|
|
|
|
|
disabling in command line overlays with all configuration
|
|
|
|
$ hg --config extensions.reposetuptest=! clone -U src clone-dst5
|
|
|
|
$ hg --config extensions.reposetuptest=! init push-dst5
|
|
|
|
$ hg --config extensions.reposetuptest=! -q -R src push push-dst5
|
|
|
|
$ hg --config extensions.reposetuptest=! init pull-src5
|
|
|
|
$ hg --config extensions.reposetuptest=! -q -R pull-src5 pull src
|
|
|
|
|
2014-11-04 17:41:46 +03:00
|
|
|
$ cat <<EOF >> $HGRCPATH
|
|
|
|
> [extensions]
|
|
|
|
> # disable extension globally and explicitly
|
|
|
|
> reposetuptest = !
|
|
|
|
> EOF
|
2013-09-21 16:33:29 +04:00
|
|
|
$ hg init parent
|
|
|
|
$ hg init parent/sub1
|
|
|
|
$ echo 1 > parent/sub1/1
|
|
|
|
$ hg -R parent/sub1 commit -Am '#0 at parent/sub1'
|
|
|
|
adding 1
|
|
|
|
$ hg init parent/sub2
|
|
|
|
$ hg init parent/sub2/sub21
|
|
|
|
$ echo 21 > parent/sub2/sub21/21
|
|
|
|
$ hg -R parent/sub2/sub21 commit -Am '#0 at parent/sub2/sub21'
|
|
|
|
adding 21
|
|
|
|
$ cat > parent/sub2/.hgsub <<EOF
|
|
|
|
> sub21 = sub21
|
|
|
|
> EOF
|
|
|
|
$ hg -R parent/sub2 commit -Am '#0 at parent/sub2'
|
|
|
|
adding .hgsub
|
|
|
|
$ hg init parent/sub3
|
|
|
|
$ echo 3 > parent/sub3/3
|
|
|
|
$ hg -R parent/sub3 commit -Am '#0 at parent/sub3'
|
|
|
|
adding 3
|
|
|
|
$ cat > parent/.hgsub <<EOF
|
|
|
|
> sub1 = sub1
|
|
|
|
> sub2 = sub2
|
|
|
|
> sub3 = sub3
|
|
|
|
> EOF
|
|
|
|
$ hg -R parent commit -Am '#0 at parent'
|
|
|
|
adding .hgsub
|
|
|
|
$ echo '[extensions]' >> parent/.hg/hgrc
|
|
|
|
$ echo '# enable extension locally' >> parent/.hg/hgrc
|
|
|
|
$ echo "reposetuptest = $TESTTMP/reposetuptest.py" >> parent/.hg/hgrc
|
|
|
|
$ cp parent/.hg/hgrc parent/sub2/.hg/hgrc
|
|
|
|
$ hg -R parent status -S -A
|
2017-12-11 06:50:57 +03:00
|
|
|
reposetup() for $TESTTMP/reposetup-test/parent
|
|
|
|
reposetup() for $TESTTMP/reposetup-test/parent/sub2
|
2013-09-21 16:33:29 +04:00
|
|
|
C .hgsub
|
|
|
|
C .hgsubstate
|
|
|
|
C sub1/1
|
|
|
|
C sub2/.hgsub
|
|
|
|
C sub2/.hgsubstate
|
|
|
|
C sub2/sub21/21
|
|
|
|
C sub3/3
|
|
|
|
|
|
|
|
$ cd ..
|
2015-02-09 22:02:45 +03:00
|
|
|
|
2017-05-13 09:41:50 +03:00
|
|
|
Prohibit registration of commands that don't use @command (issue5137)
|
|
|
|
|
|
|
|
$ hg init deprecated
|
|
|
|
$ cd deprecated
|
|
|
|
|
|
|
|
$ cat <<EOF > deprecatedcmd.py
|
|
|
|
> def deprecatedcmd(repo, ui):
|
|
|
|
> pass
|
|
|
|
> cmdtable = {
|
|
|
|
> 'deprecatedcmd': (deprecatedcmd, [], ''),
|
|
|
|
> }
|
|
|
|
> EOF
|
|
|
|
$ cat <<EOF > .hg/hgrc
|
|
|
|
> [extensions]
|
|
|
|
> deprecatedcmd = `pwd`/deprecatedcmd.py
|
|
|
|
> mq = !
|
|
|
|
> hgext.mq = !
|
|
|
|
> hgext/mq = !
|
|
|
|
> EOF
|
|
|
|
|
|
|
|
$ hg deprecatedcmd > /dev/null
|
|
|
|
*** failed to import extension deprecatedcmd from $TESTTMP/deprecated/deprecatedcmd.py: missing attributes: norepo, optionalrepo, inferrepo
|
|
|
|
*** (use @command decorator to register 'deprecatedcmd')
|
|
|
|
hg: unknown command 'deprecatedcmd'
|
|
|
|
[255]
|
|
|
|
|
|
|
|
the extension shouldn't be loaded at all so the mq works:
|
|
|
|
|
2018-07-30 18:46:11 +03:00
|
|
|
$ hg log -r null --config extensions.mq= > /dev/null
|
2017-05-13 09:41:50 +03:00
|
|
|
*** failed to import extension deprecatedcmd from $TESTTMP/deprecated/deprecatedcmd.py: missing attributes: norepo, optionalrepo, inferrepo
|
|
|
|
*** (use @command decorator to register 'deprecatedcmd')
|
|
|
|
|
|
|
|
$ cd ..
|
|
|
|
|
2015-02-09 22:02:45 +03:00
|
|
|
Test synopsis and docstring extending
|
|
|
|
|
|
|
|
$ hg init exthelp
|
|
|
|
$ cat > exthelp.py <<EOF
|
|
|
|
> from mercurial import commands, extensions
|
|
|
|
> def exbookmarks(orig, *args, **opts):
|
|
|
|
> return orig(*args, **opts)
|
|
|
|
> def uisetup(ui):
|
|
|
|
> synopsis = ' GREPME [--foo] [-x]'
|
|
|
|
> docstring = '''
|
|
|
|
> GREPME make sure that this is in the help!
|
|
|
|
> '''
|
|
|
|
> extensions.wrapcommand(commands.table, 'bookmarks', exbookmarks,
|
|
|
|
> synopsis, docstring)
|
|
|
|
> EOF
|
|
|
|
$ abspath=`pwd`/exthelp.py
|
|
|
|
$ echo '[extensions]' >> $HGRCPATH
|
|
|
|
$ echo "exthelp = $abspath" >> $HGRCPATH
|
|
|
|
$ cd exthelp
|
|
|
|
$ hg help bookmarks | grep GREPME
|
|
|
|
hg bookmarks [OPTIONS]... [NAME]... GREPME [--foo] [-x]
|
|
|
|
GREPME make sure that this is in the help!
|
2016-01-09 17:24:52 +03:00
|
|
|
$ cd ..
|
|
|
|
|
|
|
|
Show deprecation warning for the use of cmdutil.command
|
|
|
|
|
|
|
|
$ cat > nonregistrar.py <<EOF
|
|
|
|
> from mercurial import cmdutil
|
|
|
|
> cmdtable = {}
|
|
|
|
> command = cmdutil.command(cmdtable)
|
2017-06-25 05:50:05 +03:00
|
|
|
> @command(b'foo', [], norepo=True)
|
2016-01-09 17:24:52 +03:00
|
|
|
> def foo(ui):
|
|
|
|
> pass
|
|
|
|
> EOF
|
2015-02-09 22:02:45 +03:00
|
|
|
|
2016-01-09 17:24:52 +03:00
|
|
|
$ hg --config extensions.nonregistrar=`pwd`/nonregistrar.py version > /dev/null
|
|
|
|
devel-warn: cmdutil.command is deprecated, use registrar.command to register 'foo'
|
|
|
|
(compatibility will be dropped after Mercurial-4.6, update your code.) * (glob)
|
2017-08-29 19:24:51 +03:00
|
|
|
|
|
|
|
Prohibit the use of unicode strings as the default value of options
|
|
|
|
|
|
|
|
$ hg init $TESTTMP/opt-unicode-default
|
|
|
|
|
|
|
|
$ cat > $TESTTMP/test_unicode_default_value.py << EOF
|
|
|
|
> from mercurial import registrar
|
|
|
|
> cmdtable = {}
|
|
|
|
> command = registrar.command(cmdtable)
|
|
|
|
> @command('dummy', [('', 'opt', u'value', u'help')], 'ext [OPTIONS]')
|
|
|
|
> def ext(*args, **opts):
|
|
|
|
> print(opts['opt'])
|
|
|
|
> EOF
|
|
|
|
$ cat > $TESTTMP/opt-unicode-default/.hg/hgrc << EOF
|
|
|
|
> [extensions]
|
|
|
|
> test_unicode_default_value = $TESTTMP/test_unicode_default_value.py
|
|
|
|
> EOF
|
|
|
|
$ hg -R $TESTTMP/opt-unicode-default dummy
|
|
|
|
*** failed to import extension test_unicode_default_value from $TESTTMP/test_unicode_default_value.py: option 'dummy.opt' has a unicode default value
|
|
|
|
*** (change the dummy.opt default value to a non-unicode string)
|
|
|
|
hg: unknown command 'dummy'
|
|
|
|
(did you mean summary?)
|
|
|
|
[255]
|