Commit Graph

288 Commits

Author SHA1 Message Date
timeless
f77cdcd3b1 pycompat: switch to util.stringio for py3 compat 2016-04-10 20:55:37 +00:00
timeless
4fdfca9cff help: report source of aliases 2016-04-08 18:35:49 +00:00
Martijn Pieters
b0b9bca0ca dispatch: split out warning message generation to separate function
Allow for patching warning message generation, or for patching out the ui.log /
ui.warn behaviour (but still generate the warning message).
2016-04-05 20:01:23 +01:00
Martijn Pieters
bc2e641437 dispatch: factor out command failure handling into a function
Moving the warning generation to a function allows for wrapping and
alternative error handling.
2016-04-04 17:27:37 +01:00
FUJIWARA Katsunori
7a6d96d902 registrar: add templatefunc to mark a function as template function (API)
This patch also adds loadfunction() to templater, because this
combination helps to figure out how they cooperate with each other.

Listing up loadfunction() in dispatch.extraloaders causes implicit
loading template function at loading (3rd party) extension.

This patch explicitly tests whether templatefunc decorator works as
expected, because there is no bundled extension, which defines
template function.

This change requires that "templatefunc" attribute of (3rd party)
extension is registrar.templatefunc or so.
2016-03-30 02:10:44 +09:00
FUJIWARA Katsunori
098aa2f5a6 registrar: add templatefilter to mark a function as template filter (API)
This patch also adds loadfilter() to templatefilters, because this
combination helps to figure out how they cooperate with each other.

Listing up loadfilter() in dispatch.extraloaders causes implicit
loading template filter functions at loading (3rd party) extension.

This change requires that "templatefilter" attribute of (3rd party)
extension is registrar.templatefilter or so.
2016-03-30 02:10:44 +09:00
Yuya Nishihara
73426f0951 dispatch: show deprecation warning if command has no attributes (issue5137)
norepo/optionalrepo/inferrepo were removed by e1563031f528, which would be
significant API change. This patch tries to avoid crash even if ancient
third-party extensions are enabled.
2016-01-09 22:46:26 +09:00
Yuya Nishihara
f591623eb5 dispatch: extract function that tests command attributes
This function will host the compatibility layer for old third-party commands.
See the next patch for details.
2016-03-14 00:14:43 +09:00
Yuya Nishihara
788633ed56 dispatch: make cmdalias forward command attributes to function
This delays resolution of command attributes so that missing attributes
can be warned only when necessary.
2016-03-14 00:06:52 +09:00
FUJIWARA Katsunori
adbb470b46 registrar: add templatekeyword to mark a function as template keyword (API)
_templateregistrarbase is defined as a super class of templatekeyword,
for ease of adding template common features between "keyword",
"filter" and "function".

This patch also adds loadkeyword() to templatekw, because this
combination helps to figure out how they cooperate with each other.

Listing up loadkeyword() in dispatch.extraloaders causes implicit
loading template keyword functions at loading (3rd party) extension.

This change requires that "templatekeyword" attribute of (3rd party)
extension is registrar.templatekeyword or so.
2016-03-13 05:17:06 +09:00
Jun Wu
75b4a0eb75 dispatch: flush ui before returning from dispatch
A chg client may exit after received the result from runcommand. It is
necessary to do a flush to make sure the warning message is printed out
and the process waiting for the chg client will actually see the output.

This helps chg to pass test-alias.t.
2016-03-14 11:06:34 +00:00
Yuya Nishihara
bd1b10fbe6 dispatch: catch KeyboardInterrupt more broadly
Because _runcatch() can run long operations in its exception handler,
it wasn't enough to catch KeyboardInterrupt at the same level. For
example, "hg unknown" will load all extension modules, so we could
easily make it crashed by Ctrl-C.
2015-12-27 13:38:46 +09:00
Jun Wu
7f24d247cc dispatch: extract common logic for handling ParseError
The way ParseError is handled at two different places in dispatch.py is the
same. Move common logic into _formatparse.
2016-03-14 12:32:09 +00:00
FUJIWARA Katsunori
f997d054b1 registrar: add filesetpredicate to mark a function as fileset predicate
filesetpredicate is used to replace fileset.predicate in subsequent
patch.

This patch also adds loadpredicate() to fileset, because this
combination helps to figure out how the name of "status caller" (or
"existing caller") predicate is put into _statuscallers (or
_existingcallers).

Listing up loadpredicate() in dispatch.extraloaders causes implicit
loading fileset predicate functions at loading (3rd party) extension.
2016-03-11 04:14:54 +09:00
FUJIWARA Katsunori
60e9ee2742 revset: replace extpredicate by revsetpredicate of registrar
This patch consists of changes below (these can't be applied
separately).

  - replace revset.extpredicate by registrar.revsetpredicate in
    extensions

  - remove setup() on an instance named as revsetpredicate in
    uisetup()/extsetup() of each extensions

    registrar.revsetpredicate doesn't have setup() API.

  - put new entry for revsetpredicate into extraloaders in dispatch

    This causes implicit loading predicate functions at loading
    extension.

    This loading mechanism requires that an extension has an instance
    named as revsetpredicate, and this is reason why
    largefiles/__init__.py is also changed in this patch.

Before this patch, test-revset.t tests that all decorated revset
predicates are loaded by explicit setup() at once ("all or nothing").

Now, test-revset.t tests that any revset predicate isn't loaded at
failure of loading extension, because loading itself is executed by
dispatch and it can't be controlled on extension side.
2016-03-08 23:04:53 +09:00
FUJIWARA Katsunori
f9e776bc8b dispatch: make loading extra information from extension extensible
This patch makes loading extra information from extension module at
dispatching extensible. Factoring 'loadcmdtable()' into commands.py is
a part of generalization of loading extra information.

This extensibility assumes registration of new function like below,
for example:

  - revset predicate
  - fileset predicate
  - template keyword
  - template filter
  - template function
  - internal merge tool
  - web command

This patch requires not loader function itself but container module
and the name of it, because listing loader function directly up
implies actual loading module of it, even if it isn't used at runtime
(for example, extensions don't always define revset predicate)
2016-03-08 23:04:53 +09:00
Yuya Nishihara
e4227925aa dispatch: store norepo/optionalrepo/inferrepo attributes in function (API)
This can eliminate import cycles and ugly push/pop of global variables at
_checkshellalias(). Attributes of aliascmd are directly accessible.

Because norepo/optionalrepo/inferrepo lists aren't populated, extensions
examining them no longer work. That's why this patch removes these lists
to signal the API incompatibility.

This breaks 3rd-party extensions that are yet to be ported to @command
decorator.
2016-01-01 22:16:25 +09:00
Jun Wu
fd6f6e6e7a dispatch: add wd parameter to _getlocal
Before this patch, _getlocal uses os.getcwd() to locate repo in current dir.
chgserver needs it to load repo config and has to do chdir twice: the first
is to set current directory and the second is to redo the side effect (in case
hg --cwd some/relative/path, chdir will be called again in dispatch later),
which is not pretty.

This patch adds an optional wd parameter to make it possible to specify wd
without chdir (and its side effect).
2016-02-26 15:07:58 +00:00
Tony Tung
3ed9c83afd dispatch: strip command line options like config file options
Currently, whitespace in command line --config options are considered
significant while whitespace in config files are not considered
significant.  This diff strips the leading and trailing whitespace from
command line config options.
2016-02-08 15:35:30 -08:00
Yuya Nishihara
27d625a5ea dispatch: copy inferrepo attribute to alias commands
The other attributes are copied. Let's do the same for the inferrepo.
2016-01-04 21:40:05 +09:00
timeless
7ff607f2d6 error: make InterventionRequired take a hint 2015-12-23 08:52:52 +00:00
Bryan O'Sullivan
ca96e23cd1 dispatch: report similar names consistently 2016-01-04 21:52:44 -08:00
Gregory Szorc
edf696301c dispatch: use print function
Python 3 doesn't have a print statement.
2015-06-21 21:45:41 -07:00
timeless
da2a72be71 error: make ParseError inherit from HintException 2015-12-23 17:39:32 +00:00
timeless
65f4d64bf2 help: fix help -c/help -e/help -k
Before, hg help -c was the same as hg help, now it only shows commands.
Before, hg help -e was the same as hg help, now it only shows extensions.
Before, hg help -k crashed, now it shows all topics.
2015-12-09 05:56:54 +00:00
Gregory Szorc
f29561137a dispatch: use versiontuple()
We have a new generic function for this. Use it.
2015-11-24 14:23:46 -08:00
Pierre-Yves David
30913031d4 error: get Abort from 'error' instead of 'util'
The home of 'Abort' is 'error' not 'util' however, a lot of code seems to be
confused about that and gives all the credit to 'util' instead of the
hardworking 'error'. In a spirit of equity, we break the cycle of injustice and
give back to 'error' the respect it deserves. And screw that 'util' poser.

For great justice.
2015-10-08 12:55:45 -07:00
Matt Mackall
5e1b4ad958 urls: bulk-change primary website URLs 2015-09-30 15:43:49 -05:00
Jordi Gutiérrez Hermoso
8a7abebe42 dispatch: don't stack trace on commands like hg .log
This used to stack trace because it raised a util.Abort which wasn't
handled in this block. We now handle it. Additionally, we error out
earlier instead of plodding on and showing the "log" entry of the
plain `hg help` output.
2015-09-25 11:16:20 -04:00
Daniel Colascione
4eefceee97 dispatch: stop warning about EPIPE in --debug mode
It seems silly for "hg --debug manifest | less" to print a scary
message after the user hits "q" in less.  hg should just exit silently
instead, since EPIPE on stdout is a perfectly reasonable result.
2015-09-24 10:15:37 +03:00
Pierre-Yves David
4595c06fb1 traceback: allow providing a local support contact point
The extensions blaming code is fine for casual users but pretty terrible for
corporate environments that can deploy a large amount of extensions to
unsuspecting users. Reports will likely blame a random "innocent" extension (in
our case crecord) and the hint in the message will triggers endless debug
attempts from the user.

We introduce a "ui.supportcontact" option that allow such big company to redirect
their users to their own support desk. This disables all extensions blaming and
just point people to the local support in all cases.
2015-09-11 12:45:19 -07:00
Pierre-Yves David
50db85e952 dispatch: pre-indent the extensions blaming logic
We are about to put some real conditional here, but pre-indenting in it's own
changesets makes next patch much cleaner.
2015-09-17 11:50:55 -07:00
Jordi Gutiérrez Hermoso
b64649a4e1 dispatch: use the right context manager to deactivate demandimport
In 4bc3dc605581 I very embarrassingly wrote a patch with the
completely wrong function name. This should fix it.
2015-09-13 16:30:21 -04:00
Jordi Gutiérrez Hermoso
9269dd23a1 dispatch: disable demandimport when invoking the debugger
Turns out that demandimport confuses pudb, which does some pretty
complicated imports. I think it's reasonable to disable demandimport
here.
2015-09-10 09:30:10 -04:00
Durham Goode
74879ebad9 profiling: allow logging profile to the blackbox
This allows specifying '--config profiling.output=blackbox' which will log the
profile output to the blackbox (if enabled). This is useful for doing profiling
on the server since it allows us to record the command, it's result, any
exceptions, and it's profile, all in one spot.  And we get log rotation for
free.
2015-09-08 11:39:52 -07:00
Durham Goode
3402ff59db profiling: add config option for enabling profiling
Previously you could only enable profiling via the --profile option. This is
awkward when trying to debug a server side operation. Let's add a config option
to enable profiling.

In the future, this could be extended to allow profiling a certain percentage of
operations (and potentially reporting that information to an external service).
2015-09-07 11:35:40 -07:00
Yuya Nishihara
69537fb219 dispatch: error out on invalid -R path even if optionalrepo (issue4805) (BC)
Before this patch, repo could be set to None for wrong -R. It's okay for
commands that can reject repo=None, but the command server have a problem
because:

 - it accepts repo=None for "unbound" mode
 - and it reenters dispatch() where repo object is created for cwd by default

Test outputs are changed because the error is detected earlier. I think new
message is better than ".hg not found".
2015-08-31 23:29:15 +09:00
Gregory Szorc
177174bac6 dispatch: use absolute_import
A mixed, ambiguous import has been removed!
2015-08-08 14:42:48 -07:00
Matt Mackall
694178b7ed profiler: mark developer-only config option 2015-06-25 17:46:29 -05:00
Matt Mackall
48e65fe108 debugger: mark developer-only option
(and rearrange comment)
2015-06-25 17:45:49 -05: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
Jordi Gutiérrez Hermoso
92cd916ad6 dispatch: disable demandimport for the --debugger option
Something in Python 2.7.9 or so broke the --debugger option with
ui.debugger = ipdb. I get the traceback below. There is some apparent
confusion with demandimport. This should be disabled anyway for the
--debugger option. The debugger must be imported right away, before
any other dispatch. There's no benefit in delaying the debugger
import.

This patch uses the demandimport.deactivated() context manager.

  Traceback (most recent call last):
    File "/usr/lib/python2.7/dist-packages/mercurial/dispatch.py", line 121, in _runcatch
      debugmod = __import__(debugger)
    File "/usr/lib/python2.7/dist-packages/mercurial/demandimport.py", line 115, in _demandimport
      return _hgextimport(_import, name, globals, locals, fromlist, level)
    File "/usr/lib/python2.7/dist-packages/mercurial/demandimport.py", line 47, in _hgextimport
      return importfunc(name, globals, *args)
    File "/usr/lib/python2.7/dist-packages/ipdb/__init__.py", line 16, in <module>
      from ipdb.__main__ import set_trace, post_mortem, pm, run, runcall, runeval, launch_ipdb_on_exception
    File "/usr/lib/python2.7/dist-packages/mercurial/demandimport.py", line 134, in _demandimport
      mod = _hgextimport(_origimport, name, globals, locals)
    File "/usr/lib/python2.7/dist-packages/mercurial/demandimport.py", line 47, in _hgextimport
      return importfunc(name, globals, *args)
    File "/usr/lib/python2.7/dist-packages/ipdb/__main__.py", line 29, in <module>
      if IPython.__version__ > '0.10.2':
    File "/usr/lib/python2.7/dist-packages/mercurial/demandimport.py", line 106, in __getattribute__
      self._load()
    File "/usr/lib/python2.7/dist-packages/mercurial/demandimport.py", line 78, in _load
      mod = _hgextimport(_import, head, globals, locals, None, level)
    File "/usr/lib/python2.7/dist-packages/mercurial/demandimport.py", line 47, in _hgextimport
      return importfunc(name, globals, *args)
    File "/usr/lib/python2.7/dist-packages/IPython/__init__.py", line 45, in <module>
      from .config.loader import Config
    File "/usr/lib/python2.7/dist-packages/mercurial/demandimport.py", line 132, in _demandimport
      return _origimport(name, globals, locals, fromlist, level)
    File "/usr/lib/python2.7/dist-packages/IPython/config/__init__.py", line 16, in <module>
      from .application import *
    File "/usr/lib/python2.7/dist-packages/mercurial/demandimport.py", line 115, in _demandimport
      return _hgextimport(_import, name, globals, locals, fromlist, level)
    File "/usr/lib/python2.7/dist-packages/mercurial/demandimport.py", line 47, in _hgextimport
      return importfunc(name, globals, *args)
    File "/usr/lib/python2.7/dist-packages/IPython/config/application.py", line 30, in <module>
      from IPython.external.decorator import decorator
    File "/usr/lib/python2.7/dist-packages/mercurial/demandimport.py", line 134, in _demandimport
      mod = _hgextimport(_origimport, name, globals, locals)
    File "/usr/lib/python2.7/dist-packages/mercurial/demandimport.py", line 47, in _hgextimport
      return importfunc(name, globals, *args)
    File "/usr/lib/python2.7/dist-packages/IPython/external/decorator/__init__.py", line 2, in <module>
      from decorator import *
    File "/usr/lib/python2.7/dist-packages/mercurial/demandimport.py", line 115, in _demandimport
      return _hgextimport(_import, name, globals, locals, fromlist, level)
    File "/usr/lib/python2.7/dist-packages/mercurial/demandimport.py", line 47, in _hgextimport
      return importfunc(name, globals, *args)
    File "/usr/lib/python2.7/dist-packages/decorator.py", line 240, in <module>
      'ContextManager', (_GeneratorContextManager,), dict(__call__=__call__))
2015-05-28 16:42:21 -04:00
Matt Mackall
a6696debd5 profile: disable nested report in lsprof by default
The nesting makes profiles harder to read and often pushes important
data off the end of the report.
2015-05-22 12:14:23 -05:00
Pierre-Yves David
8e64cd3aeb error: allow a 'hint' to OutOfBandError
This will be useful when changing the behavior of OutOfBandError for ssh in the
next changeset.
2015-05-20 18:17:40 -05:00
Augie Fackler
8aa1286c70 dispatch: add support for python-flamegraph[0] profiling
This gives us nicer svg flame graphs for output, which can make
understanding some types of performance problems significantly easier.

0: https://github.com/evanhempel/python-flamegraph/
2015-04-16 17:12:33 -04:00
Yuya Nishihara
29fb442439 ssl: set explicit symbol "!" to web.cacerts to disable SSL verification (BC)
The next patch will enable verification by using the system's CA store if
possible, which means we would have to distinguish None (=use default) from
'' (=--insecure). This smells bug-prone and provides no way to override
web.cacerts to forcibly use the system's store by --config argument.

This patch changes the meaning of web.cacerts as follows:

  value   behavior
  ------- ---------------------------------------
  None/'' use default
  '!'     never use CA certs (set by --insecure)
  <path>  verify by the specified CA certificates

Values other than <path> are for internal use and therefore undocumented.
2015-03-04 23:27:04 +09:00
Augie Fackler
dbd43329ce dispatch: offer suggestions of similar-named commands
When suggestions are available, we show those suggestions instead of
showing some help output.
2015-02-10 15:59:12 -05:00
Augie Fackler
6941008520 dispatch: offer near-edit-distance suggestions for {file,rev}set functions
Before this patch, when I have a brain fart and type `hg log -r
'add(foo)'`, hg exits and just says add isn't a function, leading me
to the help page for revset to figure out how to spell the
function. With this patch, it suggests 'adds' as a function I might
have meant.
2015-01-26 15:43:13 -05:00
Matt Mackall
b907416f7b merge with stable 2015-03-02 01:20:14 -06:00
Yuya Nishihara
be4fae44fb dispatch: work around UnicodeDecodeError caused by SSLError of Python 2.7.9
SSLError of Python 2.7.9 may keep error message in unicode. It will be
wrapped by URLError(reason) at KeepAliveHandler.do_open, so inst.reason can
be a unicode.

https://hg.python.org/cpython/file/v2.7.9/Modules/_ssl.c#l329
2015-02-26 23:30:33 +09:00