Commit Graph

82 Commits

Author SHA1 Message Date
Gregory Szorc
3d27c748ce extensions: use absolute_import 2015-08-08 19:13:14 -07:00
Gregory Szorc
5380dea2a7 global: mass rewrite to use modern exception syntax
Python 2.6 introduced the "except type as instance" syntax, replacing
the "except type, instance" syntax that came before. Python 3 dropped
support for the latter syntax. Since we no longer support Python 2.4 or
2.5, we have no need to continue supporting the "except type, instance".

This patch mass rewrites the exception syntax to be Python 2.6+ and
Python 3 compatible.

This patch was produced by running `2to3 -f except -w -n .`.
2015-06-23 22:20:08 -07:00
Yuya Nishihara
8c4e6f9099 extensions: show traceback on load failure if --traceback flag is set
Before this patch, there was no handy way to investigate the reason why
extension couldn't be loaded.

If ui.debug is set, tracebacks of both "hgext.foo" and "foo" are displayed
because the first ImportError could occur at very deep dependency module.
2015-03-30 16:23:35 +09:00
Gregory Szorc
466d2ce272 extensions: clear aftercallbacks after execution (issue4646)
It was reported that enabling pager without color could cause a hang.
Inserting print statements revealed that the callbacks in
extensions._aftercallbacks were being invoked twice.

extensions.loadall can be called multiple times. If entries in
extensions._aftercallbacks linger between calls, this could result
in double execution of the callbacks. This can lead to unwanted
behavior.

The reproduce steps in the bug seem to only occur when the output of
a command is less than the size of the current screen. This is not
something that can easily be tested. I verified the test case works
with this patch and that pager and color interaction continues to
work. Since we have no existing automated tests for pager, this sadly
appears to be the best testing I can do.
2015-05-06 09:52:10 -07:00
Eric Sumner
89d6b43acb extensions: extract partial application into a bind() function
We use partial function application for wrapping existing Mercurial functions,
and it's implemented separately each time.  This patch extracts the partial
application into a new bind() function that can be used on its own by extensions
when appropriate.

In particular, the evolve extension needs to wrap functions in the various
bundle2 processing dictionaries, which the pre-existing methods don't support.
2015-04-15 12:18:05 -04:00
Matt Harbison
7c735629be extensions: indicate loaded for an immediately called afterload callback
Otherwise, there's no way to tell between the immediate callback when it is
already loaded, and when the extension is not loaded at all.
2015-02-21 00:40:18 -05:00
Ryan McElroy
54e6a6adbc extensions: allow extending command synopsis and docstring
Mercurial uses a synopsis string and the docstring of a command for the
command's help output. Today  there is no way for an extension that adds
functionality to a command to extend either of these help strings.

This patch enables appending to both the doctring and the synopsis, and adds
a test for this functionality. Example usage is shown in the test and is also
described in the docstring of extensions.wrapcommand().
2015-02-09 11:02:45 -08:00
Gregory Szorc
d7228dc186 extensions: support callbacks after another extension loads
An upcoming patch will introduce a dependency between the color and
pager extensions. To prepare for this, we teach extensions how to
register callbacks that can execute when another extension loads.

This patch is based on code provided by Matt Mackall. But significant
parts have changed (such as the ability to register multiple callbacks
and the change in behavior to always call a callback).

I believe that always firing the callback is a good practice. I think
the common use for this feature will be for extensions to say "run this
one-time setup code, after this other extension if possible." Always
running the callback will facilitate this.
2015-02-06 12:07:32 -08:00
Siddharth Agarwal
845426bfe6 extensions: don't quit loading extensions in the middle if traceback is on
This was introduced way back in 2006 (rev e8e3582d6f80) as sys.exit(0) if
loading an extension failed when --traceback was on, then at some point morphed
into a 'return 1' in a function that otherwise returns nothing.

At this point, if ui.traceback is enabled and if loading an extension fails for
whatever reason, including one as innocent as it not being present, we leave
any extensions loaded so far in a bogus half-initialized state. That doesn't
really make any sense.
2015-01-23 20:30:49 -08:00
anatoly techtonik
1ed4ec4c3a version: show enabled extensions (issue4209)
This code is based by hg-versions extension (GPLv2)
by Markus Zapke-Gruendemann <info@keimlink.de>


http://mercurial.selenic.com/wiki/VersionsExtension
2014-06-10 13:44:37 +03:00
Augie Fackler
d39e848921 extensions: restore use of callable() since it was readded in Python 3.2 2014-06-23 09:24:06 -04:00
Thomas Arendsen Hein
aedd3b060c setup.py, make: avoid problems with outdated, existing hgext/__index__.py*
"make clean" already removed __index__.py[cdo], but not the __index__.py
(automatically generated by "python setup.py build_hgextindex").

"setup.py build_hgextindex" did not generate a new index if file
__index__.py[cdo] already existed, because if __index__.py was removed,
the compiled file containing the old information was imported and used.
Generate an empty file (with a new timestamp to generate a new .py[cdo])
instead and make mercurial.extensions ignore the unset docs attribute.

One of the problems was a failed test-help.t, to reproduce:

$ rm hgext/__index__.py*
$ echo 'docs = {"mq": "dummy"}' > hgext/__index__.py
$ make test-help.t

With this a "make clean" or "python setup.py build_hgextindex" helps.
2014-05-05 16:54:15 +02:00
Ed Morley
33ad7df82b extensions: use normpath to allow trailing '\' on Windows (issue4187)
Fixes same issue as 3dadbacb6aa4 but now works on Windows too.

With this patch a trailing backward slash won't prevent the extension from
being found on Windows, and we continue to support any combination of forward
and back slashes within the path.
2014-03-05 09:31:05 +00:00
Matt Mackall
66c8bd54e8 extensions: remove the inotify extension (BC)
This extension has always had correctness issues and has been
unmaintained for years. It is now removed in favor of the third-party
hgwatchman which is maintained and appears to be correct.

Users with inotify enabled in their config files will fall back to
standard status performance.
2014-03-01 16:20:15 -06:00
FUJIWARA Katsunori
495b98fa37 extensions: list up only enabled extensions, if "ui" is specified
Before this patch, "extensions.extensions()" always lists up all
loaded extensions. So, commands handling multiple repositories at a
time like below enable extensions unexpectedly.

  - clone from or push to localhost: extensions enabled only in the
    source are enabled also in the destination

  - pull from localhost: extensions enabled only in the destination
    are enabled also in the source

  - recursive execution in subrepo tree: extensions enabled only in
    the parent or some of siblings in the tree are enabled also in
    others

In addition to it, extensions disabled locally may be enabled
unexpectedly.

This patch checks whether each of extensions should be listed up or
not, if "ui" is specified to "extensions.extensions()", and invokes
"reposetup()" of each extensions only for repositories enabling it.
2013-09-21 21:33:29 +09:00
FUJIWARA Katsunori
af33f66d43 help: use full name of extensions to look up them for keyword search
Before this patch, "hg help -k KEYWORD" fails, if there is the
extension of which name includes ".", because "extensions.load()"
invoked from "help.topicmatch()" fails to look such extension up, even
though it is already loaded in.

"help.topicmatch()" invokes "extensions.load()" with the name gotten
from "extensions.enabled()". The former expects full name of extension
(= key in '[extensions]' section), but the latter returns names
shortened by "split('.')[-1]". This difference causes failure of
looking extension up.

This patch adds "shortname" argument to "extensions.enabled()" to make
it return shortened names only if it is True. "help.topicmatch()"
turns it off to get full name of extensions.

Then, this patch shortens full name of extensions by "split('.')[-1]"
for showing them in the list of extensions.

Shortening is also applied on names gotten from
"extensions.disabled()" but harmless, because it returns only
extensions directly under "hgext" and their names should not include
".".
2013-09-23 20:23:25 +09:00
Kevin Bullock
f74ef64c15 extensions: remove erroneous comment
We actually -do- use the 'ui' argument to print a debug statement.
2013-02-14 13:56:02 -06:00
Angel Ezquerra
4651989f9b extensions: obsolete and remove interhg extension
With the addition of the websub filter extension this extension is no longer
needed. We maintain a sort of backwards compatibility by reading the [interhg]
section and using it as we would use the [websub] section.
2013-02-09 11:00:42 +01:00
Simon Heimberg
8eb4380be9 hooks: print out more information when loading a python hook fails
When loading a python hook with file syntax fails, there is no
information that this happened while loading a hook. When the python
file does not exist even the file name is not printed. (Only that a
file is missing.)

This patch adds this information and a test for loading a non existing file and
a directory not being a python module.
2012-07-06 18:41:25 +02:00
Augie Fackler
52177e47bf extensions.disabled: return {} instead of None no extensions are disabled 2012-05-13 04:06:07 -05:00
Martin Geisler
7724ee63b3 extensions: don't suggest commands from deprecated extensions 2012-05-11 14:00:51 +02:00
Augie Fackler
587cefc90e extensions: fix documentation of disabledcmd return value 2012-05-11 04:33:33 -05:00
Greg Ward
122fc5d49f extensions: print some debug info on import failure
This is handy if hgext.foo exists but has a bogus "import blah":
previously we just discarded the "No module named blah" error. Now at
least you can see it with --debug. Not perfect, but better than
nothing.
2011-10-01 16:42:39 -04:00
Augie Fackler
fdd2f9d735 globally: use safehasattr(x, '__call__') instead of hasattr(x, '__call__') 2011-07-25 16:24:37 -05:00
Yuya Nishihara
5c2b085d52 extensions: make disabled()/disabledext() load prebuilt index if available
__index__ contains a dict of {name: desc} of all extensions.
2011-06-04 20:19:30 +09:00
Yuya Nishihara
e900ecac29 extensions: update doc of enabled() and disabled() according to 96b1098c07ee 2011-06-04 20:01:01 +09:00
Idan Kamara
d5c206ffa2 extensions: raise when trying to find an extension that failed to load
extensions that depend on other extensions (such as record) use this pattern
to check if the dependant extension is available:

    try:
        mq = extensions.find('mq')
    except KeyError:
        return

but since if an error occurs while loading an extension it leaves its entry
in the _extensions map as None, we want to raise in that situation too.

(rather than adding another check if the return value is None)
2011-05-23 23:09:00 +03:00
Matt Mackall
1d5abac148 help: consolidate topic hooks in help.py
This removes loops like cmdutil->revset->help->extensions->cmdutil and
simplifies the code.
2011-05-13 12:57:27 -05:00
Matt Mackall
9fd29f01e9 extensions: move moduledoc to break import loop with help 2011-05-13 11:04:51 -05:00
Matt Mackall
d184ed2af2 extensions: drop maxlength from enabled and disabled
This is a bad/silly API. Instead calculate maxlength in one place in help
it's used and simplify all the callers.
2011-05-13 11:04:51 -05:00
Kevin Gessner
bf8c80ca9d extensions: obsolete and remove parentrevspec extension
As of 48639b58ef80, revsets implements the ^ and ~ operators that this
extension provides, so it's no longer necessary.
2011-04-30 18:27:39 +02:00
Matt Mackall
d27d1fae16 bookmarks: move push/pull command features to core 2011-02-10 13:46:28 -06:00
Matt Mackall
906534053e extensions: add an ignore list for old extensions 2011-02-10 13:46:27 -06:00
Mads Kiilerich
b89ce1b270 extensions: warn about invalid extensions when listing disabled commands
Invalid extensions in hgext/ could in some cases cause a crash when searching
for unknown commands in disabled extensions.

With this change we issue a warning if extracting commands from the extensions
fails. Traceback is available on request.

Reported on https://bugzilla.redhat.com/show_bug.cgi?id=663183 with forest.py.
2010-12-26 00:43:49 +01:00
Erik Zielke
1c7a5f9d36 extensions.load: return module
Makes extensions.load return the module that
it has loaded.

This is done so that callers can get information on this module, which
e.g. can be used for generating docs.
2010-10-19 13:43:40 +02:00
Dan Villiom Podlaski Christiansen
11602a3741 extensions: add a few assertions to wrapfunction() and wrapcommand().
Specifically, assert that the given wrapper is callable in both
functions, and assert that the original was also callable in
wrapfunction().
2010-07-09 11:04:00 +02:00
Dan Villiom Podlaski Christiansen
50d47676be extensions: improve language for wrapfunction() docstring. 2010-07-09 11:13:45 +02:00
Dan Villiom Podlaski Christiansen
5987e4e005 extensions: add docstring for wrapcommand(). 2010-07-09 10:57:57 +02:00
Greg Ward
0756f7dc65 extensions: recommend against using wrapfunction for repo methods
Instead, all extensions should use the "dynamic subclass" trick:
subclass repo.__class__ and then replace repo.__class__ with your new
subclass.  This avoids conflicts that happen when one extension uses
wrapfunction and another uses subclassing to extend the same method of
localrepository.
2010-06-15 13:04:22 -04:00
Brodie Rao
91c6eab10f dispatch: provide help for disabled extensions and commands
Before a command is declared unknown, each extension in hgext is searched,
starting with hgext.<cmdname>. If there's a matching command, a help message
suggests the appropriate extension and how to enable it.

Every extension could potentially be imported, but for cases like rebase,
relink, etc. only one extension is imported.

For the case of "hg help disabledext", if the extension is in hgext, the
extension description is read and a similar help suggestion is printed.
No extension import occurs.
2010-02-07 14:01:43 +01:00
Brodie Rao
b0f0c580fa extensions: refactor disabled() 2010-02-07 11:32:08 +01:00
Matt Mackall
595d66f424 Update license to GPLv2+ 2010-01-19 22:20:08 -06:00
Benoit Boissinot
80a458a464 pychecker: remove unused local variables 2009-10-31 17:04:46 +01:00
Yuya Nishihara
ac33bbc42b extensions: changed to call extsetup() from extensions.loadall()
previously uisetup() was invoked by extensions.loadall(), but
extsetup() was by _dispatch().

there's no need to split them because we have nothing to do
between uisetup() and extsetup().

this fixes issue1824 indirectly.
2009-10-28 23:55:23 +09:00
Alexander Solovyov
32999e4659 make path expanding more consistent
This expands ~user and $FOO constructs in ui.ignore files, [defaults],
[paths], extension paths, and HGRCPATH files.
2009-10-19 22:19:28 +03:00
Martin Geisler
559ff1708d extensions: load and configure extensions in well-defined phases
Extensions are now loaded with a call-graph like this:

  dispatch._dispatch
      extensions.loadall
          extensions.load
                # add foo module to extensions._extensions
          extensions.load
                # add bar module to extensions._extensions

          foo.uisetup(ui)
          bar.uisetup(ui)

      foo.extsetup()
      bar.extsetup()

      commands.table.update(foo.cmdtable)
      commands.table.update(bar.cmdtable)

  hg.repository
      foo.reposetup(ui, repo)
      bar.reposetup(ui, repo)

The uisetup calls could easily be moved out to dispatch._dispatch, but
have been kept in extensions.loadall since at least TortoiseHg calls
extensions.loadall and expects it to call uisetup.

The extensions.load function called uisetup. It now has an unused ui
argument which has been kept for backwards compatibility.
2009-08-29 00:29:16 +02:00
Nicolas Dumazet
7eadbe8d42 for calls expecting bool args, pass bool instead of int
str.splitlines and email.message.as_string both expect a bool argument
defaulting at False: replace f(1) by f(True) and f(0) by f()
2009-07-13 09:50:26 +09:00
Cédric Duval
1fafb1baee extensions: remove dead code
enabled used to be a boolean, and somehow that bit of code inadvertently
slipped through during a refactoring. Effectively dead code, as the
condition can never be triggered.
2009-07-04 12:06:33 +02:00
Cédric Duval
1a0b6e0ded extensions: catch OSError when hgext is not accessible (issue1708)
Temporary workaround for issue1708: on win32 with py2exe, hgext is distributed
inside a zipped file (which anyway does not contain the py files from which we
ought to extract the documentation strings), which raises a WindowsError
(subclasses OSError).

This means that on such platforms the list of disabled extensions won't be
available. Real fix postponed for after Mercurial 1.3.
2009-06-29 19:28:54 +02:00
Cédric Duval
295c588e3f extensions: remove import rendered unnecessary by 69a0fe38731b 2009-06-21 20:34:58 +02:00