Mercurial > hg
annotate mercurial/extensions.py @ 31187:6b8e1a08ef1d
patchbomb: add config knob to generate flags by template (issue5354)
This can be used to flag patches by branch or topic automatically. Flags
optionally given by --flag option are exported as {flags} template keyword,
so you can add --flag V2.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 25 Feb 2017 18:41:00 +0900 |
parents | 2912b06905dc |
children | d79761fe697f |
rev | line source |
---|---|
4544
930ed513c864
Create a separate module for managing extensions
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
1 # extensions.py - extension handling for mercurial |
930ed513c864
Create a separate module for managing extensions
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
2 # |
4635
63b9d2deed48
Updated copyright notices and add "and others" to "hg version"
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4633
diff
changeset
|
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
4544
930ed513c864
Create a separate module for managing extensions
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
4 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8206
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
10263 | 6 # GNU General Public License version 2 or any later version. |
4544
930ed513c864
Create a separate module for managing extensions
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
7 |
25946
5e0d80195a0f
extensions: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
8 from __future__ import absolute_import |
5e0d80195a0f
extensions: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
9 |
5e0d80195a0f
extensions: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
10 import imp |
5e0d80195a0f
extensions: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
11 import os |
5e0d80195a0f
extensions: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
12 |
5e0d80195a0f
extensions: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
13 from .i18n import ( |
5e0d80195a0f
extensions: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
14 _, |
5e0d80195a0f
extensions: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
15 gettext, |
5e0d80195a0f
extensions: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
16 ) |
5e0d80195a0f
extensions: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
17 |
5e0d80195a0f
extensions: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
18 from . import ( |
5e0d80195a0f
extensions: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
19 cmdutil, |
5e0d80195a0f
extensions: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
20 error, |
30570
c4c51fd0e11d
py3: use pycompat.sysstr() in __import__()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30306
diff
changeset
|
21 pycompat, |
25946
5e0d80195a0f
extensions: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
22 util, |
5e0d80195a0f
extensions: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
23 ) |
4544
930ed513c864
Create a separate module for managing extensions
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
24 |
930ed513c864
Create a separate module for managing extensions
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
25 _extensions = {} |
29895
b1ebc767563d
help: show content for explicitly disabled extension (issue5228)
liscju <piotr.listkiewicz@gmail.com>
parents:
29841
diff
changeset
|
26 _disabledextensions = {} |
24065
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
27 _aftercallbacks = {} |
5192
60acf1432ee0
Move cmdtable and reposetup handling out of extensions.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5152
diff
changeset
|
28 _order = [] |
27116
0214cc0a0e97
extensions: properly mark progress as part of core
Augie Fackler <augie@google.com>
parents:
27111
diff
changeset
|
29 _builtin = set(['hbisect', 'bookmarks', 'parentrevspec', 'progress', 'interhg', |
29162 | 30 'inotify', 'hgcia']) |
5192
60acf1432ee0
Move cmdtable and reposetup handling out of extensions.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5152
diff
changeset
|
31 |
19777
6f72e7d28b35
extensions: list up only enabled extensions, if "ui" is specified
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19769
diff
changeset
|
32 def extensions(ui=None): |
6f72e7d28b35
extensions: list up only enabled extensions, if "ui" is specified
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19769
diff
changeset
|
33 if ui: |
6f72e7d28b35
extensions: list up only enabled extensions, if "ui" is specified
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19769
diff
changeset
|
34 def enabled(name): |
6f72e7d28b35
extensions: list up only enabled extensions, if "ui" is specified
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19769
diff
changeset
|
35 for format in ['%s', 'hgext.%s']: |
6f72e7d28b35
extensions: list up only enabled extensions, if "ui" is specified
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19769
diff
changeset
|
36 conf = ui.config('extensions', format % name) |
6f72e7d28b35
extensions: list up only enabled extensions, if "ui" is specified
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19769
diff
changeset
|
37 if conf is not None and not conf.startswith('!'): |
6f72e7d28b35
extensions: list up only enabled extensions, if "ui" is specified
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19769
diff
changeset
|
38 return True |
6f72e7d28b35
extensions: list up only enabled extensions, if "ui" is specified
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19769
diff
changeset
|
39 else: |
6f72e7d28b35
extensions: list up only enabled extensions, if "ui" is specified
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19769
diff
changeset
|
40 enabled = lambda name: True |
5192
60acf1432ee0
Move cmdtable and reposetup handling out of extensions.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5152
diff
changeset
|
41 for name in _order: |
60acf1432ee0
Move cmdtable and reposetup handling out of extensions.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5152
diff
changeset
|
42 module = _extensions[name] |
19777
6f72e7d28b35
extensions: list up only enabled extensions, if "ui" is specified
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19769
diff
changeset
|
43 if module and enabled(name): |
5192
60acf1432ee0
Move cmdtable and reposetup handling out of extensions.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5152
diff
changeset
|
44 yield name, module |
4544
930ed513c864
Create a separate module for managing extensions
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
45 |
930ed513c864
Create a separate module for managing extensions
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
46 def find(name): |
930ed513c864
Create a separate module for managing extensions
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
47 '''return module with given extension name''' |
14415
c238b12a1ed4
extensions: raise when trying to find an extension that failed to load
Idan Kamara <idankk86@gmail.com>
parents:
14318
diff
changeset
|
48 mod = None |
4544
930ed513c864
Create a separate module for managing extensions
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
49 try: |
27637
b502138f5faa
cleanup: remove superfluous space after space after equals (python)
timeless <timeless@mozdev.org>
parents:
27142
diff
changeset
|
50 mod = _extensions[name] |
4544
930ed513c864
Create a separate module for managing extensions
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
51 except KeyError: |
930ed513c864
Create a separate module for managing extensions
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
52 for k, v in _extensions.iteritems(): |
4560
3daed3680554
extensions: fix lookup of hgext.foo modules
Matt Mackall <mpm@selenic.com>
parents:
4558
diff
changeset
|
53 if k.endswith('.' + name) or k.endswith('/' + name): |
14415
c238b12a1ed4
extensions: raise when trying to find an extension that failed to load
Idan Kamara <idankk86@gmail.com>
parents:
14318
diff
changeset
|
54 mod = v |
c238b12a1ed4
extensions: raise when trying to find an extension that failed to load
Idan Kamara <idankk86@gmail.com>
parents:
14318
diff
changeset
|
55 break |
c238b12a1ed4
extensions: raise when trying to find an extension that failed to load
Idan Kamara <idankk86@gmail.com>
parents:
14318
diff
changeset
|
56 if not mod: |
4544
930ed513c864
Create a separate module for managing extensions
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
57 raise KeyError(name) |
14415
c238b12a1ed4
extensions: raise when trying to find an extension that failed to load
Idan Kamara <idankk86@gmail.com>
parents:
14318
diff
changeset
|
58 return mod |
4544
930ed513c864
Create a separate module for managing extensions
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
59 |
7916
f779e1996e23
ability to load hooks from arbitrary python module
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7876
diff
changeset
|
60 def loadpath(path, module_name): |
f779e1996e23
ability to load hooks from arbitrary python module
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7876
diff
changeset
|
61 module_name = module_name.replace('.', '_') |
20645
7d83c3b6e8d9
extensions: use normpath to allow trailing '\' on Windows (issue4187)
Ed Morley <emorley@mozilla.com>
parents:
20622
diff
changeset
|
62 path = util.normpath(util.expandpath(path)) |
30575
5ffbaba9acac
py3: use pycompat.fsdecode() to pass to imp.* functions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30570
diff
changeset
|
63 module_name = pycompat.fsdecode(module_name) |
5ffbaba9acac
py3: use pycompat.fsdecode() to pass to imp.* functions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30570
diff
changeset
|
64 path = pycompat.fsdecode(path) |
7916
f779e1996e23
ability to load hooks from arbitrary python module
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7876
diff
changeset
|
65 if os.path.isdir(path): |
f779e1996e23
ability to load hooks from arbitrary python module
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7876
diff
changeset
|
66 # module/__init__.py style |
20645
7d83c3b6e8d9
extensions: use normpath to allow trailing '\' on Windows (issue4187)
Ed Morley <emorley@mozilla.com>
parents:
20622
diff
changeset
|
67 d, f = os.path.split(path) |
7916
f779e1996e23
ability to load hooks from arbitrary python module
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7876
diff
changeset
|
68 fd, fpath, desc = imp.find_module(f, [d]) |
f779e1996e23
ability to load hooks from arbitrary python module
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7876
diff
changeset
|
69 return imp.load_module(module_name, fd, fpath, desc) |
f779e1996e23
ability to load hooks from arbitrary python module
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7876
diff
changeset
|
70 else: |
17217
1b2b727a885f
hooks: print out more information when loading a python hook fails
Simon Heimberg <simohe@besonet.ch>
parents:
16709
diff
changeset
|
71 try: |
1b2b727a885f
hooks: print out more information when loading a python hook fails
Simon Heimberg <simohe@besonet.ch>
parents:
16709
diff
changeset
|
72 return imp.load_source(module_name, path) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25364
diff
changeset
|
73 except IOError as exc: |
17217
1b2b727a885f
hooks: print out more information when loading a python hook fails
Simon Heimberg <simohe@besonet.ch>
parents:
16709
diff
changeset
|
74 if not exc.filename: |
1b2b727a885f
hooks: print out more information when loading a python hook fails
Simon Heimberg <simohe@besonet.ch>
parents:
16709
diff
changeset
|
75 exc.filename = path # python does not fill this |
1b2b727a885f
hooks: print out more information when loading a python hook fails
Simon Heimberg <simohe@besonet.ch>
parents:
16709
diff
changeset
|
76 raise |
7916
f779e1996e23
ability to load hooks from arbitrary python module
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7876
diff
changeset
|
77 |
28505
d5512a0a8ad6
extensions: extract the 'importh' closure as normal function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
28312
diff
changeset
|
78 def _importh(name): |
d5512a0a8ad6
extensions: extract the 'importh' closure as normal function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
28312
diff
changeset
|
79 """import and return the <name> module""" |
30570
c4c51fd0e11d
py3: use pycompat.sysstr() in __import__()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30306
diff
changeset
|
80 mod = __import__(pycompat.sysstr(name)) |
28505
d5512a0a8ad6
extensions: extract the 'importh' closure as normal function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
28312
diff
changeset
|
81 components = name.split('.') |
d5512a0a8ad6
extensions: extract the 'importh' closure as normal function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
28312
diff
changeset
|
82 for comp in components[1:]: |
d5512a0a8ad6
extensions: extract the 'importh' closure as normal function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
28312
diff
changeset
|
83 mod = getattr(mod, comp) |
d5512a0a8ad6
extensions: extract the 'importh' closure as normal function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
28312
diff
changeset
|
84 return mod |
d5512a0a8ad6
extensions: extract the 'importh' closure as normal function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
28312
diff
changeset
|
85 |
30058
8f54f9b8010d
extensions: move the "import" logic out from "load"
Jun Wu <quark@fb.com>
parents:
30028
diff
changeset
|
86 def _importext(name, path=None, reportfunc=None): |
8f54f9b8010d
extensions: move the "import" logic out from "load"
Jun Wu <quark@fb.com>
parents:
30028
diff
changeset
|
87 if path: |
8f54f9b8010d
extensions: move the "import" logic out from "load"
Jun Wu <quark@fb.com>
parents:
30028
diff
changeset
|
88 # the module will be loaded in sys.modules |
8f54f9b8010d
extensions: move the "import" logic out from "load"
Jun Wu <quark@fb.com>
parents:
30028
diff
changeset
|
89 # choose an unique name so that it doesn't |
8f54f9b8010d
extensions: move the "import" logic out from "load"
Jun Wu <quark@fb.com>
parents:
30028
diff
changeset
|
90 # conflicts with other modules |
8f54f9b8010d
extensions: move the "import" logic out from "load"
Jun Wu <quark@fb.com>
parents:
30028
diff
changeset
|
91 mod = loadpath(path, 'hgext.%s' % name) |
8f54f9b8010d
extensions: move the "import" logic out from "load"
Jun Wu <quark@fb.com>
parents:
30028
diff
changeset
|
92 else: |
8f54f9b8010d
extensions: move the "import" logic out from "load"
Jun Wu <quark@fb.com>
parents:
30028
diff
changeset
|
93 try: |
8f54f9b8010d
extensions: move the "import" logic out from "load"
Jun Wu <quark@fb.com>
parents:
30028
diff
changeset
|
94 mod = _importh("hgext.%s" % name) |
8f54f9b8010d
extensions: move the "import" logic out from "load"
Jun Wu <quark@fb.com>
parents:
30028
diff
changeset
|
95 except ImportError as err: |
8f54f9b8010d
extensions: move the "import" logic out from "load"
Jun Wu <quark@fb.com>
parents:
30028
diff
changeset
|
96 if reportfunc: |
8f54f9b8010d
extensions: move the "import" logic out from "load"
Jun Wu <quark@fb.com>
parents:
30028
diff
changeset
|
97 reportfunc(err, "hgext.%s" % name, "hgext3rd.%s" % name) |
8f54f9b8010d
extensions: move the "import" logic out from "load"
Jun Wu <quark@fb.com>
parents:
30028
diff
changeset
|
98 try: |
8f54f9b8010d
extensions: move the "import" logic out from "load"
Jun Wu <quark@fb.com>
parents:
30028
diff
changeset
|
99 mod = _importh("hgext3rd.%s" % name) |
8f54f9b8010d
extensions: move the "import" logic out from "load"
Jun Wu <quark@fb.com>
parents:
30028
diff
changeset
|
100 except ImportError as err: |
8f54f9b8010d
extensions: move the "import" logic out from "load"
Jun Wu <quark@fb.com>
parents:
30028
diff
changeset
|
101 if reportfunc: |
8f54f9b8010d
extensions: move the "import" logic out from "load"
Jun Wu <quark@fb.com>
parents:
30028
diff
changeset
|
102 reportfunc(err, "hgext3rd.%s" % name, name) |
8f54f9b8010d
extensions: move the "import" logic out from "load"
Jun Wu <quark@fb.com>
parents:
30028
diff
changeset
|
103 mod = _importh(name) |
8f54f9b8010d
extensions: move the "import" logic out from "load"
Jun Wu <quark@fb.com>
parents:
30028
diff
changeset
|
104 return mod |
8f54f9b8010d
extensions: move the "import" logic out from "load"
Jun Wu <quark@fb.com>
parents:
30028
diff
changeset
|
105 |
28506
10252652c6e4
extensions: factor import error reporting out
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
28505
diff
changeset
|
106 def _reportimporterror(ui, err, failed, next): |
30028
3741a8f86e88
extensions: add a note about debug output during extensions search
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30027
diff
changeset
|
107 # note: this ui.debug happens before --debug is processed, |
3741a8f86e88
extensions: add a note about debug output during extensions search
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30027
diff
changeset
|
108 # Use --config ui.debug=1 to see them. |
28506
10252652c6e4
extensions: factor import error reporting out
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
28505
diff
changeset
|
109 ui.debug('could not import %s (%s): trying %s\n' |
10252652c6e4
extensions: factor import error reporting out
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
28505
diff
changeset
|
110 % (failed, err, next)) |
10252652c6e4
extensions: factor import error reporting out
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
28505
diff
changeset
|
111 if ui.debugflag: |
10252652c6e4
extensions: factor import error reporting out
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
28505
diff
changeset
|
112 ui.traceback() |
10252652c6e4
extensions: factor import error reporting out
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
28505
diff
changeset
|
113 |
4544
930ed513c864
Create a separate module for managing extensions
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
114 def load(ui, name, path): |
7011
7da76778dbd7
Do not try to load extensions twice (issue811)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6212
diff
changeset
|
115 if name.startswith('hgext.') or name.startswith('hgext/'): |
5031
af0995261f02
extensions: don't get confused by aliasing between "foo" and "hgext.foo"
Bryan O'Sullivan <bos@serpentine.com>
parents:
4818
diff
changeset
|
116 shortname = name[6:] |
af0995261f02
extensions: don't get confused by aliasing between "foo" and "hgext.foo"
Bryan O'Sullivan <bos@serpentine.com>
parents:
4818
diff
changeset
|
117 else: |
af0995261f02
extensions: don't get confused by aliasing between "foo" and "hgext.foo"
Bryan O'Sullivan <bos@serpentine.com>
parents:
4818
diff
changeset
|
118 shortname = name |
27111
9de814b35808
extensions: rename _ignore to _builtin, add descriptive comment
Bryan O'Sullivan <bos@serpentine.com>
parents:
26781
diff
changeset
|
119 if shortname in _builtin: |
13349
0d3f35394af4
extensions: add an ignore list for old extensions
Matt Mackall <mpm@selenic.com>
parents:
13191
diff
changeset
|
120 return None |
5031
af0995261f02
extensions: don't get confused by aliasing between "foo" and "hgext.foo"
Bryan O'Sullivan <bos@serpentine.com>
parents:
4818
diff
changeset
|
121 if shortname in _extensions: |
12779
891ddf76b73e
extensions.load: return module
Erik Zielke <ez@aragost.com>
parents:
11521
diff
changeset
|
122 return _extensions[shortname] |
5087
b3cc62268a91
Cache extension load failures.
Brendan Cully <brendan@kublai.com>
parents:
4635
diff
changeset
|
123 _extensions[shortname] = None |
30058
8f54f9b8010d
extensions: move the "import" logic out from "load"
Jun Wu <quark@fb.com>
parents:
30028
diff
changeset
|
124 mod = _importext(name, path, bind(_reportimporterror, ui)) |
27142
060f83d219b9
extensions: refuse to load extensions if minimum hg version not met
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27116
diff
changeset
|
125 |
060f83d219b9
extensions: refuse to load extensions if minimum hg version not met
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27116
diff
changeset
|
126 # Before we do anything with the extension, check against minimum stated |
060f83d219b9
extensions: refuse to load extensions if minimum hg version not met
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27116
diff
changeset
|
127 # compatibility. This gives extension authors a mechanism to have their |
060f83d219b9
extensions: refuse to load extensions if minimum hg version not met
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27116
diff
changeset
|
128 # extensions short circuit when loaded with a known incompatible version |
060f83d219b9
extensions: refuse to load extensions if minimum hg version not met
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27116
diff
changeset
|
129 # of Mercurial. |
060f83d219b9
extensions: refuse to load extensions if minimum hg version not met
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27116
diff
changeset
|
130 minver = getattr(mod, 'minimumhgversion', None) |
060f83d219b9
extensions: refuse to load extensions if minimum hg version not met
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27116
diff
changeset
|
131 if minver and util.versiontuple(minver, 2) > util.versiontuple(n=2): |
060f83d219b9
extensions: refuse to load extensions if minimum hg version not met
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27116
diff
changeset
|
132 ui.warn(_('(third party extension %s requires version %s or newer ' |
060f83d219b9
extensions: refuse to load extensions if minimum hg version not met
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27116
diff
changeset
|
133 'of Mercurial; disabling)\n') % (shortname, minver)) |
060f83d219b9
extensions: refuse to load extensions if minimum hg version not met
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27116
diff
changeset
|
134 return |
060f83d219b9
extensions: refuse to load extensions if minimum hg version not met
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27116
diff
changeset
|
135 |
5031
af0995261f02
extensions: don't get confused by aliasing between "foo" and "hgext.foo"
Bryan O'Sullivan <bos@serpentine.com>
parents:
4818
diff
changeset
|
136 _extensions[shortname] = mod |
5192
60acf1432ee0
Move cmdtable and reposetup handling out of extensions.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5152
diff
changeset
|
137 _order.append(shortname) |
24065
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
138 for fn in _aftercallbacks.get(shortname, []): |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
139 fn(loaded=True) |
12779
891ddf76b73e
extensions.load: return module
Erik Zielke <ez@aragost.com>
parents:
11521
diff
changeset
|
140 return mod |
4544
930ed513c864
Create a separate module for managing extensions
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
141 |
29461
7d88fde2309f
extensions: move uisetup and extsetup to standalone functions
Jun Wu <quark@fb.com>
parents:
29162
diff
changeset
|
142 def _runuisetup(name, ui): |
7d88fde2309f
extensions: move uisetup and extsetup to standalone functions
Jun Wu <quark@fb.com>
parents:
29162
diff
changeset
|
143 uisetup = getattr(_extensions[name], 'uisetup', None) |
7d88fde2309f
extensions: move uisetup and extsetup to standalone functions
Jun Wu <quark@fb.com>
parents:
29162
diff
changeset
|
144 if uisetup: |
7d88fde2309f
extensions: move uisetup and extsetup to standalone functions
Jun Wu <quark@fb.com>
parents:
29162
diff
changeset
|
145 uisetup(ui) |
7d88fde2309f
extensions: move uisetup and extsetup to standalone functions
Jun Wu <quark@fb.com>
parents:
29162
diff
changeset
|
146 |
7d88fde2309f
extensions: move uisetup and extsetup to standalone functions
Jun Wu <quark@fb.com>
parents:
29162
diff
changeset
|
147 def _runextsetup(name, ui): |
7d88fde2309f
extensions: move uisetup and extsetup to standalone functions
Jun Wu <quark@fb.com>
parents:
29162
diff
changeset
|
148 extsetup = getattr(_extensions[name], 'extsetup', None) |
7d88fde2309f
extensions: move uisetup and extsetup to standalone functions
Jun Wu <quark@fb.com>
parents:
29162
diff
changeset
|
149 if extsetup: |
7d88fde2309f
extensions: move uisetup and extsetup to standalone functions
Jun Wu <quark@fb.com>
parents:
29162
diff
changeset
|
150 try: |
7d88fde2309f
extensions: move uisetup and extsetup to standalone functions
Jun Wu <quark@fb.com>
parents:
29162
diff
changeset
|
151 extsetup(ui) |
7d88fde2309f
extensions: move uisetup and extsetup to standalone functions
Jun Wu <quark@fb.com>
parents:
29162
diff
changeset
|
152 except TypeError: |
7d88fde2309f
extensions: move uisetup and extsetup to standalone functions
Jun Wu <quark@fb.com>
parents:
29162
diff
changeset
|
153 if extsetup.func_code.co_argcount != 0: |
7d88fde2309f
extensions: move uisetup and extsetup to standalone functions
Jun Wu <quark@fb.com>
parents:
29162
diff
changeset
|
154 raise |
7d88fde2309f
extensions: move uisetup and extsetup to standalone functions
Jun Wu <quark@fb.com>
parents:
29162
diff
changeset
|
155 extsetup() # old extsetup with no ui argument |
7d88fde2309f
extensions: move uisetup and extsetup to standalone functions
Jun Wu <quark@fb.com>
parents:
29162
diff
changeset
|
156 |
4544
930ed513c864
Create a separate module for managing extensions
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
157 def loadall(ui): |
4617
669e76b7df24
extensions: pull extension-aware bits out of ui
Matt Mackall <mpm@selenic.com>
parents:
4582
diff
changeset
|
158 result = ui.configitems("extensions") |
9410
1c83938b6a8e
extensions: load and configure extensions in well-defined phases
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
159 newindex = len(_order) |
7876
53c72ba36c2b
cleanup: drop enumerate() when index is not used
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7644
diff
changeset
|
160 for (name, path) in result: |
4617
669e76b7df24
extensions: pull extension-aware bits out of ui
Matt Mackall <mpm@selenic.com>
parents:
4582
diff
changeset
|
161 if path: |
5469
b12432b1c2c7
Allow explicit disabling of extensions
Steve Borho <steve@borho.org>
parents:
5192
diff
changeset
|
162 if path[0] == '!': |
29895
b1ebc767563d
help: show content for explicitly disabled extension (issue5228)
liscju <piotr.listkiewicz@gmail.com>
parents:
29841
diff
changeset
|
163 _disabledextensions[name] = path[1:] |
5469
b12432b1c2c7
Allow explicit disabling of extensions
Steve Borho <steve@borho.org>
parents:
5192
diff
changeset
|
164 continue |
4544
930ed513c864
Create a separate module for managing extensions
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
165 try: |
930ed513c864
Create a separate module for managing extensions
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
166 load(ui, name, path) |
7644
182b7114d35a
error: move SignalInterrupt
Matt Mackall <mpm@selenic.com>
parents:
7388
diff
changeset
|
167 except KeyboardInterrupt: |
4544
930ed513c864
Create a separate module for managing extensions
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
168 raise |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25364
diff
changeset
|
169 except Exception as inst: |
6204
f8a86ea7521b
When failing to load an extension, show where Hg tried to load it from.
Jesse Glick <jesse.glick@sun.com>
parents:
5469
diff
changeset
|
170 if path: |
f8a86ea7521b
When failing to load an extension, show where Hg tried to load it from.
Jesse Glick <jesse.glick@sun.com>
parents:
5469
diff
changeset
|
171 ui.warn(_("*** failed to import extension %s from %s: %s\n") |
f8a86ea7521b
When failing to load an extension, show where Hg tried to load it from.
Jesse Glick <jesse.glick@sun.com>
parents:
5469
diff
changeset
|
172 % (name, path, inst)) |
f8a86ea7521b
When failing to load an extension, show where Hg tried to load it from.
Jesse Glick <jesse.glick@sun.com>
parents:
5469
diff
changeset
|
173 else: |
f8a86ea7521b
When failing to load an extension, show where Hg tried to load it from.
Jesse Glick <jesse.glick@sun.com>
parents:
5469
diff
changeset
|
174 ui.warn(_("*** failed to import extension %s: %s\n") |
f8a86ea7521b
When failing to load an extension, show where Hg tried to load it from.
Jesse Glick <jesse.glick@sun.com>
parents:
5469
diff
changeset
|
175 % (name, inst)) |
25364
de23a552fc23
extensions: show traceback on load failure if --traceback flag is set
Yuya Nishihara <yuya@tcha.org>
parents:
24950
diff
changeset
|
176 ui.traceback() |
4544
930ed513c864
Create a separate module for managing extensions
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
177 |
9410
1c83938b6a8e
extensions: load and configure extensions in well-defined phases
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
178 for name in _order[newindex:]: |
29461
7d88fde2309f
extensions: move uisetup and extsetup to standalone functions
Jun Wu <quark@fb.com>
parents:
29162
diff
changeset
|
179 _runuisetup(name, ui) |
9410
1c83938b6a8e
extensions: load and configure extensions in well-defined phases
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
180 |
9660
e0eae93e6c67
extensions: changed to call extsetup() from extensions.loadall()
Yuya Nishihara <yuya@tcha.org>
parents:
9610
diff
changeset
|
181 for name in _order[newindex:]: |
29461
7d88fde2309f
extensions: move uisetup and extsetup to standalone functions
Jun Wu <quark@fb.com>
parents:
29162
diff
changeset
|
182 _runextsetup(name, ui) |
9660
e0eae93e6c67
extensions: changed to call extsetup() from extensions.loadall()
Yuya Nishihara <yuya@tcha.org>
parents:
9610
diff
changeset
|
183 |
24065
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
184 # Call aftercallbacks that were never met. |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
185 for shortname in _aftercallbacks: |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
186 if shortname in _extensions: |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
187 continue |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
188 |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
189 for fn in _aftercallbacks[shortname]: |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
190 fn(loaded=False) |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
191 |
24950
e6e7d1cce04d
extensions: clear aftercallbacks after execution (issue4646)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24734
diff
changeset
|
192 # loadall() is called multiple times and lingering _aftercallbacks |
e6e7d1cce04d
extensions: clear aftercallbacks after execution (issue4646)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24734
diff
changeset
|
193 # entries could result in double execution. See issue4646. |
e6e7d1cce04d
extensions: clear aftercallbacks after execution (issue4646)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24734
diff
changeset
|
194 _aftercallbacks.clear() |
e6e7d1cce04d
extensions: clear aftercallbacks after execution (issue4646)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24734
diff
changeset
|
195 |
24065
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
196 def afterloaded(extension, callback): |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
197 '''Run the specified function after a named extension is loaded. |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
198 |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
199 If the named extension is already loaded, the callback will be called |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
200 immediately. |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
201 |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
202 If the named extension never loads, the callback will be called after |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
203 all extensions have been loaded. |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
204 |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
205 The callback receives the named argument ``loaded``, which is a boolean |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
206 indicating whether the dependent extension actually loaded. |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
207 ''' |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
208 |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
209 if extension in _extensions: |
24145
28af978c8f13
extensions: indicate loaded for an immediately called afterload callback
Matt Harbison <matt_harbison@yahoo.com>
parents:
24124
diff
changeset
|
210 callback(loaded=True) |
24065
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
211 else: |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
212 _aftercallbacks.setdefault(extension, []).append(callback) |
d8837ad682dd
extensions: support callbacks after another extension loads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23953
diff
changeset
|
213 |
24734
fb6cb1b82f4f
extensions: extract partial application into a bind() function
Eric Sumner <ericsumner@fb.com>
parents:
24145
diff
changeset
|
214 def bind(func, *args): |
fb6cb1b82f4f
extensions: extract partial application into a bind() function
Eric Sumner <ericsumner@fb.com>
parents:
24145
diff
changeset
|
215 '''Partial function application |
fb6cb1b82f4f
extensions: extract partial application into a bind() function
Eric Sumner <ericsumner@fb.com>
parents:
24145
diff
changeset
|
216 |
fb6cb1b82f4f
extensions: extract partial application into a bind() function
Eric Sumner <ericsumner@fb.com>
parents:
24145
diff
changeset
|
217 Returns a new function that is the partial application of args and kwargs |
fb6cb1b82f4f
extensions: extract partial application into a bind() function
Eric Sumner <ericsumner@fb.com>
parents:
24145
diff
changeset
|
218 to func. For example, |
fb6cb1b82f4f
extensions: extract partial application into a bind() function
Eric Sumner <ericsumner@fb.com>
parents:
24145
diff
changeset
|
219 |
fb6cb1b82f4f
extensions: extract partial application into a bind() function
Eric Sumner <ericsumner@fb.com>
parents:
24145
diff
changeset
|
220 f(1, 2, bar=3) === bind(f, 1)(2, bar=3)''' |
fb6cb1b82f4f
extensions: extract partial application into a bind() function
Eric Sumner <ericsumner@fb.com>
parents:
24145
diff
changeset
|
221 assert callable(func) |
fb6cb1b82f4f
extensions: extract partial application into a bind() function
Eric Sumner <ericsumner@fb.com>
parents:
24145
diff
changeset
|
222 def closure(*a, **kw): |
fb6cb1b82f4f
extensions: extract partial application into a bind() function
Eric Sumner <ericsumner@fb.com>
parents:
24145
diff
changeset
|
223 return func(*(args + a), **kw) |
fb6cb1b82f4f
extensions: extract partial application into a bind() function
Eric Sumner <ericsumner@fb.com>
parents:
24145
diff
changeset
|
224 return closure |
fb6cb1b82f4f
extensions: extract partial application into a bind() function
Eric Sumner <ericsumner@fb.com>
parents:
24145
diff
changeset
|
225 |
29763
ce6317dcb944
extensions: set attributes to wrappers so we can trace them back
Jun Wu <quark@fb.com>
parents:
29461
diff
changeset
|
226 def _updatewrapper(wrap, origfn, unboundwrapper): |
ce6317dcb944
extensions: set attributes to wrappers so we can trace them back
Jun Wu <quark@fb.com>
parents:
29461
diff
changeset
|
227 '''Copy and add some useful attributes to wrapper''' |
28310
01dc11e7191f
extensions: extract function that copies function attributes to wrapper
Yuya Nishihara <yuya@tcha.org>
parents:
28155
diff
changeset
|
228 wrap.__module__ = getattr(origfn, '__module__') |
01dc11e7191f
extensions: extract function that copies function attributes to wrapper
Yuya Nishihara <yuya@tcha.org>
parents:
28155
diff
changeset
|
229 wrap.__doc__ = getattr(origfn, '__doc__') |
28312
24f1d3c70c41
extensions: copy extra __dict__ of original function
Yuya Nishihara <yuya@tcha.org>
parents:
28311
diff
changeset
|
230 wrap.__dict__.update(getattr(origfn, '__dict__', {})) |
29763
ce6317dcb944
extensions: set attributes to wrappers so we can trace them back
Jun Wu <quark@fb.com>
parents:
29461
diff
changeset
|
231 wrap._origfunc = origfn |
ce6317dcb944
extensions: set attributes to wrappers so we can trace them back
Jun Wu <quark@fb.com>
parents:
29461
diff
changeset
|
232 wrap._unboundwrapper = unboundwrapper |
28310
01dc11e7191f
extensions: extract function that copies function attributes to wrapper
Yuya Nishihara <yuya@tcha.org>
parents:
28155
diff
changeset
|
233 |
24124
042d95beeee8
extensions: allow extending command synopsis and docstring
Ryan McElroy <rm@fb.com>
parents:
24065
diff
changeset
|
234 def wrapcommand(table, command, wrapper, synopsis=None, docstring=None): |
11519
bbdf1fb1d3e3
extensions: add docstring for wrapcommand().
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11402
diff
changeset
|
235 '''Wrap the command named `command' in table |
bbdf1fb1d3e3
extensions: add docstring for wrapcommand().
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11402
diff
changeset
|
236 |
bbdf1fb1d3e3
extensions: add docstring for wrapcommand().
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11402
diff
changeset
|
237 Replace command in the command table with wrapper. The wrapped command will |
bbdf1fb1d3e3
extensions: add docstring for wrapcommand().
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11402
diff
changeset
|
238 be inserted into the command table specified by the table argument. |
bbdf1fb1d3e3
extensions: add docstring for wrapcommand().
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11402
diff
changeset
|
239 |
bbdf1fb1d3e3
extensions: add docstring for wrapcommand().
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11402
diff
changeset
|
240 The wrapper will be called like |
bbdf1fb1d3e3
extensions: add docstring for wrapcommand().
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11402
diff
changeset
|
241 |
bbdf1fb1d3e3
extensions: add docstring for wrapcommand().
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11402
diff
changeset
|
242 wrapper(orig, *args, **kwargs) |
bbdf1fb1d3e3
extensions: add docstring for wrapcommand().
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11402
diff
changeset
|
243 |
bbdf1fb1d3e3
extensions: add docstring for wrapcommand().
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11402
diff
changeset
|
244 where orig is the original (wrapped) function, and *args, **kwargs |
bbdf1fb1d3e3
extensions: add docstring for wrapcommand().
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11402
diff
changeset
|
245 are the arguments passed to it. |
24124
042d95beeee8
extensions: allow extending command synopsis and docstring
Ryan McElroy <rm@fb.com>
parents:
24065
diff
changeset
|
246 |
042d95beeee8
extensions: allow extending command synopsis and docstring
Ryan McElroy <rm@fb.com>
parents:
24065
diff
changeset
|
247 Optionally append to the command synopsis and docstring, used for help. |
042d95beeee8
extensions: allow extending command synopsis and docstring
Ryan McElroy <rm@fb.com>
parents:
24065
diff
changeset
|
248 For example, if your extension wraps the ``bookmarks`` command to add the |
042d95beeee8
extensions: allow extending command synopsis and docstring
Ryan McElroy <rm@fb.com>
parents:
24065
diff
changeset
|
249 flags ``--remote`` and ``--all`` you might call this function like so: |
042d95beeee8
extensions: allow extending command synopsis and docstring
Ryan McElroy <rm@fb.com>
parents:
24065
diff
changeset
|
250 |
042d95beeee8
extensions: allow extending command synopsis and docstring
Ryan McElroy <rm@fb.com>
parents:
24065
diff
changeset
|
251 synopsis = ' [-a] [--remote]' |
042d95beeee8
extensions: allow extending command synopsis and docstring
Ryan McElroy <rm@fb.com>
parents:
24065
diff
changeset
|
252 docstring = """ |
042d95beeee8
extensions: allow extending command synopsis and docstring
Ryan McElroy <rm@fb.com>
parents:
24065
diff
changeset
|
253 |
042d95beeee8
extensions: allow extending command synopsis and docstring
Ryan McElroy <rm@fb.com>
parents:
24065
diff
changeset
|
254 The ``remotenames`` extension adds the ``--remote`` and ``--all`` (``-a``) |
042d95beeee8
extensions: allow extending command synopsis and docstring
Ryan McElroy <rm@fb.com>
parents:
24065
diff
changeset
|
255 flags to the bookmarks command. Either flag will show the remote bookmarks |
26781
1aee2ab0f902
spelling: trivial spell checking
Mads Kiilerich <madski@unity3d.com>
parents:
25946
diff
changeset
|
256 known to the repository; ``--remote`` will also suppress the output of the |
24124
042d95beeee8
extensions: allow extending command synopsis and docstring
Ryan McElroy <rm@fb.com>
parents:
24065
diff
changeset
|
257 local bookmarks. |
042d95beeee8
extensions: allow extending command synopsis and docstring
Ryan McElroy <rm@fb.com>
parents:
24065
diff
changeset
|
258 """ |
042d95beeee8
extensions: allow extending command synopsis and docstring
Ryan McElroy <rm@fb.com>
parents:
24065
diff
changeset
|
259 |
042d95beeee8
extensions: allow extending command synopsis and docstring
Ryan McElroy <rm@fb.com>
parents:
24065
diff
changeset
|
260 extensions.wrapcommand(commands.table, 'bookmarks', exbookmarks, |
042d95beeee8
extensions: allow extending command synopsis and docstring
Ryan McElroy <rm@fb.com>
parents:
24065
diff
changeset
|
261 synopsis, docstring) |
11519
bbdf1fb1d3e3
extensions: add docstring for wrapcommand().
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11402
diff
changeset
|
262 ''' |
21795
711498bb4ff5
extensions: restore use of callable() since it was readded in Python 3.2
Augie Fackler <raf@durin42.com>
parents:
21229
diff
changeset
|
263 assert callable(wrapper) |
7215
0ab5f21c390b
extensions: add wrapping functions
Matt Mackall <mpm@selenic.com>
parents:
7011
diff
changeset
|
264 aliases, entry = cmdutil.findcmd(command, table) |
0ab5f21c390b
extensions: add wrapping functions
Matt Mackall <mpm@selenic.com>
parents:
7011
diff
changeset
|
265 for alias, e in table.iteritems(): |
0ab5f21c390b
extensions: add wrapping functions
Matt Mackall <mpm@selenic.com>
parents:
7011
diff
changeset
|
266 if e is entry: |
0ab5f21c390b
extensions: add wrapping functions
Matt Mackall <mpm@selenic.com>
parents:
7011
diff
changeset
|
267 key = alias |
0ab5f21c390b
extensions: add wrapping functions
Matt Mackall <mpm@selenic.com>
parents:
7011
diff
changeset
|
268 break |
0ab5f21c390b
extensions: add wrapping functions
Matt Mackall <mpm@selenic.com>
parents:
7011
diff
changeset
|
269 |
0ab5f21c390b
extensions: add wrapping functions
Matt Mackall <mpm@selenic.com>
parents:
7011
diff
changeset
|
270 origfn = entry[0] |
24734
fb6cb1b82f4f
extensions: extract partial application into a bind() function
Eric Sumner <ericsumner@fb.com>
parents:
24145
diff
changeset
|
271 wrap = bind(util.checksignature(wrapper), util.checksignature(origfn)) |
29763
ce6317dcb944
extensions: set attributes to wrappers so we can trace them back
Jun Wu <quark@fb.com>
parents:
29461
diff
changeset
|
272 _updatewrapper(wrap, origfn, wrapper) |
24124
042d95beeee8
extensions: allow extending command synopsis and docstring
Ryan McElroy <rm@fb.com>
parents:
24065
diff
changeset
|
273 if docstring is not None: |
28310
01dc11e7191f
extensions: extract function that copies function attributes to wrapper
Yuya Nishihara <yuya@tcha.org>
parents:
28155
diff
changeset
|
274 wrap.__doc__ += docstring |
24124
042d95beeee8
extensions: allow extending command synopsis and docstring
Ryan McElroy <rm@fb.com>
parents:
24065
diff
changeset
|
275 |
7215
0ab5f21c390b
extensions: add wrapping functions
Matt Mackall <mpm@selenic.com>
parents:
7011
diff
changeset
|
276 newentry = list(entry) |
0ab5f21c390b
extensions: add wrapping functions
Matt Mackall <mpm@selenic.com>
parents:
7011
diff
changeset
|
277 newentry[0] = wrap |
24124
042d95beeee8
extensions: allow extending command synopsis and docstring
Ryan McElroy <rm@fb.com>
parents:
24065
diff
changeset
|
278 if synopsis is not None: |
042d95beeee8
extensions: allow extending command synopsis and docstring
Ryan McElroy <rm@fb.com>
parents:
24065
diff
changeset
|
279 newentry[2] += synopsis |
7215
0ab5f21c390b
extensions: add wrapping functions
Matt Mackall <mpm@selenic.com>
parents:
7011
diff
changeset
|
280 table[key] = tuple(newentry) |
0ab5f21c390b
extensions: add wrapping functions
Matt Mackall <mpm@selenic.com>
parents:
7011
diff
changeset
|
281 return entry |
0ab5f21c390b
extensions: add wrapping functions
Matt Mackall <mpm@selenic.com>
parents:
7011
diff
changeset
|
282 |
0ab5f21c390b
extensions: add wrapping functions
Matt Mackall <mpm@selenic.com>
parents:
7011
diff
changeset
|
283 def wrapfunction(container, funcname, wrapper): |
11402
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
284 '''Wrap the function named funcname in container |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
285 |
11520
94b3bbc886cf
extensions: improve language for wrapfunction() docstring.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11519
diff
changeset
|
286 Replace the funcname member in the given container with the specified |
94b3bbc886cf
extensions: improve language for wrapfunction() docstring.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11519
diff
changeset
|
287 wrapper. The container is typically a module, class, or instance. |
11402
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
288 |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
289 The wrapper will be called like |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
290 |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
291 wrapper(orig, *args, **kwargs) |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
292 |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
293 where orig is the original (wrapped) function, and *args, **kwargs |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
294 are the arguments passed to it. |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
295 |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
296 Wrapping methods of the repository object is not recommended since |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
297 it conflicts with extensions that extend the repository by |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
298 subclassing. All extensions that need to extend methods of |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
299 localrepository should use this subclassing trick: namely, |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
300 reposetup() should look like |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
301 |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
302 def reposetup(ui, repo): |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
303 class myrepo(repo.__class__): |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
304 def whatever(self, *args, **kwargs): |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
305 [...extension stuff...] |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
306 super(myrepo, self).whatever(*args, **kwargs) |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
307 [...extension stuff...] |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
308 |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
309 repo.__class__ = myrepo |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
310 |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
311 In general, combining wrapfunction() with subclassing does not |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
312 work. Since you cannot control what other extensions are loaded by |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
313 your end users, you should play nicely with others by using the |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
314 subclass trick. |
367ce8514da0
extensions: recommend against using wrapfunction for repo methods
Greg Ward <greg-hg@gerg.ca>
parents:
10364
diff
changeset
|
315 ''' |
21795
711498bb4ff5
extensions: restore use of callable() since it was readded in Python 3.2
Augie Fackler <raf@durin42.com>
parents:
21229
diff
changeset
|
316 assert callable(wrapper) |
7215
0ab5f21c390b
extensions: add wrapping functions
Matt Mackall <mpm@selenic.com>
parents:
7011
diff
changeset
|
317 |
0ab5f21c390b
extensions: add wrapping functions
Matt Mackall <mpm@selenic.com>
parents:
7011
diff
changeset
|
318 origfn = getattr(container, funcname) |
21795
711498bb4ff5
extensions: restore use of callable() since it was readded in Python 3.2
Augie Fackler <raf@durin42.com>
parents:
21229
diff
changeset
|
319 assert callable(origfn) |
28311
1b0ef07ba783
extensions: copy attributes to wrapper by wrapfunction()
Yuya Nishihara <yuya@tcha.org>
parents:
28310
diff
changeset
|
320 wrap = bind(wrapper, origfn) |
29763
ce6317dcb944
extensions: set attributes to wrappers so we can trace them back
Jun Wu <quark@fb.com>
parents:
29461
diff
changeset
|
321 _updatewrapper(wrap, origfn, wrapper) |
28311
1b0ef07ba783
extensions: copy attributes to wrapper by wrapfunction()
Yuya Nishihara <yuya@tcha.org>
parents:
28310
diff
changeset
|
322 setattr(container, funcname, wrap) |
7215
0ab5f21c390b
extensions: add wrapping functions
Matt Mackall <mpm@selenic.com>
parents:
7011
diff
changeset
|
323 return origfn |
8871
20a25042fadc
extensions: move extensions listing functions from mercurial.help
Cédric Duval <cedricduval@free.fr>
parents:
8225
diff
changeset
|
324 |
29765
19578bb84731
extensions: add unwrapfunction to undo wrapfunction
Jun Wu <quark@fb.com>
parents:
29764
diff
changeset
|
325 def unwrapfunction(container, funcname, wrapper=None): |
19578bb84731
extensions: add unwrapfunction to undo wrapfunction
Jun Wu <quark@fb.com>
parents:
29764
diff
changeset
|
326 '''undo wrapfunction |
19578bb84731
extensions: add unwrapfunction to undo wrapfunction
Jun Wu <quark@fb.com>
parents:
29764
diff
changeset
|
327 |
19578bb84731
extensions: add unwrapfunction to undo wrapfunction
Jun Wu <quark@fb.com>
parents:
29764
diff
changeset
|
328 If wrappers is None, undo the last wrap. Otherwise removes the wrapper |
19578bb84731
extensions: add unwrapfunction to undo wrapfunction
Jun Wu <quark@fb.com>
parents:
29764
diff
changeset
|
329 from the chain of wrappers. |
19578bb84731
extensions: add unwrapfunction to undo wrapfunction
Jun Wu <quark@fb.com>
parents:
29764
diff
changeset
|
330 |
19578bb84731
extensions: add unwrapfunction to undo wrapfunction
Jun Wu <quark@fb.com>
parents:
29764
diff
changeset
|
331 Return the removed wrapper. |
19578bb84731
extensions: add unwrapfunction to undo wrapfunction
Jun Wu <quark@fb.com>
parents:
29764
diff
changeset
|
332 Raise IndexError if wrapper is None and nothing to unwrap; ValueError if |
19578bb84731
extensions: add unwrapfunction to undo wrapfunction
Jun Wu <quark@fb.com>
parents:
29764
diff
changeset
|
333 wrapper is not None but is not found in the wrapper chain. |
19578bb84731
extensions: add unwrapfunction to undo wrapfunction
Jun Wu <quark@fb.com>
parents:
29764
diff
changeset
|
334 ''' |
19578bb84731
extensions: add unwrapfunction to undo wrapfunction
Jun Wu <quark@fb.com>
parents:
29764
diff
changeset
|
335 chain = getwrapperchain(container, funcname) |
19578bb84731
extensions: add unwrapfunction to undo wrapfunction
Jun Wu <quark@fb.com>
parents:
29764
diff
changeset
|
336 origfn = chain.pop() |
19578bb84731
extensions: add unwrapfunction to undo wrapfunction
Jun Wu <quark@fb.com>
parents:
29764
diff
changeset
|
337 if wrapper is None: |
19578bb84731
extensions: add unwrapfunction to undo wrapfunction
Jun Wu <quark@fb.com>
parents:
29764
diff
changeset
|
338 wrapper = chain[0] |
19578bb84731
extensions: add unwrapfunction to undo wrapfunction
Jun Wu <quark@fb.com>
parents:
29764
diff
changeset
|
339 chain.remove(wrapper) |
19578bb84731
extensions: add unwrapfunction to undo wrapfunction
Jun Wu <quark@fb.com>
parents:
29764
diff
changeset
|
340 setattr(container, funcname, origfn) |
19578bb84731
extensions: add unwrapfunction to undo wrapfunction
Jun Wu <quark@fb.com>
parents:
29764
diff
changeset
|
341 for w in reversed(chain): |
19578bb84731
extensions: add unwrapfunction to undo wrapfunction
Jun Wu <quark@fb.com>
parents:
29764
diff
changeset
|
342 wrapfunction(container, funcname, w) |
19578bb84731
extensions: add unwrapfunction to undo wrapfunction
Jun Wu <quark@fb.com>
parents:
29764
diff
changeset
|
343 return wrapper |
19578bb84731
extensions: add unwrapfunction to undo wrapfunction
Jun Wu <quark@fb.com>
parents:
29764
diff
changeset
|
344 |
29764
8bf97c4c6c2a
extensions: add getwrapperchain to get a list of wrappers
Jun Wu <quark@fb.com>
parents:
29763
diff
changeset
|
345 def getwrapperchain(container, funcname): |
8bf97c4c6c2a
extensions: add getwrapperchain to get a list of wrappers
Jun Wu <quark@fb.com>
parents:
29763
diff
changeset
|
346 '''get a chain of wrappers of a function |
8bf97c4c6c2a
extensions: add getwrapperchain to get a list of wrappers
Jun Wu <quark@fb.com>
parents:
29763
diff
changeset
|
347 |
8bf97c4c6c2a
extensions: add getwrapperchain to get a list of wrappers
Jun Wu <quark@fb.com>
parents:
29763
diff
changeset
|
348 Return a list of functions: [newest wrapper, ..., oldest wrapper, origfunc] |
8bf97c4c6c2a
extensions: add getwrapperchain to get a list of wrappers
Jun Wu <quark@fb.com>
parents:
29763
diff
changeset
|
349 |
8bf97c4c6c2a
extensions: add getwrapperchain to get a list of wrappers
Jun Wu <quark@fb.com>
parents:
29763
diff
changeset
|
350 The wrapper functions are the ones passed to wrapfunction, whose first |
8bf97c4c6c2a
extensions: add getwrapperchain to get a list of wrappers
Jun Wu <quark@fb.com>
parents:
29763
diff
changeset
|
351 argument is origfunc. |
8bf97c4c6c2a
extensions: add getwrapperchain to get a list of wrappers
Jun Wu <quark@fb.com>
parents:
29763
diff
changeset
|
352 ''' |
8bf97c4c6c2a
extensions: add getwrapperchain to get a list of wrappers
Jun Wu <quark@fb.com>
parents:
29763
diff
changeset
|
353 result = [] |
8bf97c4c6c2a
extensions: add getwrapperchain to get a list of wrappers
Jun Wu <quark@fb.com>
parents:
29763
diff
changeset
|
354 fn = getattr(container, funcname) |
8bf97c4c6c2a
extensions: add getwrapperchain to get a list of wrappers
Jun Wu <quark@fb.com>
parents:
29763
diff
changeset
|
355 while fn: |
8bf97c4c6c2a
extensions: add getwrapperchain to get a list of wrappers
Jun Wu <quark@fb.com>
parents:
29763
diff
changeset
|
356 assert callable(fn) |
8bf97c4c6c2a
extensions: add getwrapperchain to get a list of wrappers
Jun Wu <quark@fb.com>
parents:
29763
diff
changeset
|
357 result.append(getattr(fn, '_unboundwrapper', fn)) |
8bf97c4c6c2a
extensions: add getwrapperchain to get a list of wrappers
Jun Wu <quark@fb.com>
parents:
29763
diff
changeset
|
358 fn = getattr(fn, '_origfunc', None) |
8bf97c4c6c2a
extensions: add getwrapperchain to get a list of wrappers
Jun Wu <quark@fb.com>
parents:
29763
diff
changeset
|
359 return result |
8bf97c4c6c2a
extensions: add getwrapperchain to get a list of wrappers
Jun Wu <quark@fb.com>
parents:
29763
diff
changeset
|
360 |
10364
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
361 def _disabledpaths(strip_init=False): |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
362 '''find paths of disabled extensions. returns a dict of {name: path} |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
363 removes /__init__.py from packages if strip_init is True''' |
8872
d0c0013f8713
extensions: simplify by selecting primary hgext
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8871
diff
changeset
|
364 import hgext |
31074
2912b06905dc
py3: use pycompat.fsencode() to convert __file__ to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30575
diff
changeset
|
365 extpath = os.path.dirname( |
2912b06905dc
py3: use pycompat.fsencode() to convert __file__ to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30575
diff
changeset
|
366 os.path.abspath(pycompat.fsencode(hgext.__file__))) |
8964
119d1f664eae
extensions: catch OSError when hgext is not accessible (issue1708)
Cédric Duval <cedricduval@free.fr>
parents:
8896
diff
changeset
|
367 try: # might not be a filesystem path |
119d1f664eae
extensions: catch OSError when hgext is not accessible (issue1708)
Cédric Duval <cedricduval@free.fr>
parents:
8896
diff
changeset
|
368 files = os.listdir(extpath) |
119d1f664eae
extensions: catch OSError when hgext is not accessible (issue1708)
Cédric Duval <cedricduval@free.fr>
parents:
8896
diff
changeset
|
369 except OSError: |
10363
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
370 return {} |
8964
119d1f664eae
extensions: catch OSError when hgext is not accessible (issue1708)
Cédric Duval <cedricduval@free.fr>
parents:
8896
diff
changeset
|
371 |
8871
20a25042fadc
extensions: move extensions listing functions from mercurial.help
Cédric Duval <cedricduval@free.fr>
parents:
8225
diff
changeset
|
372 exts = {} |
8964
119d1f664eae
extensions: catch OSError when hgext is not accessible (issue1708)
Cédric Duval <cedricduval@free.fr>
parents:
8896
diff
changeset
|
373 for e in files: |
8872
d0c0013f8713
extensions: simplify by selecting primary hgext
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8871
diff
changeset
|
374 if e.endswith('.py'): |
d0c0013f8713
extensions: simplify by selecting primary hgext
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8871
diff
changeset
|
375 name = e.rsplit('.', 1)[0] |
d0c0013f8713
extensions: simplify by selecting primary hgext
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8871
diff
changeset
|
376 path = os.path.join(extpath, e) |
d0c0013f8713
extensions: simplify by selecting primary hgext
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8871
diff
changeset
|
377 else: |
d0c0013f8713
extensions: simplify by selecting primary hgext
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8871
diff
changeset
|
378 name = e |
d0c0013f8713
extensions: simplify by selecting primary hgext
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8871
diff
changeset
|
379 path = os.path.join(extpath, e, '__init__.py') |
8877
08636e18268f
extensions: check for path existence only when necessary
Cédric Duval <cedricduval@free.fr>
parents:
8876
diff
changeset
|
380 if not os.path.exists(path): |
08636e18268f
extensions: check for path existence only when necessary
Cédric Duval <cedricduval@free.fr>
parents:
8876
diff
changeset
|
381 continue |
10364
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
382 if strip_init: |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
383 path = os.path.dirname(path) |
10363
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
384 if name in exts or name in _order or name == '__init__': |
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
385 continue |
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
386 exts[name] = path |
29895
b1ebc767563d
help: show content for explicitly disabled extension (issue5228)
liscju <piotr.listkiewicz@gmail.com>
parents:
29841
diff
changeset
|
387 exts.update(_disabledextensions) |
10363
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
388 return exts |
8872
d0c0013f8713
extensions: simplify by selecting primary hgext
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8871
diff
changeset
|
389 |
14317
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
390 def _moduledoc(file): |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
391 '''return the top-level python documentation for the given file |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
392 |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
393 Loosely inspired by pydoc.source_synopsis(), but rewritten to |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
394 handle triple quotes and to return the whole text instead of just |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
395 the synopsis''' |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
396 result = [] |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
397 |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
398 line = file.readline() |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
399 while line[:1] == '#' or not line.strip(): |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
400 line = file.readline() |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
401 if not line: |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
402 break |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
403 |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
404 start = line[:3] |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
405 if start == '"""' or start == "'''": |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
406 line = line[3:] |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
407 while line: |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
408 if line.rstrip().endswith(start): |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
409 line = line.split(start)[0] |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
410 if line: |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
411 result.append(line) |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
412 break |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
413 elif not line: |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
414 return None # unmatched delimiter |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
415 result.append(line) |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
416 line = file.readline() |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
417 else: |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
418 return None |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
419 |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
420 return ''.join(result) |
660b0c1b6196
extensions: move moduledoc to break import loop with help
Matt Mackall <mpm@selenic.com>
parents:
14316
diff
changeset
|
421 |
10363
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
422 def _disabledhelp(path): |
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
423 '''retrieve help synopsis of a disabled extension (without importing)''' |
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
424 try: |
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
425 file = open(path) |
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
426 except IOError: |
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
427 return |
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
428 else: |
14318
1f46be4689ed
help: consolidate topic hooks in help.py
Matt Mackall <mpm@selenic.com>
parents:
14317
diff
changeset
|
429 doc = _moduledoc(file) |
10363
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
430 file.close() |
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
431 |
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
432 if doc: # extracting localized synopsis |
30306
5581b294f3c6
help: show help for disabled extensions (issue5228)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30058
diff
changeset
|
433 return gettext(doc) |
10363
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
434 else: |
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
435 return _('(no help text available)') |
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
436 |
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
437 def disabled(): |
14530
cd31a1cc1521
extensions: update doc of enabled() and disabled() according to d5b525697ddb
Yuya Nishihara <yuya@tcha.org>
parents:
14415
diff
changeset
|
438 '''find disabled extensions from hgext. returns a dict of {name: desc}''' |
14539
558ec14ba6be
extensions: make disabled()/disabledext() load prebuilt index if available
Yuya Nishihara <yuya@tcha.org>
parents:
14530
diff
changeset
|
439 try: |
558ec14ba6be
extensions: make disabled()/disabledext() load prebuilt index if available
Yuya Nishihara <yuya@tcha.org>
parents:
14530
diff
changeset
|
440 from hgext import __index__ |
558ec14ba6be
extensions: make disabled()/disabledext() load prebuilt index if available
Yuya Nishihara <yuya@tcha.org>
parents:
14530
diff
changeset
|
441 return dict((name, gettext(desc)) |
558ec14ba6be
extensions: make disabled()/disabledext() load prebuilt index if available
Yuya Nishihara <yuya@tcha.org>
parents:
14530
diff
changeset
|
442 for name, desc in __index__.docs.iteritems() |
558ec14ba6be
extensions: make disabled()/disabledext() load prebuilt index if available
Yuya Nishihara <yuya@tcha.org>
parents:
14530
diff
changeset
|
443 if name not in _order) |
21229
54d7657d7d1e
setup.py, make: avoid problems with outdated, existing hgext/__index__.py*
Thomas Arendsen Hein <thomas@intevation.de>
parents:
20645
diff
changeset
|
444 except (ImportError, AttributeError): |
14539
558ec14ba6be
extensions: make disabled()/disabledext() load prebuilt index if available
Yuya Nishihara <yuya@tcha.org>
parents:
14530
diff
changeset
|
445 pass |
558ec14ba6be
extensions: make disabled()/disabledext() load prebuilt index if available
Yuya Nishihara <yuya@tcha.org>
parents:
14530
diff
changeset
|
446 |
10363
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
447 paths = _disabledpaths() |
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
448 if not paths: |
16709
9eca39a91964
extensions.disabled: return {} instead of None no extensions are disabled
Augie Fackler <raf@durin42.com>
parents:
16667
diff
changeset
|
449 return {} |
10363
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
450 |
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
451 exts = {} |
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
452 for name, path in paths.iteritems(): |
c07974215b3d
extensions: refactor disabled()
Brodie Rao <me+hg@dackz.net>
parents:
10263
diff
changeset
|
453 doc = _disabledhelp(path) |
14316
d5b525697ddb
extensions: drop maxlength from enabled and disabled
Matt Mackall <mpm@selenic.com>
parents:
14079
diff
changeset
|
454 if doc: |
30306
5581b294f3c6
help: show help for disabled extensions (issue5228)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30058
diff
changeset
|
455 exts[name] = doc.splitlines()[0] |
8871
20a25042fadc
extensions: move extensions listing functions from mercurial.help
Cédric Duval <cedricduval@free.fr>
parents:
8225
diff
changeset
|
456 |
14316
d5b525697ddb
extensions: drop maxlength from enabled and disabled
Matt Mackall <mpm@selenic.com>
parents:
14079
diff
changeset
|
457 return exts |
8871
20a25042fadc
extensions: move extensions listing functions from mercurial.help
Cédric Duval <cedricduval@free.fr>
parents:
8225
diff
changeset
|
458 |
10364
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
459 def disabledext(name): |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
460 '''find a specific disabled extension from hgext. returns desc''' |
14539
558ec14ba6be
extensions: make disabled()/disabledext() load prebuilt index if available
Yuya Nishihara <yuya@tcha.org>
parents:
14530
diff
changeset
|
461 try: |
558ec14ba6be
extensions: make disabled()/disabledext() load prebuilt index if available
Yuya Nishihara <yuya@tcha.org>
parents:
14530
diff
changeset
|
462 from hgext import __index__ |
558ec14ba6be
extensions: make disabled()/disabledext() load prebuilt index if available
Yuya Nishihara <yuya@tcha.org>
parents:
14530
diff
changeset
|
463 if name in _order: # enabled |
558ec14ba6be
extensions: make disabled()/disabledext() load prebuilt index if available
Yuya Nishihara <yuya@tcha.org>
parents:
14530
diff
changeset
|
464 return |
558ec14ba6be
extensions: make disabled()/disabledext() load prebuilt index if available
Yuya Nishihara <yuya@tcha.org>
parents:
14530
diff
changeset
|
465 else: |
558ec14ba6be
extensions: make disabled()/disabledext() load prebuilt index if available
Yuya Nishihara <yuya@tcha.org>
parents:
14530
diff
changeset
|
466 return gettext(__index__.docs.get(name)) |
21229
54d7657d7d1e
setup.py, make: avoid problems with outdated, existing hgext/__index__.py*
Thomas Arendsen Hein <thomas@intevation.de>
parents:
20645
diff
changeset
|
467 except (ImportError, AttributeError): |
14539
558ec14ba6be
extensions: make disabled()/disabledext() load prebuilt index if available
Yuya Nishihara <yuya@tcha.org>
parents:
14530
diff
changeset
|
468 pass |
558ec14ba6be
extensions: make disabled()/disabledext() load prebuilt index if available
Yuya Nishihara <yuya@tcha.org>
parents:
14530
diff
changeset
|
469 |
10364
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
470 paths = _disabledpaths() |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
471 if name in paths: |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
472 return _disabledhelp(paths[name]) |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
473 |
13191
1aea66b71f4f
extensions: warn about invalid extensions when listing disabled commands
Mads Kiilerich <mads@kiilerich.com>
parents:
12779
diff
changeset
|
474 def disabledcmd(ui, cmd, strict=False): |
10364
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
475 '''import disabled extensions until cmd is found. |
16666
b9bef21cd214
extensions: fix documentation of disabledcmd return value
Augie Fackler <raf@durin42.com>
parents:
15199
diff
changeset
|
476 returns (cmdname, extname, module)''' |
10364
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
477 |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
478 paths = _disabledpaths(strip_init=True) |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
479 if not paths: |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
480 raise error.UnknownCommand(cmd) |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
481 |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
482 def findcmd(cmd, name, path): |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
483 try: |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
484 mod = loadpath(path, 'hgext.%s' % name) |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
485 except Exception: |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
486 return |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
487 try: |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
488 aliases, entry = cmdutil.findcmd(cmd, |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
489 getattr(mod, 'cmdtable', {}), strict) |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
490 except (error.AmbiguousCommand, error.UnknownCommand): |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
491 return |
13191
1aea66b71f4f
extensions: warn about invalid extensions when listing disabled commands
Mads Kiilerich <mads@kiilerich.com>
parents:
12779
diff
changeset
|
492 except Exception: |
1aea66b71f4f
extensions: warn about invalid extensions when listing disabled commands
Mads Kiilerich <mads@kiilerich.com>
parents:
12779
diff
changeset
|
493 ui.warn(_('warning: error finding commands in %s\n') % path) |
1aea66b71f4f
extensions: warn about invalid extensions when listing disabled commands
Mads Kiilerich <mads@kiilerich.com>
parents:
12779
diff
changeset
|
494 ui.traceback() |
1aea66b71f4f
extensions: warn about invalid extensions when listing disabled commands
Mads Kiilerich <mads@kiilerich.com>
parents:
12779
diff
changeset
|
495 return |
10364
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
496 for c in aliases: |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
497 if c.startswith(cmd): |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
498 cmd = c |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
499 break |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
500 else: |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
501 cmd = aliases[0] |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
502 return (cmd, name, mod) |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
503 |
16667
bdb7ae65c27c
extensions: don't suggest commands from deprecated extensions
Martin Geisler <mg@lazybytes.net>
parents:
16666
diff
changeset
|
504 ext = None |
10364
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
505 # first, search for an extension with the same name as the command |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
506 path = paths.pop(cmd, None) |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
507 if path: |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
508 ext = findcmd(cmd, cmd, path) |
16667
bdb7ae65c27c
extensions: don't suggest commands from deprecated extensions
Martin Geisler <mg@lazybytes.net>
parents:
16666
diff
changeset
|
509 if not ext: |
bdb7ae65c27c
extensions: don't suggest commands from deprecated extensions
Martin Geisler <mg@lazybytes.net>
parents:
16666
diff
changeset
|
510 # otherwise, interrogate each extension until there's a match |
bdb7ae65c27c
extensions: don't suggest commands from deprecated extensions
Martin Geisler <mg@lazybytes.net>
parents:
16666
diff
changeset
|
511 for name, path in paths.iteritems(): |
bdb7ae65c27c
extensions: don't suggest commands from deprecated extensions
Martin Geisler <mg@lazybytes.net>
parents:
16666
diff
changeset
|
512 ext = findcmd(cmd, name, path) |
bdb7ae65c27c
extensions: don't suggest commands from deprecated extensions
Martin Geisler <mg@lazybytes.net>
parents:
16666
diff
changeset
|
513 if ext: |
bdb7ae65c27c
extensions: don't suggest commands from deprecated extensions
Martin Geisler <mg@lazybytes.net>
parents:
16666
diff
changeset
|
514 break |
bdb7ae65c27c
extensions: don't suggest commands from deprecated extensions
Martin Geisler <mg@lazybytes.net>
parents:
16666
diff
changeset
|
515 if ext and 'DEPRECATED' not in ext.__doc__: |
bdb7ae65c27c
extensions: don't suggest commands from deprecated extensions
Martin Geisler <mg@lazybytes.net>
parents:
16666
diff
changeset
|
516 return ext |
10364
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
517 |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
518 raise error.UnknownCommand(cmd) |
de1e7099d100
dispatch: provide help for disabled extensions and commands
Brodie Rao <me+hg@dackz.net>
parents:
10363
diff
changeset
|
519 |
19769
83d79a00cc24
help: use full name of extensions to look up them for keyword search
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18692
diff
changeset
|
520 def enabled(shortname=True): |
14530
cd31a1cc1521
extensions: update doc of enabled() and disabled() according to d5b525697ddb
Yuya Nishihara <yuya@tcha.org>
parents:
14415
diff
changeset
|
521 '''return a dict of {name: desc} of extensions''' |
8871
20a25042fadc
extensions: move extensions listing functions from mercurial.help
Cédric Duval <cedricduval@free.fr>
parents:
8225
diff
changeset
|
522 exts = {} |
20a25042fadc
extensions: move extensions listing functions from mercurial.help
Cédric Duval <cedricduval@free.fr>
parents:
8225
diff
changeset
|
523 for ename, ext in extensions(): |
20a25042fadc
extensions: move extensions listing functions from mercurial.help
Cédric Duval <cedricduval@free.fr>
parents:
8225
diff
changeset
|
524 doc = (gettext(ext.__doc__) or _('(no help text available)')) |
19769
83d79a00cc24
help: use full name of extensions to look up them for keyword search
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18692
diff
changeset
|
525 if shortname: |
83d79a00cc24
help: use full name of extensions to look up them for keyword search
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18692
diff
changeset
|
526 ename = ename.split('.')[-1] |
9136
31177742f54a
for calls expecting bool args, pass bool instead of int
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9020
diff
changeset
|
527 exts[ename] = doc.splitlines()[0].strip() |
8871
20a25042fadc
extensions: move extensions listing functions from mercurial.help
Cédric Duval <cedricduval@free.fr>
parents:
8225
diff
changeset
|
528 |
14316
d5b525697ddb
extensions: drop maxlength from enabled and disabled
Matt Mackall <mpm@selenic.com>
parents:
14079
diff
changeset
|
529 return exts |
21848
ecdbbb6e5d06
version: show enabled extensions (issue4209)
anatoly techtonik <techtonik@gmail.com>
parents:
21795
diff
changeset
|
530 |
28155
7f430b2ac7fd
extensions: add notloaded method to return extensions failed to load
Jun Wu <quark@fb.com>
parents:
27990
diff
changeset
|
531 def notloaded(): |
7f430b2ac7fd
extensions: add notloaded method to return extensions failed to load
Jun Wu <quark@fb.com>
parents:
27990
diff
changeset
|
532 '''return short names of extensions that failed to load''' |
7f430b2ac7fd
extensions: add notloaded method to return extensions failed to load
Jun Wu <quark@fb.com>
parents:
27990
diff
changeset
|
533 return [name for name, mod in _extensions.iteritems() if mod is None] |
7f430b2ac7fd
extensions: add notloaded method to return extensions failed to load
Jun Wu <quark@fb.com>
parents:
27990
diff
changeset
|
534 |
21848
ecdbbb6e5d06
version: show enabled extensions (issue4209)
anatoly techtonik <techtonik@gmail.com>
parents:
21795
diff
changeset
|
535 def moduleversion(module): |
ecdbbb6e5d06
version: show enabled extensions (issue4209)
anatoly techtonik <techtonik@gmail.com>
parents:
21795
diff
changeset
|
536 '''return version information from given module as a string''' |
ecdbbb6e5d06
version: show enabled extensions (issue4209)
anatoly techtonik <techtonik@gmail.com>
parents:
21795
diff
changeset
|
537 if (util.safehasattr(module, 'getversion') |
ecdbbb6e5d06
version: show enabled extensions (issue4209)
anatoly techtonik <techtonik@gmail.com>
parents:
21795
diff
changeset
|
538 and callable(module.getversion)): |
ecdbbb6e5d06
version: show enabled extensions (issue4209)
anatoly techtonik <techtonik@gmail.com>
parents:
21795
diff
changeset
|
539 version = module.getversion() |
ecdbbb6e5d06
version: show enabled extensions (issue4209)
anatoly techtonik <techtonik@gmail.com>
parents:
21795
diff
changeset
|
540 elif util.safehasattr(module, '__version__'): |
ecdbbb6e5d06
version: show enabled extensions (issue4209)
anatoly techtonik <techtonik@gmail.com>
parents:
21795
diff
changeset
|
541 version = module.__version__ |
ecdbbb6e5d06
version: show enabled extensions (issue4209)
anatoly techtonik <techtonik@gmail.com>
parents:
21795
diff
changeset
|
542 else: |
ecdbbb6e5d06
version: show enabled extensions (issue4209)
anatoly techtonik <techtonik@gmail.com>
parents:
21795
diff
changeset
|
543 version = '' |
ecdbbb6e5d06
version: show enabled extensions (issue4209)
anatoly techtonik <techtonik@gmail.com>
parents:
21795
diff
changeset
|
544 if isinstance(version, (list, tuple)): |
ecdbbb6e5d06
version: show enabled extensions (issue4209)
anatoly techtonik <techtonik@gmail.com>
parents:
21795
diff
changeset
|
545 version = '.'.join(str(o) for o in version) |
ecdbbb6e5d06
version: show enabled extensions (issue4209)
anatoly techtonik <techtonik@gmail.com>
parents:
21795
diff
changeset
|
546 return version |
27990
96bfd2875213
version: verbose list internal and external extension source (issue4731)
liscju <piotr.listkiewicz@gmail.com>
parents:
27637
diff
changeset
|
547 |
96bfd2875213
version: verbose list internal and external extension source (issue4731)
liscju <piotr.listkiewicz@gmail.com>
parents:
27637
diff
changeset
|
548 def ismoduleinternal(module): |
96bfd2875213
version: verbose list internal and external extension source (issue4731)
liscju <piotr.listkiewicz@gmail.com>
parents:
27637
diff
changeset
|
549 exttestedwith = getattr(module, 'testedwith', None) |
29841
d5883fd055c6
extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents:
29765
diff
changeset
|
550 return exttestedwith == "ships-with-hg-core" |