Commit Graph

339 Commits

Author SHA1 Message Date
Augie Fackler
7a3b5c3c7d dispatch: use pycompat.maplist to allow summing with args 2017-03-19 14:17:07 -04:00
Augie Fackler
f1710548b8 dispatch: replace mayberepr with shellquote
The quoting logic here was actually insufficient, and would have had
bogus b-prefixes on Python 3. shellquote seems more appropriate
anyway. Surprisingly, only two tests have output changes, and both of
them look reasonable to me (both are in blackbox logs).

Spotted by Yuya during review.
2017-03-19 14:23:30 -04:00
Augie Fackler
4eeee9b0e9 dispatch: ensure repr is bytes in _mayberepr
Fixes command line arguments containing spaces on Python 3.
2017-03-19 00:22:04 -04:00
Augie Fackler
ecf3381175 dispatch: extract maybe-use-repr formatting to helper function
I think this makes the code much clearer. I had to think for a bit to
unpack the old-school `condition and if-true or if-false` dance, and
formatting argument lists here shouldn't be performance critical.
2017-03-19 00:21:26 -04:00
Augie Fackler
956c1da8ce dispatch: consolidate formatting of arguments
This was getting done twice, and it's clever enough I'm about to split
it apart and then fix it for Python 3.
2017-03-19 00:18:53 -04:00
Pulkit Goyal
03903626e4 py3: make the regular expression bytes to prevent TypeError 2017-03-17 05:10:58 +05:30
Augie Fackler
5759889c58 dispatch: enforce bytes when converting boolean flags to config items
This fixes --verbose on Python 3.
2017-03-03 14:43:27 -05:00
Augie Fackler
7405058a22 dispatch: add pagination of two more help cases
I missed these in the last round anf Yuya spotted them in
review. Thanks!
2017-03-08 18:32:42 -05:00
Simon Farnsworth
36d4b32d0f dispatch: set a blockedtag when running an external alias 2017-03-06 03:25:44 -08:00
Augie Fackler
601a6ec266 dispatch: cope with sys.version being unicode on Python 3 2017-03-03 13:29:50 -05:00
Augie Fackler
5bdccc39a5 dispatch: allow testedwith to be bytes or str 2017-03-03 13:29:25 -05:00
Pierre-Yves David
b29eb57306 color: add a 'ui.color' option to control color behavior
This new option control whether or not color will be used. It mirror the behavior
of '--color'. I usually avoid adding new option to '[ui]' as the section is
already filled with many option. However, I feel like 'color' is central enough
to deserves a spot in this '[ui]' section.

For now the option is not documented so it is still marked as experimental. Once
it get documented and official, we should be able to deprecate the color
extensions.

There is more cleanup to do before that documentation is written, but we need
this option early to made them. Having that option will allow for more cleanup
of the initialisation process and proper separation between color
configuration.
2017-02-25 19:44:23 +01:00
Pierre-Yves David
89576090e1 color: move triggering of the initialisation logic in core
We now run the color initialisation as part of the standard dispatch. This is
opening the way for multiple cleanups since we now have access to the multiple 'ui'
object and we'll be able to see difference between global and local config. This
cleanup will arrive in later changesets.

As a side effect, the '--color' flag is now working without the extension.

Since we now properly initialize color for each ui idependently, we get a
warning message twice.
2017-02-21 18:20:12 +01:00
Augie Fackler
b88e5ebe27 dispatch: rearrange 'unknown command' code to better employ pager
dispatch calls help like a ninja if you give it a truly unknown
command, and that might want to be paged. If it gets paged, then the
'hg: unknown command' text gets eaten by a grue, unless we call the
pager first. This change rearranges the codepaths so we can safely
only invoke the pager in the case where we'll have long output from
the help command code, rather than just a short message like "did you
mean stat instead of start" or "fetch is provided by the fetch
extension".
2017-02-21 14:20:05 -05:00
Augie Fackler
4357a98af3 dispatch: consolidate pager flag handling to a single place
This makes a little more sense, thanks to Martin for suggesting it.
2017-02-19 20:16:11 -05:00
Augie Fackler
7dca05b0fd ui: rename neverpager to disablepager
I agree this is a clearer name for this method.
2017-02-19 20:12:52 -05:00
Augie Fackler
af842b14a1 ui: introduce neverpager() call
I'm about to add direct paging support to some commands, and as a
result we need a way to communicate from the higher layers of dispatch
that paging is explicitly disabled.
2017-02-15 17:48:03 -05:00
Augie Fackler
3967c4ed9b pager: move more behavior into core
This moves the global flag and the --pager=yes logic into core. Only
functionality change is that users now always get a --pager flag and
can enable the pager via the flag without the extension active.

Moving the flag into core exposes a defect in the ro localization,
which will have to be corrected later.
2017-02-15 17:47:57 -05:00
Simon Farnsworth
bd8f9eccad ui: provide a mechanism to track and log blocked time
We want to log the time Mercurial spends trapped in things outside
programmatic control. Provide a mechanism to give us both command runtime
and as many different sources of blocking as we deem useful.
2017-02-15 13:17:45 -08:00
Simon Farnsworth
e0b70e4f7f mercurial: switch to util.timer for all interval timings
util.timer is now the best available interval timer, at the expense of not
having a known epoch. Let's use it whenever the epoch is irrelevant.
2017-02-15 13:17:39 -08:00
Bryan O'Sullivan
486015e16e dispatch: start profiling earlier
This makes it possible to profile extension loading and setup, which
takes a substantial fraction of overall execution time for fast
commands.

(99% of this commit is simply changes of indentation to reflect the
hoisting of the two calls to maybeprofile to a single one that
happens earlier.)

# no-check-commit
2017-02-13 20:47:41 -08:00
Bryan O'Sullivan
817be1196c dispatch: move detection of profiling earlier during startup 2017-02-13 20:44:20 -08:00
Pierre-Yves David
2d361a4933 dispatch: load debugcommand before extension
Multiple extension will manipulate commands on load, we need the debug command
to be loaded before that point.
2017-02-13 16:35:49 +01:00
Pulkit Goyal
d310fba3dd py3: have a bytes version of shlex.split()
shlex.split() only accepts unicodes on Python 3. After this patch we will be
using pycompat.shlexsplit(). This patch also replaces existing occurences of
shlex.split with pycompat.shlexsplit.
2016-12-25 03:06:55 +05:30
Pierre-Yves David
9ff835aa99 color: load 'colortable' from extension using an 'extraloader'
Now that we have the '_style' dictionary in core, we can use the clean and
standard 'extraloader' mechanism to load extension's 'colortable'.
color.loadcolortable
2016-11-18 18:18:15 +01:00
Pulkit Goyal
9d833da676 py3: make keys of keyword arguments strings
keys of keyword arguments on Python 3 has to be string. We are dealing with
bytes in our codebase so the keys are also bytes. Done that using
pycompat.strkwargs().

Also after this patch, `hg version` now runs on Python 3.5. Hurray!
2016-12-13 20:53:40 +05:30
Pulkit Goyal
9523fa9b6b fancyopts: switch from fancyopts.getopt.* to getopt.*
In the next patch, we will be creating a bytes version of getopt.getopt() and
doing that will leave getopt as unused import in fancyopts. So before removing
that there are instances in codebase where instead of importing getopt, we
have used fancyopts.getopt. This patch will switch all those cases so that
the next patch can remove the import of getopt from fancyopts without breaking
things.
2016-12-06 06:27:58 +05:30
Yuya Nishihara
1d44bd2bbb ui: factor out ui.load() to create a ui without loading configs (API)
This allows us to write doctests depending on a ui object, but not on global
configs.

ui.load() is a class method so we can do wsgiui.load(). All ui() calls but
for doctests are replaced with ui.load(). Some of them could be changed to
not load configs later.
2016-10-22 14:35:10 +09:00
Jun Wu
115ee04855 dispatch: move part of callcatch to scmutil
Per discussion at 7d927e65eaf2 [1], we need "callcatch" in worker.py. Move
it to scmutil.py to avoid cycles.

Note that dispatch's callcatch handles some additional high-level exceptions
related to config parsing, and commands. Moving them to scmutil will make
scmutil depend on "commands" or require "_formatparse" and "_getsimilar"
(and "difflib") to be moved as well. In the worker use-case, it is forked
when config and commands are fully loaded. So it should not care about those
exceptions.

[1]: https://www.mercurial-scm.org/pipermail/mercurial-devel/2016-August/087116.html
2016-11-24 00:48:40 +00:00
Pulkit Goyal
97f340e354 py3: use pycompat.getcwd() instead of os.getcwd()
We have pycompat.getcwd() which returns bytes path on Python 3. This patch
changes most of the occurences of the os.getcwd() with pycompat one.
2016-11-23 00:03:11 +05:30
Pulkit Goyal
57f271b08e py3: add os.getcwdb() to have bytes path
Following the behaviour of Python 3, os.getcwd() return unicodes. We need
bytes version as path variables are bytes in UNIX. Python 3 has os.getcwdb()
which returns current working directory in bytes.

Like rest of the things there in pycompat, like osname, ossep, we need to
rewrite every instance of os.getcwd to pycompat.getcwd to make them work
correctly on Python 3.
2016-11-22 18:46:50 +05:30
Augie Fackler
d3b8e6d277 dispatch: stop supporting non-use of @command
We said we'd delete this after 3.8. It's time.
2016-11-21 21:51:23 -05:00
Yuya Nishihara
47f9c8b52e py3: bulk replace sys.stdin/out/err by util's
Almost all sys.stdin/out/err in hgext/ and mercurial/ are replaced by util's.
There are a few exceptions:

 - lsprof.py and statprof.py are untouched since they are a kind of vendor
   code and they never import mercurial modules right now.
 - ui._readline() needs to replace sys.stdin and stdout to pass them to
   raw_input(). We'll need another workaround here.
2016-10-20 23:53:36 +09:00
Pulkit Goyal
bf942f7498 py3: use pycompat.sysargv in dispatch.run()
Another one to have a bytes result from sys.argv in Python 3.
This one is also a part of running `hg version` on Python 3.
2016-11-21 15:35:22 +05:30
Gregory Szorc
f70b24b885 debugcommands: introduce standalone module for debug commands
commands.py is our largest .py file by nearly 2x. Debug commands live
in a world of their own. So let's extract them to their own module.

We start with "debugancestor."

We currently reuse the commands table with commands.py and have a hack
in dispatch.py for loading debugcommands.py. In the future, we could
potentially use a separate commands table and avoid the import of
debugcommands.py.
2016-08-17 21:07:38 -07:00
Arun Kulshreshtha
29d0603a2c dispatch: make hg --profile wrap reposetup
Move profiling.maybeprofile() from _runcommand to _dispatch() so that
profiler output will include reposetup.
2016-09-22 12:36:30 -07:00
Arun Kulshreshtha
19e2dbbbbc dispatch: change indentation level in _dispatch()
Add an if True: placeholder for a profiling context manager that
will be added in the next commit, for the purpose of reducing size
of the diff due to trivial indentation changes.

This change should be a no-op.
2016-09-22 12:19:48 -07:00
Yuya Nishihara
228026b4ee extensions: use ismoduleinternal() thoroughly
"ships-with-hg-core" would be long enough to typo.
2016-08-27 00:00:28 +09:00
Augie Fackler
82bc5f196f blackbox: also log alias expansions
This should be extremely useful for helping users debug without having
to see their complete configuration.

Shell aliases do not get their expansion logged, because we don't look
and see if we're in a repo before we dive into the execution of a
shell alias. As a result, the ui object doesn't know where to log.
2016-08-23 16:40:08 -04:00
Augie Fackler
4e1c384d0a extensions: change magic "shipped with hg" string
I've caught multiple extensions in the wild lying about being
'internal', so it's time to move the goalposts on people. Goalpost
moving will continue until third party extensions stop trying to
defeat the system.
2016-08-23 11:26:08 -04:00
Augie Fackler
afb1d21a9d dispatch: explicitly pass fancyopts optional arg as a keyword
I've been baffled by this a couple of times (mainly wondering if any
callers of fancyopts.fancyopts that don't use gnu=True exist), so
let's just specify this as a keyword argument to preserve sanity.
2016-08-18 11:32:02 -04:00
Gregory Szorc
9ac5776ef7 profiling: add a context manager that no-ops if profiling isn't enabled
And refactor dispatch.py to use it. As you can see, the resulting code
is much simpler.

I was tempted to inline _runcommand as part of writing this series.
However, a number of extensions wrap _runcommand. So keeping it around
is necessary (extensions can't easily wrap runcommand because it calls
hooks before and after command execution).
2016-08-14 17:51:12 -07:00
Gregory Szorc
fbd4d1a639 profiling: make profiling functions context managers (API)
This makes profiling more flexible since we can now call multiple
functions when a profiler is active. But the real reason for this
is to enable a future consumer to profile a function that returns
a generator. We can't do this from the profiling function itself
because functions can either be generators or have return values:
they can't be both. So therefore it isn't possible to have a generic
profiling function that can both consume and re-emit a generator
and return a value.
2016-08-14 18:25:22 -07:00
Gregory Szorc
1aca3f1e38 dispatch: set profiling.enabled when profiling is enabled
We do this for other global command arguments. We don't for --profile
for reasons that are unknown to me. Probably because nobody has needed
it.

An upcoming patch will introduce a new consumer of the profiling
code. It doesn't have access to command line arguments. So let's
set the config option during argument processing.

We also remove a check for "options['profile']" because it is now
redundant.
2016-08-14 16:35:58 -07:00
Gregory Szorc
bdb3786ca0 profiling: move profiling code from dispatch.py (API)
Currently, profiling code lives in dispatch.py, which is a low-level
module centered around command dispatch. Furthermore, dispatch.py
imports a lot of other modules, meaning that importing dispatch.py
to get at profiling functionality would often result in a module import
cycle.

Profiling is a generic activity. It shouldn't be limited to command
dispatch. This patch moves profiling code from dispatch.py to the
new profiling.py. The low-level "run a profiler against a function"
functions have been moved verbatim. The code for determining how to
invoke the profiler has been extracted to its own function.

I decided to create a new module rather than stick this code
elsewhere (such as util.py) because util.py is already quite large.
And, I foresee this file growing larger once Facebook's profiling
enhancements get added to it.
2016-08-14 16:30:44 -07:00
Jun Wu
5eaa546711 dispatch: split global error handling out so it can be reused
We may want a similar error handling at worker.py. This patch extracts the
error handling logic to "callcatch" so it can be reused.
2016-08-09 16:45:28 +01:00
Jun Wu
ad658fc71c dispatch: always load extensions before running shell aliases (issue5230)
Before this patch, we may or may not load extensions for shell aliases
depending on whether the command is abbreviated or not.

Loading extensions may have useful side effects to shell aliases. For example,
the pager extension does not work for shell aliases.

This patch removes the code checking shell aliases before loading extensions
to give the user a more consistent experience. It may hurt performance for
shell aliases a bit without chg but the correctness seems worth it. It will
also make the behavior consistent with chg since chg will always load all
extensions before running commands.
2016-05-07 14:12:23 +01:00
Jordi Gutiérrez Hermoso
dc2068ce42 dispatch: add fail-* family of hooks
The post-* family of hooks will not run in case a command fails (i.e.
raises an exception). This makes it inconvenient to hook into events
such as doing something in case of a failed push.

We catch all exceptions to run the failure hook. I am not sure if this
is too aggressive, but tests apparently pass.
2016-04-28 10:37:47 -04:00
Gregory Szorc
d5340c808d dispatch: stop setting web.cacerts=! to indicate --insecure
Consumers needing to know if --insecure was used have already
transitioned to using ui.insecureconnections. The previous
patch removed the last meaningful consumer looking for
web.cacerts=!.
2016-05-05 00:40:01 -07:00
Gregory Szorc
afd3cdf559 dispatch: set ui.insecureconnections when --insecure is used 2016-05-05 00:34:22 -07:00