Commit Graph

269 Commits

Author SHA1 Message Date
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
Gregory Szorc
28755d2e9a dispatch: only check compatibility against major and minor versions (BC)
Extensions can declare compatibility with Mercurial versions. If an
error occurs, Mercurial will attempt to pin blame on an extension that
isn't marked as compatible.

While all bets are off when it comes to the internal API, my experience
has shown that a monthly/patch release of Mercurial has never broken any
of the extensions I've written. I think that expecting extensions to
declare compatibility with every patch release of Mercurial is asking a
bit much and adds little to no value.

This patch changes the blame logic from exact version matching to only
match on the major and minor Mercurial versions. This means that
extensions only need to mark themselves as compatible with the major,
quarterly releases and not the monthly ones in order to stay current and
avoid what is almost certainly unfair blame. This will mean less work
for extension authors and almost certainly fewer false positives in the
blame attribution.
2015-01-15 20:36:03 -08:00
Augie Fackler
2c187ced4b dispatch: consolidate formatting of ParseErrors 2015-01-26 14:50:36 -05:00
Yuya Nishihara
ceda6fbba9 util.system: use ui.system() in place of optional ui.fout parameter 2014-11-08 13:06:22 +09:00
Mike Edgar
e100ea2d6a error: add CensoredNodeError, will be thrown when content deliberately erased
This change introduces the error plus a corresponding catch in dispatch, to
provide localized error messages.

The verb "censor" is used in this commit and all following to refer to erasing
the content of a revlog revision (filelog, for now) without recalculating node
IDs, leaving that revision invalid. Further work must be done to safely share
such revision data with compliant clients.

I find the analogy to censorship straightforward; for less politically
charged options, consider "erase", "excise", "expunge", or "blackhole".
2014-09-03 15:59:03 -04:00
Augie Fackler
a0fd83333c merge with stable 2014-09-09 13:47:50 -04:00
FUJIWARA Katsunori
0d1dc1fcfa dispatch: check shell alias again after loading extensions (issue4355)
Before this patch, the shell alias causes failure when it takes its
specific (= unknown for "hg") options in the command line, because
"_parse()" can't accept them.

This is the regression introduced by 7849ac1dbc57.

It fixed the issue that ambiguity between shell aliases and commands
defined by extensions was ignored. But it also caused that ambiguous
shell alias is handled in "_parse()" even if it takes specific options
in the command line.

To avoid such failure, this patch checks shell alias again after
loading extensions.

All aliases and commands (including ones defined by extensions) are
completely defined before the 2nd (= newly added in this patch)
"_checkshellalias()" invocation, and "cmdutil.findcmd(strict=False)"
can detect ambiguity between them correctly.

For efficiency, this patch does:

  - omit the 2nd "_checkshellalias()" invocation if "[ui] strict= True"

    it causes "cmdutil.findcmd(strict=True)", of which result should
    be equal to one of the 1st invocation before adding aliases

  - avoid removing the 1st "_checkshellalias()" invocation

    it causes "cmdutil.findcmd(strict=True)" invocation preventing
    shell alias execution from loading extensions uselessly
2014-09-10 00:41:44 +09:00
FUJIWARA Katsunori
906133d681 dispatch: make "_checkshellalias" reusable regardless of adding aliases
To reduce changes in the subsequent patch fixing issue4355, this patch
makes "_checkshellalias" reusable regardless of adding aliases.

In this patch, alias definitions are added and restored, only when
"precheck=True".
2014-09-10 00:41:44 +09:00
Matt Mackall
73a6114d2a help: always show command help with -h (issue4240)
Old behavior:
              hg help x    hg x -h    hg help -e x  hg help -c x
config        topic        topic (!)  -             cmd
showconfig    cmd          topic (!)  -             cmd
rebase        cmd          cmd        ext           cmd

New behavior:
              hg help x    hg x -h    hg help -e x  hg help -c x
config        topic        cmd        -             cmd
showconfig    cmd          cmd        -             cmd
rebase        cmd          cmd        ext           cmd
2014-07-31 14:31:31 -05:00
Razvan Cojocaru
e0ffeec97b config: highlight parse error caused by leading spaces (issue3214)
Added "unexpected leading whitespace" message to parse error
when .hgrc has a line that starts with whitespace.
Helps new users unfamiliar with syntax of rc file.
2014-03-16 17:31:31 +02:00
Yuya Nishihara
ea70238e6f alias: exit from bad definition by Abort 2014-08-13 22:22:24 +09:00
Yuya Nishihara
2d19d347a0 alias: show one-line hint for command provided by disabled extension
It will be a hint of Abort exception.  "hg help <alias>" provides the detailed
version as before.
2014-08-13 22:18:28 +09:00
Yuya Nishihara
02fa6ed1f7 alias: provide "unknowncmd" flag to tell help to look for disabled command
This patch prepares for breaking the call loop: help.help_() -> cmdalias() ->
commands.help_() -> help.help_().
2014-08-13 19:28:42 +09:00
Yuya Nishihara
9f46c8b964 alias: keep error message in "badalias" so that help can see it
Upcoming patches will

 - change help_() to get badalias message without executing cmdalias()
 - raise Abort on bad alias
2014-05-17 21:13:31 +09:00
Siddharth Agarwal
4b5c9f694a alias: expand "$@" as list of parameters quoted individually (BC) (issue4200)
Before this patch, there was no way to pass in all the positional parameters as
separate words down to another command.

(1) $@ (without quotes) would expand to all the parameters separated by a space.
    This would work fine for arguments without spaces, but arguments with spaces
    in them would be split up by POSIX shells into separate words.
(2) '$@' (in single quotes) would expand to all the parameters within a pair of
    single quotes. POSIX shells would then treat the entire list of arguments
    as one word.
(3) "$@" (in double quotes) would expand similarly to (2).

With this patch, we expand "$@" (in double quotes) as all positional
parameters, quoted individually with util.shellquote, and separated by spaces.
Under standard field-splitting conditions, POSIX shells will tokenize each
argument into exactly one word.

This is a backwards-incompatible change, but the old behavior was arguably a
bug: Bourne-derived shells have expanded "$@" as a tokenized list of positional
parameters for a very long time. I could find this behavior specified in IEEE
Std 1003.1-2001, and this probably goes back to much further before that.
2014-08-13 23:21:52 -07:00
Matt Mackall
8a748a627c dispatch: handle empty IOError args
We occasionally throw bare IOError objects (especially in convert),
don't choke on them.
2014-07-01 19:54:48 -05:00
Yuya Nishihara
bc04e2c6cd alias: change return code of bad definition to 255
We use 255 for general command error.

It can't raise util.Abort because help module executes badalias command to get
error message.
2014-05-17 15:14:18 +09:00
Yuya Nishihara
2827ff321c alias: handle shlex error in command aliases
No command should fail with ValueError just because there is unparseable
alias definition.

It returns 1 like other badalias handlers, but should be changed to 255 in
a later version because we use 255 for general command error.
2014-05-17 13:06:16 +09:00
Yuya Nishihara
c5b2af81b6 alias: fix loss of non-zero return code in command aliases
This also includes test for shell aliases.  It avoid using "false" command
because "man false" does not say "exit with 1" but "exit with a status code
indicating failure."
2014-05-17 14:43:06 +09:00
Matt Mackall
b465bcd596 merge with stable 2014-03-25 16:17:16 -05:00