Commit Graph

262 Commits

Author SHA1 Message Date
Sean Farley
480e39282c dispatch: move command line --config argument parsing to _runcatch()
Previously, command line parsing of --config arguments was done in
_dispatch. This means that it takes place after activating the debugger. In an
upcoming patch, we will add a ui.debugger setting so we need to have this
parsing done before _runcatch.
2013-07-13 16:33:07 -05:00
Durham Goode
1e38cba77a blackbox: fix recording exit codes (issue3938)
Previously the blackbox wrapped runcommand, but this failed to see the error
codes that were created if an exception occurred. I moved that logging to now
wrap _runcatch, so it can observe and log the actual error code (such as when
a user ctrl+c's during a command).

Updated the tests as well. Tested the change by running all the tests with the
blackbox extension enabled and verifying nothing broke (aside from things that
printed what extensions were enabeld).

The progress tests are affected by calls to time.time() so they needed to be
updated to pass.
2013-05-22 17:31:47 -07:00
Bryan O'Sullivan
fe88e48153 dispatch: add support for --option=value to _earlygetopt
This fixes a very confusing error message:

  $ hg --config=pager.enabled=off st
  abort: option --config may not be abbreviated!
2013-04-29 14:14:42 -07:00
Bryan O'Sullivan
6ad1b7d190 dispatch: add doctests for _earlygetopt 2013-04-29 14:14:41 -07:00
Siddharth Agarwal
33d0a49008 dispatch: print 'abort:' when a pre-command hook fails (BC)
This also changes the exit code from whatever the hook returned to 255. This
brings it in line with all the other hooks that abort.
2013-04-16 14:39:37 -07:00
Augie Fackler
be59bb31f7 dispatch: exit with status 1 for an InterventionRequired exception (bc) 2013-02-08 16:17:46 -06:00
Augie Fackler
818d095a0a dispatch: catch InterventionRequired and print the message with no prefix 2013-02-08 16:28:24 -06:00
Durham Goode
2d704dd602 blackbox: fix exception when logging commands with format characters
When running commands like 'hg export -o mypatch-%N.patch', the blackbox
would throw an exception because it tried to format %N. This change
prevents it from trying to format the command string.
2013-02-28 10:12:26 -08:00
Simon Heimberg
e0c976111f dispatch: also a separate warning message on aliases with --config
As mentioned in bug 2043, --config is also not supported in an alias. So report
this the same way as the other "early" options.

Example with alias.broken = stat --config a.config=1

Before:
  $ hg broken
  abort: Option --config may not be abbreviated!

After:
  $ hg broken
  error in definition for alias 'broken': --config may only be given on the command line
2013-02-12 22:15:31 +01:00
Durham Goode
7b7c4c6333 blackbox: do not translate the log messages
User 'timeless' in irc mentioned that having the blackbox be
translated would result in logs that:

- may be mixed language, if multiple users use the same repo
- are not google searchable (since searching for english gives more
  results)
- might not be readable by an admin if the employee is using hg in
  his native language

And therefore we should log everything in english.
2013-02-13 12:51:30 -08:00
Durham Goode
49b2c47b06 blackbox: log the commands that are run
Uses ui.log to log which commands are run, their exit code, the time taken,
and any unhandled exceptions thrown.

Example log lines:
2013/02/09 08:35:19 durham> add foo
2013/02/09 08:35:19 durham> add exited 0 after 0.02 seconds

Updates the progress tests because they use a mocked time.time() which these
changes affect.
2013-02-09 09:04:14 -08:00
Mads Kiilerich
a13d45eee6 profiling: introduce limit configuration option
The number of output lines was hardcoded to 30.

There was a 'nested' configuration options that controlled something else
related to counting the number of output lines.

This introduces the profiling.limit configuration option for controlling the
number of profiling output to show.
2013-02-04 02:46:53 +01:00
Pierre-Yves David
4e9586f18e clfilter: enforce hidden filtering on all repository accesses
We ensure all repositores created through `mercurial.hg.repository`
are "hidden" filtered. This is an even stronger enforcement than
86530c899687.

Citing Matt's response to changeset 86530c899687 installing filtering
in dispatch:

> Unfortunately, this means that code that doesn't go through dispatch (ie all
> those crazy misguided people using Mercurial as a library) are going to see
> these hidden changesets.
>
> Might be better to instead install the filter in localrepo construction by
> default and disable it in dispatch.
2013-01-11 20:34:54 +01:00
Pierre-Yves David
a1985448ad clfilter: enforce hidden changeset globally
The dispatch code now enables filtering of "hidden" changesets globally. The
filter is installed before command and extension invocation. The `--hidden`
switch is now global and disables this filtering for any command.

Code in log dedicated to changeset exclusion is removed as this global filtering
has the same effect.
2013-01-08 20:37:37 +01:00
Mads Kiilerich
5584e7ca16 dispatch: show empty filename in OSError aborts
Mercurial would sometimes exit with:
  abort: No such file or directory
where str of the actual OSError exception was the more helpful:
  [Errno 2] No such file or directory: ''

The exception will now always show the filename and quote it:
  abort: No such file or directory: ''
2013-01-07 02:00:29 +01:00
Pierre-Yves David
ed7bbaa14c dispatch: handle empty testedwith value in extension
When extensions had an empty `testedwith` attribute the code tried to parse it
and failed. As a result the actual error were shallowed by a This crash.

We now treat empty strip as 'unknown'
2013-01-04 19:06:42 +01:00
Siddharth Agarwal
a5e71891bd commands: don't infer repo for commands like update (issue2748)
Maintain a whitelist of commands to infer the repo for instead. The whitelist
contains those commands that take file(s) in the working dir as arguments.
2012-10-16 11:43:15 -07:00
Mads Kiilerich
688b9e2048 check-code: indent 4 spaces in py files 2012-07-31 03:30:42 +02:00
Thomas Arendsen Hein
2b505739fb dispatch: fix traceback when extension was tested with newer versions only
The "worst" extension still is the one tested with the lowest tested version
below the current version of Mercurial, but if an extension with was only
tested with newer versions, it is considered a candidate for a bad extension,
too. In this case extensions which have been tested with higher versions of
Mercurial are considered better. This allows finding the oldest extension if
ct can't be calculated correctly and therefore defaults to an empty tuple, and
it involves less changes to the comparison logic during the current code
freeze.
2012-07-19 21:20:56 +02:00
Martin Geisler
65ea7aa7d4 dispatch: lowercase --time message 2012-06-12 14:18:18 +02:00
Adrian Buehlmann
cf5a074e7d dispatch: tolerate non-standard version strings in tuplever() (issue3470)
When developing, we may see non-standard version strings of the form

  5d64306f39bb+20120525

which caused tuplever() to raise

  ValueError: invalid literal for int() with base 10: '5d64306f39bb'

and shadowing the real traceback.
2012-05-25 14:24:07 +02:00
Augie Fackler
1d813c0d7e dispatch: try and identify third-party extensions as sources of tracebacks
Extension authors should explicitly declare their supported hg
versions and include a buglink attribute in their extension. In the
event that a traceback occurs, we'll identify the
least-recently-tested extensionas the most likely source of the defect
and suggest the user disable that extension.

Packagers should make every effort to ship hg versions from exact
tags, or with as few modifications as possible so that the versioning
can work appropriately.
2012-05-16 16:18:07 -05:00
Brodie Rao
7f47d4e347 check-code: ignore naked excepts with a "re-raise" comment
This also promotes the naked except check from a warning to an error.
2012-05-13 13:18:06 +02:00
Brodie Rao
a7ef0a0cc5 cleanup: "not x in y" -> "x not in y" 2012-05-12 16:00:57 +02:00
Brodie Rao
d6a6abf2b0 cleanup: eradicate long lines 2012-05-12 15:54:54 +02:00
Patrick Mezard
9c5568246f alias: inherit command optionalrepo flag (issue3298)
Commands working without a repository, like "init", are listed in
commands.norepo. Commands optionally using a repository, like "showconfig", are
listed in commands.optionalrepo. Command aliases were inheriting the former but
not the latter.
2012-05-05 12:21:22 +02:00
Yuya Nishihara
8284425c7d commands: parse ui.strict config item as bool 2012-05-06 23:58:04 +09:00
Bryan O'Sullivan
af2413c514 dispatch: add support for statprof as a profiler
This can be selected using the config variable profiling.type or
the environment variable HGPROF ("ls" for the default, "stat" for
statprof).  The only tuneable is the frequency, profiling.freq,
which defaults to 1000 Hz.

If statprof is not available, a warning is printed.
2012-04-09 13:48:45 -07:00
Matt Mackall
2cf26ea8f0 merge with stable 2012-03-27 16:17:46 -05:00
Matt Mackall
3eb6e77c5e alias: abort on missing positional args (issue3331) 2012-03-27 16:13:59 -05:00
Matt Mackall
39c1d7334a merge with stable 2012-03-22 17:08:05 -05:00
Matt Mackall
8fac36f6df aliases: use empty string for missing position parameters (issue3331) 2012-03-22 17:07:39 -05:00
Matt Mackall
000c79b7ce profile: add undocumented config options for profiler output 2012-03-15 15:59:26 -05:00
Martin Geisler
cf414756e1 dispatch: lowercase abort message 2012-01-06 16:16:58 +01:00
Martin Geisler
237daccf1b dispatch: remove extra newline
The return statement belongs to the lines above.
2011-12-10 18:40:05 +01:00
Matt Mackall
75db0d196a merge with stable 2011-11-17 16:53:17 -06:00
Mads Kiilerich
065de91b14 add missing localization markup 2011-11-11 01:07:10 +01:00
Mads Kiilerich
06a1eb11e4 dispatch: exit with 8-bit exit code
The exit code returned from a program to the shell is unsigned 8-bit, but
Mercurial would sometimes try to exit with negative numbers or None. sys.exit
on Unix will convert that to 8-bit exit codes, but on Windows negative values
showed up as 0.

The exit code is now explicitly converted to unsigned 8-bit.
2011-11-07 03:14:53 +01:00
Augie Fackler
b0cd40af6a alias: don't shadow commands that we only partially matched (issue2993) (BC)
Previously, if you set an alias for "ci", it'd also shadow "commit"
even though you didn't specify that. This occurred for all commands
with explicit short variations.
2011-10-11 17:20:03 -05:00
Matt Mackall
96e41d94f5 merge with stable 2011-08-05 16:07:51 -05:00
Matt Mackall
1731276051 help: drop with_version
If --version is specified, we print the version and exit (as documented).
2011-08-04 15:08:41 -05:00
Idan Kamara
073a89cf8a dispatch: don't rewrap aliases that have the same definition
Previously aliases that overrode existing commands would wrap the old alias
on every call to dispatch() (twice actually), which is an obvious re-entrancy
issue for things like the command server or TortoiseHG.
2011-08-04 19:41:23 +03:00
Andrew Pritchard
2d8acb3e0b wireproto: add out-of-band error class to allow remote repo to report errors
Older clients will still print the provided error message and not much else:
over ssh, this will be each line prefixed with 'remote: ' in addition to an
"abort: unexpected response: '\n'"; over http, this will be the '---%<---'
banners in addition to the 'does not appear to be a repository' message.

Currently, clients with this patch will display 'abort: remote error:\n' and
the provided error text, but it is trivial to style the error text however is
deemed appropriate.
2011-08-02 15:21:10 -04:00
Matt Mackall
e75325116a merge with stable 2011-08-01 10:54:34 -05:00
Idan Kamara
19f1b36e00 dispatch: make sure global options on the command line take precedence
So if a user has verbose=True somewhere in his .hgrc files, giving -q
on the command line will override that.

This basically reverts cd10f447ccba.
2011-07-30 21:04:14 +03:00
David Golub
11baa243a9 dispatch: avoid double backslashes in error message
The use of %r in the format string caused Python to display Windows paths with
double backslashes.
2011-07-21 16:02:34 -04:00
Idan Kamara
27bbf9363c dispatch: don't use request repo if we have --cwd 2011-07-11 17:46:55 +03:00
Pierre-Yves David
f95a6cfc12 error: Add a hint argument to RepoError
This use the same mechanism than Abort. Except clause stay distinct
because RepoError add "!" at the end of the message.
2011-06-25 02:30:17 +02:00
Idan Kamara
a1bff0c5fe dispatch: set config options on the request repo.ui 2011-06-24 19:44:59 +03:00
Idan Kamara
f0f55bda59 dispatch: return read config options 2011-06-24 19:44:59 +03:00
Idan Kamara
122edf3c57 dispatch: set global options on the request repo.ui
If the request has a repo, and global options such as --verbose are passed,
we need to set those explicitly on the repo.ui.
2011-06-24 19:44:58 +03:00
Idan Kamara
ff97debbbd dispatch: make sure unspecified global ui options don't override old values 2011-06-24 12:16:14 +03:00
Idan Kamara
c368cbab93 dispatch: set descriptors on the request repo.ui 2011-06-24 19:38:28 +03:00
Idan Kamara
22edb918b3 dispatch: pass the correct ui to runcommand
For commands that take a repo, repo.ui is passed as the ui to runcommand.
This restores that behaviour when the request has a repo.
2011-06-24 19:36:44 +03:00
Idan Kamara
848255e076 dispatch: check for None before closing repo
We were trying to call close() if repo == None and req.repo != None.
This can happen when running commands that don't take a repo.
2011-06-24 16:30:43 +03:00
Idan Kamara
27964e7418 dispatch: do not close the request repo
Closing here means we've closed the repo passed to us in the request,
which is not our responsibility.

This is essential for bundlerepo, and possibly other localrepository
subclasses who do something in their close().
2011-06-21 17:08:21 +03:00
David Soria Parra
881ac28f17 i18n: remove translation of debug messages 2011-06-21 18:35:13 +02:00
Martin Geisler
01ba8f6e18 Backed out changeset 48c996bf6ba4
Debug messages should not be translated.
2011-06-21 14:57:17 +02:00
David Soria Parra
81153f2f12 dispatch: translate alias debugging messages 2011-06-21 13:24:19 +02:00
Idan Kamara
5e2d608efc dispatch: write shell alias output to ui out descriptor 2011-06-07 13:39:09 +03:00
Idan Kamara
c2b2fe4489 dispatch: fix for-loop variable name 2011-06-14 20:25:38 +03:00
Idan Kamara
c08a096623 dispatch: assign I/O descriptors from the request to the ui 2011-06-08 14:54:47 +03:00
Idan Kamara
e05ad378b0 dispatch: add I/O descriptors to the request 2011-06-07 13:39:09 +03:00
Idan Kamara
b335d3e278 dispatch: propagate ui command options to the local ui (issue2523)
so the ui object passed to pre/post python hooks has the verbose flag
(and the rest) set correctly
2011-06-13 00:19:26 +03:00
Idan Kamara
a910ab36b8 dispatch: add repo to the request
allows callers of dispatch.dispatch to pass in
an initialized repo object to be used.

-R/--repository overrides the request repo.
2011-06-02 00:43:34 +03:00
Idan Kamara
b9dc5b5bf7 dispatch: use the request to store the ui object
and check if we got one before creating.

note that the contents of the ui object might change after
dispatch() returns (by options passed through --config for example),
to ensure it doesn't, pass a copy() of it.
2011-05-26 00:53:23 +03:00
Idan Kamara
5544ef8f07 dispatch: wrap dispatch related information in a request class
currently only stores the arguments.
2011-05-26 00:44:11 +03:00
Martin Geisler
58a533fee9 help: add -c/--command flag to only show command help (issue2799) 2011-05-10 14:42:53 +02:00
Augie Fackler
79ea417a18 dispatch: use safehasattr instead of hasattr 2011-07-25 15:17:47 -05:00
Matt Mackall
e7ac311a48 merge with stable 2011-07-22 17:17:23 -05:00
Matt Mackall
550b5c3614 alias: pass local ui to shell alias
This avoids an additional config read
2011-07-15 18:03:37 -05:00
Matt Mackall
c229c0a5cf aliases: drop cwd manipulation
Already done in _dispatch
2011-07-15 16:06:54 -05:00
Matt Mackall
5ce8f05f45 dispatch: move shell alias handling after early arg handling
--cwd, --repo, and --config obviously should be handled first
2011-07-15 16:06:53 -05:00
Matt Mackall
4773ae257d merge with stable 2011-07-13 16:29:28 -05:00
Matt Mackall
bd16bb0fe4 dispatch: fix checking of rpath in _getlocal
This avoids an extra config read
2011-07-12 16:36:34 -05:00
Alexander Solovyov
325788efb7 add positional arguments to non-shell aliases 2011-05-01 12:29:32 +02:00
Dan Villiom Podlaski Christiansen
1eaa37ca32 dispatch: handle IndexErrors 2011-05-01 11:01:57 +02:00
Idan Kamara
762d333ae9 eliminate various naked except clauses 2011-04-23 00:51:25 +03:00
Matt Mackall
a33ce77f33 dispatch: improve repository not found message
This should help clarify what the problem is in various problematic
cases like ssh.
2011-04-20 14:28:40 -05:00
Adrian Buehlmann
3efb31d590 help: do not show full help text for command on option errors
Example

  $ hg clone --jump foo bar
  hg clone: option --jump not recognized
  hg clone [OPTION]... SOURCE [DEST]

  make a copy of an existing repository

  options:

   -U --noupdate           the clone will include an empty working copy (only a
                           repository)
   -u --updaterev REV      revision, tag or branch to check out
   -r --rev REV [+]        include the specified changeset
   -b --branch BRANCH [+]  clone only the specified branch
      --pull               use pull protocol to copy metadata
      --uncompressed       use uncompressed transfer (fast over LAN)
   -e --ssh CMD            specify ssh command to use
      --remotecmd CMD      specify hg command to run on the remote side
      --insecure           do not verify server certificate (ignoring
                           web.cacerts config)

  [+] marked option can be specified multiple times

  use "hg help clone" to show the full help text

Motivation for this change

  If the user already has specified the command, he probably already knows
  the command to some extent. Apparently, he has a problem with the options,
  so we show him just the synopsis with the short help and the details about
  the options, with a hint on the last line how to get the full help text.

Why is Mercurial better with this change?

  Experts who just forgot about the details of an option don't get that
  much text thrown at them, while the newbies still get a hint on the last
  line how to get the full help text.
2011-04-17 11:37:11 +02:00
Adrian Buehlmann
a8a418601f introduce new RequirementError (issue2649)
This improves the misleading error message

  $ hg identify
  abort: there is no Mercurial repository here (.hg not found)!

to the more explicit

  $ hg identify
  abort: requirement 'fake' not supported!

for all commands in commands.optionalrepo, which includes the identify
and serve commands in particular.

This is for the case when a new entry in .hg/requires will be defined
in a future Mercurial release.
2011-02-18 20:25:25 +01:00
Wagner Bruna
297638695f dispatch: fix typo in debug message 2011-02-16 21:02:41 -02:00
Roman Sokolov
ba47cd9ff8 dispatch: use flag cmdalias.shell for detecting shell aliases 2011-02-10 15:41:34 +03:00
Roman Sokolov
00ca6be77b dispatch: debug message for missing arguments in shell alias
Shows debug message if alias definition contains substitution variables,
but insufficient number of arguments supplied.
2011-02-11 03:46:28 +03:00
Roman Sokolov
7a0b42e376 dispatch: support for $ escaping in shell-alias definition
Sigils in shell-alias can be escaped by doubling them.
2011-02-11 03:32:40 +03:00
Adrian Buehlmann
9e0069c080 Make sure bundlerepo doesn't leak temp files (issue2491)
Add empty repository.close() and call it in dispatch.

Remove bundlerepository.__del__(), merging it into bundlerepository.close(),
which overrides repository.close().

http://docs.python.org/reference/datamodel.html says:

"It is not guaranteed that __del__() methods are called for objects that
still exist when the interpreter exits."
2011-02-12 10:58:11 +01:00
Yuya Nishihara
da93c3bd0b url: add --insecure option to bypass verification of ssl certificates
If --insecure specified, it behaves in the same way as no web.cacerts
configured.

Also shows hint for --insecure option when _verifycert() failed. But currently
the hint isn't displayed on SSLError, because it needs a certain level of
changes.
2011-01-29 23:23:24 +09:00
Steve Losh
3171599307 alias: fall back to normal error handling for ambigious commands (fixes issue2475) 2010-11-05 15:54:32 -04:00
Matt Mackall
4d7b056fed traceback: point to BugTracker on the wiki 2010-10-25 13:06:37 -05:00
Martin Geisler
b7a041ed06 dispatch: backout 3b699ee0e66d
The parenthesis may need translation too: Laurens Holst pointed out
that Japanese uses full-width parentheses: () (U+FF08 U+FF09).
2010-10-21 11:23:26 +02:00
Martin Geisler
77ce66fb6a check-code: find trailing whitespace 2010-10-20 10:13:04 +02:00
Steve Losh
0224e99d28 alias: fail gracefully when invalid global options are given (issue2442)
This patch modifies the check for shell aliases to prevent crashing when an invalid
global option is given.

When an invalid global option is given the check will simply return and let the
normal error handling for this case happen.
2010-10-17 13:24:37 -04:00
Brodie Rao
95903377bf dispatch: properly handle relative path aliases used with -R (issue2376)
This ensures the repo config is read relative to the repo root during
dispatch.
2010-10-04 15:07:12 -05:00
Brodie Rao
4236676bfc dispatch: remove superfluous try/except when reading local ui config
ui.readconfig() already handles IOError in this case.
2010-10-04 14:26:38 -05:00
Steve Losh
a6ad45cc76 alias: back up and restore commands.norepo before checking for shell aliases 2010-10-08 16:10:00 -04:00
Steve Losh
0ec78824a3 alias: only allow global options before a shell alias, pass later ones through
This patch refactors the dispatch code to change how arguments to shell aliases
are handled.

A separate "pass" to determine whether a command is a shell alias has been
added. The rough steps dispatch now performs when a command is given are these:

* Parse all arguments up to the command name.

* If any arguments such as --repository or --cwd are given (which could change
  the config file used, and therefore the definition of aliases), they are
  taken into account.

* We determine whether the command is a shell alias.

    * If so, execute the alias. The --repo and --cwd arguments are still in effect.
      Any arguments *after* the command name are passed unchanged through to the
      shell command (and interpolated as normal.

    * If the command is *not* a shell alias, the dispatching is effectively "reset"
      and reparsed as normal in its entirety.

The net effect of this patch is to make shell alias commands behave as you
would expect.

Any arguments you give to a shell alias *after* the alias name are passed
through unchanged. This lets you do something like the following:

    [alias]
    filereleased = !$HG log -r 'descendants(adds("$1")) and tagged()' -l1 $2 $3 $4 $5

    $ hg filereleased hgext/bookmarks.py --style compact

Previously the `--style compact` part would fail because Mercurial would
interpret those arguments as arguments to the alias command itself (which
doesn't take any arguments).

Also: running something like `hg -R ~/src/hg-crew filereleased
hgext/bookmarks.py` when `filereleased` is only defined in that repo's config
will now work.

These global arguments can *only* be given to a shell alias *before* the alias
name.  For example, this will *not* work in the above situation:

    $ hg filereleased -R ~/src/hg-crew hgext/bookmarks.py

The reason for this is that you may want to pass arguments like --repository to
the alias (or, more likely, their short versions like -R):

    [alias]
    own = !chown $@ `$HG root`

    $ hg own steve
    $ hg own -R steve
2010-08-24 18:25:33 -04:00
Wagner Bruna
ea2a96f4d4 i18n: unmark untranslatable string 2010-09-13 10:04:41 -03:00
Brodie Rao
9eaf2eb198 alias: on --debug, print expansion when it has invalid arguments 2010-08-27 20:45:18 -04:00
Brodie Rao
edc433c7fd alias: print what command is being shadowed in debug message 2010-08-27 20:45:11 -04:00
Martin Geisler
cb36142754 Merge with stable 2010-08-29 22:55:37 +02:00