Commit Graph

446 Commits

Author SHA1 Message Date
Pierre-Yves David
00b25b244a color: have the 'ui' object carry the '_colormode' directly
Before this changeset, the value was carried by the class to work around
limitation of the extensions initialisation. Now that the initialisation is
cleanly handled in 'dispatch', we can drop this work around.
2017-02-21 18:22:07 +01:00
Pierre-Yves David
7636ff5278 color: move 'write-err' logic to the core ui class
This is similar to what we needed for 'write', we move the logic from the
extension to the core class. Beside the dispatch to 'win32print', we just apply
label to the argument.
2017-02-20 12:42:23 +01:00
Pierre-Yves David
9c19f50b1e ui: extract low level part of 'write_err' in its own method
Same as for 'write' and '_write' we needs it available for some of the color logic.
2017-02-24 19:53:41 +01:00
Pierre-Yves David
43c85b5d5f ui: extract buffer write from protect and timed 'write_err' output
That subcall to 'self.write' is never doing actual write but only store things
in buffers. So we do not need to protect it for exception not to time its
execution.

This will make it easier to extract a '_write_err' function as we did for
'write'.
2017-02-24 19:28:45 +01:00
Pierre-Yves David
26de620d6b color: move 'write' logic to the core ui class
One more step, the support for writing color is not directly in core. No
behavior change for the default case ('_colormode' = None).

Here are the details of what we have to change to the core method:

 * apply to 'self.label' to input in the buffered case
 * dispatch to 'win32print' when applicable
 * apply to 'self.label' to input when applicable
2017-02-20 12:31:39 +01:00
Pierre-Yves David
50b96ef7b4 ui: extract the low level part of 'write' in a dedicated function
We are about to add some extra logic related to color. That logic will need to
access the low level layer of ui doing the actual write to a stream. (eg:
'win32print'). We extract this logic into a private method for this purpose.
2017-02-24 19:27:00 +01:00
Pierre-Yves David
30677aa45c color: move the 'colorlabel' call to the core 'ui' class
This bring us closer to supporting color in core natively. Core already have a
'label' method that was a no-op. We update its to call the new 'colorlabel'
function. Behavior is unchanged when colormode = None.
2017-02-23 19:45:32 +01:00
Pierre-Yves David
3a2218f308 color: move '_colormode' to the core 'ui' class
Having all 'ui' objects aware of 'color' allows us to update the core code to
handle color. The mode will stay 'None' in the default case so that will not
introduce any changes.
2017-02-20 12:12:08 +01:00
Yuya Nishihara
339f9e280d pager: do not try to run an empty pager command
If pagercmd is explicitly set to '', the pager process would exit silently
and the output would be lost. We'd better disable the pager in such case.
2017-02-23 21:27:25 +09:00
Augie Fackler
127b928398 pager: add a config knob to just globally turn off the pager 2017-02-07 17:13:25 -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
5edbfee26e ui: construct _keepalnum list in a python3-friendly way
It'll be more expensive, but it preserves the behavior.
2017-02-16 11:34:50 -05:00
Augie Fackler
8940b7210f ui: add a debug print right before we start the pager
This makes it easier to figure out why a command is getting paginated.
2017-02-06 23:55:54 -05:00
Augie Fackler
998a3e5c3c ui: respect historic pager.attend-$COMMAND=no
I'm on the fence about this behavior, but the user's intent was pretty
specific and it's not expensive to support this case.
2017-02-06 23:42:04 -05:00
Augie Fackler
59b1009800 ui: add ignore-single-command functionality
This closes the last feature gap other than the attend list from the
extension. For now, I'm leaving the attend list in the extension,
because I'm unsure it has merit in a world where commands have been
updated to take advantage of the modern API.
2017-02-06 23:21:45 -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
09219ff69c pager: move pager-initiating code into core
No functionality change.

A previous version of this API had a category argument on
ui.pager(). As I migrated the commands in core, I couldn't come up
with good enough consistency in any categorization scheme so I just
scrapped the whole idea. It may be worth revisiting in the future.
2017-02-15 17:47:51 -05:00
Simon Farnsworth
79fa9e45c0 ui: give editor() a tag of its own
We know that calls to ui.editor() always block on the user's configured editor.
Use a blocking tag that ensures that we don't see a huge variety of editor
options in our logging.
2017-02-15 13:38:00 -08:00
Simon Farnsworth
c6a1e68b44 ui: time calls to ui.system
We want to know when we're blocked on ui.system, and why. Allow the user to
supply a tag - otherwise we record on an unspecific tag derived from cmd.
2017-02-15 13:29:12 -08:00
Simon Farnsworth
2172b7713c ui: log time spent blocked on stdio
We use a wrapper around Mercurial at Facebook that logs key statistics (like
elpased time) to our standard performance tooling.

This is less useful than it could be, because we currently can't tell when a
command is slow because we need to fix Mercurial versus when a command is
slow because the user isn't interacting quickly.

Teach Mercurial to log the time it spends blocked, so that our tooling can
pick it up and submit it with the elapsed time - we can then do the math in
our tooling to see if Mercurial is slow, or if the user simply failed to
interact.

Combining this with the command duration log means that we can ensure that
we concentrate performance efforts on the things that bite Facebook users.

The perfwrite microbenchmark shifts from:
Linux:
! wall 3.213560 comb 0.410000 user 0.350000 sys 0.060000 (best of 4)
Mac:
! wall 0.342325 comb 0.180000 user 0.110000 sys 0.070000 (best of 20)

before this change to:
! wall 3.478070 comb 0.500000 user 0.420000 sys 0.080000 (best of 3)
Mac:
! wall 0.218112 comb 0.220000 user 0.150000 sys 0.070000 (best of 15)

showing a small hit in comb time, but firmly in the noise on wall time.
2017-02-15 13:50:06 -08: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
Kyle Lippincott
1cd6a540e2 ui: remove urllib2 from being imported early
Before this change, urllib2 was brought in when constructing the ui object, and
that added ~5ms on my Linux workstation to the hg startup time for every
command, bringing the time for 'HGRCPATH=/dev/null hg root' from 46ms to 40ms.

Now, we construct a single proxy object per initial ui creation (so that if the
ui is copied they share the object), but defer the actual instantiation of it
and the import of urllib2 until it's needed.

# no-check-commit
2017-02-12 03:06:38 -08:00
Jun Wu
4b37e871cd ui: fix configwith doctest
4.2 cannot be expressed with IEEE floating point losslessly, and could
cause test failure on some platform:

    File ".../mercurial/ui.py", line 414, in mercurial.ui.ui.configwith
    Failed example:
        u.configwith(float, s, 'float2')
    Expected:
        -4.2
    Got:
        -4.2000000000000002

This patch fixes that by changing the number to 4.25, which can be expressed
by the binary number 100.01.
2017-02-13 21:00:50 -08:00
Bryan O'Sullivan
173258cfa2 ui: rewrite configint in terms of configwith 2017-02-12 21:44:55 -08:00
Bryan O'Sullivan
0fd65c7a86 ui: add a configwith method
This is a long-overdue generalization of the pattern in configint
and configbool.
2017-02-12 21:40:46 -08:00
Pulkit Goyal
56031921a5 py3: convert the mode argument of os.fdopen to unicodes (2 of 2) 2017-02-13 22:15:28 +05:30
Sean Farley
e145fc2df7 ui: rename tmpdir parameter to more specific repopath
This was requested by Augie and I agree that repopath is more
descriptive.
2017-01-18 18:25:51 -08:00
Sean Farley
9280f19af2 ui: add a parameter to set the temporary directory for edit
Until callsites are updated, this will have no effect. Once callsites
are updated, specifying experimental.editortmpinhg will create editor
temporary files in a subdirectory of .hg, which will make it easier
for tool integrations to determine what repository is in play when
they're asked to edit an hg-related file.
2017-01-16 21:05:22 -08:00
Matt Harbison
5a63dbb230 ui: introduce an experimental dict of exportable environment variables
Care needs to be taken to prevent leaking potentially sensitive environment
variables through hgweb, if template support for environment variables is to be
introduced.  There are a few ideas about the API for preventing accidental
leaking [1].  Option 3 seems best from the POV of not needing to configure
anything in the normal case.  I couldn't figure out how to do that, so guard it
with an experimental option for now.

[1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-January/092383.html
2017-01-17 23:05:12 -05:00
Yuya Nishihara
5d86e43147 ui: check EOF of getpass() response read from command-server channel
readline() returns '' only when EOF is encountered, in which case, Python's
getpass() raises EOFError. We should do the same to abort the session as
"response expected."

This bug was reported to
https://bitbucket.org/tortoisehg/thg/issues/4659/
2017-01-14 20:31:35 +09:00
Pulkit Goyal
8edc9540ee py3: replace sys.platform with pycompat.sysplatform (part 1 of 2)
sys.platform returns unicode on python 3 world. Our code base has most of the
things bytes because of the transformer. So we have a bytes version of this as
pycompat.sysplatform. This series of 2 patches replaces occurences of
sys.platform with pycompat.sysplatform.
2016-12-19 02:15:24 +05:30
Pulkit Goyal
24a9271007 py3: replace os.environ with encoding.environ (part 4 of 5) 2016-12-18 02:06:00 +05:30
Yuya Nishihara
26dd8d740c ui: do not translate empty configsource() to 'none' (API)
It should be processed when displaying data, so we can get "source": "" in
JSON output.
2016-10-23 17:47:00 +09:00
Pulkit Goyal
4245797c62 py3: avoid use of basestring
"In this case, result is a source variable of a list to be returned, it
shouldn't be unicode. Hence we can use bytes instead of basestring here." -Yuya
2016-11-30 23:51:11 +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
Gregory Szorc
9f87ab8fca ui: use try..finally in configoverride
@contextmanager almost always have their "yield" inside a try..finally
block. This is because if the calling code inside the activated
context manager raises, the code after the "yield" won't get
executed. A "finally" block, however, will get executed in this
scenario.
2016-11-26 09:14:41 -08: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
Kostia Balytskyi
652e43055e ui: add configoverride context manager
I feel like this idea might've been discussed before, so please
feel free to point me to the right mailing list entry to read
about why it should not be done.

We have a common pattern of the following code:
    backup = ui.backupconfig(section, name)
    try:
        ui.setconfig(section, name, temporaryvalue, source)
        do_something()
    finally:
        ui.restoreconfig(backup)

IMO, this looks better:
    with ui.configoverride({(section, name): temporaryvalue}, source):
        do_something()

Especially this becomes more convenient when one has to backup multiple
config values before doing something. In such case, adding a new value
to backup requires codemod in three places.
2016-11-21 16:22:26 -08: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
Augie Fackler
d40f484280 ui: explicitly open config files in binary mode
This has been working mostly accidentally, but now it works explicitly.
2016-10-09 09:17:49 -04:00
Mads Kiilerich
38cb771268 spelling: fixes of non-dictionary words 2016-10-17 23:16:55 +02:00
Yuya Nishihara
d1b623a5c1 scmutil: extend termwidth() to return terminal height, renamed to termsize()
It appears crecord.py has its own termsize() function. I want to get rid of it.

The fallback height is chosen from the default of cmd.exe on Windows, and
VT100 on Unix.
2016-10-20 23:09:05 +09:00
Yuya Nishihara
5b9ee7c321 scmutil: make termwidth() obtain stdio from ui
I'm getting rid of direct sys.stderr|out|in references so Py3 porting will
be slightly easier.
2016-10-20 21:42:11 +09:00
Yuya Nishihara
52e59de51c scmutil: move util.termwidth()
I'm going to get rid of sys.stderr|out|in references from posix.termwidth().
In order to do that, termwidth() needs to take a ui, but functions in util.py
shouldn't depend on a ui object. So moves termwidth() to scmutil.py.
2016-10-20 21:38:44 +09:00
Pulkit Goyal
a1ce407d6d py3: use encoding.environ in ui.py
Using source transformer we add b'' everywhere. So there are no chances
that those bytes string will work with os.environ on Py3 as that returns a
dict of unicodes. We are relying on the errors, even though no error is raised
even in future, these pieces of codes will tend to do wrong things.
if statements can result in wrong boolean and certain errors can be raised
while using this piece of code. Let's not wait for them to happen, fix what is
wrong. If this patch goes in, I will try to do it for all the cases.
Leaving it as it is buggy.
2016-11-03 03:12:57 +05:30
timeless
94b5113786 samplehgrcs: use single quotes in use warning 2016-09-20 23:49:00 +00:00
Jun Wu
5e8afd381a ui: drop values returned by inspect.*frame*() to avoid cycles
"f = inspect.currentframe()" instantly creates a cycle because
"f.f_locals['f']" is "f" itself.

This patch explicitly sets those frame objects to None to avoid cycles.
2016-08-10 15:05:20 +01:00
Gregory Szorc
9c6bc630a3 ui: path option to declare which revisions to push by default
Now that we have a mechanism for declaring path sub-options, we can
start to pile on features!

Many power users have expressed frustration that bare `hg push`
attempts to push all local revisions to the remote. This patch
introduces the "pushrev" path sub-option to control which revisions
are pushed when no "-r" argument is specified.

The value of this sub-option is a revset, naturally.

A future feature addition could potentially introduce a "pushnames"
sub-options that declares the list of names (branches, bookmarks,
topics, etc) to push by default. The entire "what to push by default"
feature should probably be considered before this patch lands.
2016-06-26 07:59:02 -07:00
Gregory Szorc
bbde62ff9f ui: don't fixup [paths] sub-options
As part of developing a subsequent patch I discovered that sub-option
values like "." were getting converted to paths. This is because the
[paths] section is treated specially during config loading.

This patch prevents post-processing sub-options from the [paths]
section.
2016-06-25 18:35:14 -07:00
liscju
ade9d0fabe url: remember http password database in ui object
This makes http password database stored in ui object.
It allows reusing authentication information when we
use this database for creating password manager for
the new connection.
2016-06-09 11:41:36 +02:00