[PATCH] extensions: add loadfailed to return extensions failed to load (API)

Yuya Nishihara yuya at tcha.org
Thu Feb 11 08:22:21 EST 2016


On Wed, 10 Feb 2016 17:07:52 +0000, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1455123574 0
> #      Wed Feb 10 16:59:34 2016 +0000
> # Node ID d58f659625ed84ce90f6eef1403199ba4f18f037
> # Parent  a036e1ae1fbe88ab99cb861ebfc2e4da7a3912ca
> extensions: add loadfailed to return extensions failed to load (API)

This isn't an incompatible API change, so (API) isn't necessary.

> chgserver is designed to preload all the extensions specified in config. The
> server needs to know which extensions fail to load to take futher action, for
> example, reload these extensions or refuse to continue. There is no easy way
> to know this kind of information without duplicating part of extensions.py.
> 
> This patch adds extensions.loadfailed() to access names of extensions failed
> to load.
> 
> diff --git a/mercurial/extensions.py b/mercurial/extensions.py
> --- a/mercurial/extensions.py
> +++ b/mercurial/extensions.py
> @@ -26,6 +26,7 @@
>  _order = []
>  _builtin = set(['hbisect', 'bookmarks', 'parentrevspec', 'progress', 'interhg',
>                  'inotify'])
> +_loadfailed = set()
>  
>  def extensions(ui=None):
>      if ui:
> @@ -130,6 +131,7 @@
>          except KeyboardInterrupt:
>              raise
>          except Exception as inst:
> +            _loadfailed.add(name)

load() has more logic to refuse to load extensions. I'm not sure if it should
be counted as a failure, but if it is, '_extensions[k] is None' means 'k' was
failed to load.

> +  $ cat <<EOF > printproblemic.py
> +  > from mercurial import cmdutil, commands, extensions
> +  > cmdtable = {}
> +  > command = cmdutil.command(cmdtable)
> +  > @command('badexts', norepo=True)
> +  > def badexts(*args):
> +  >     print('BADEXTS: %s' % ' '.join(sorted(extensions.loadfailed())))

Use ui.write() to avoid confusion of print statement/function.


More information about the Mercurial-devel mailing list