Commit Graph

466 Commits

Author SHA1 Message Date
Yuya Nishihara
7701e518b5 pager: flush outputs before firing pager process
So that buffered outputs are always sent to the console.
2017-02-25 17:29:30 +09:00
Jun Wu
3d8879dca9 ui: move configlist parser to config.py
The list parser is complex and reusable without ui. Let's move it to
config.py.

This allows us to parse a list from a "pure" config object without going
through ui. Like, we can make "_trustusers" calculated from raw configs,
instead of making sure it's synchronized by calling "fixconfig"s.
2017-03-17 09:19:56 -07:00
Augie Fackler
3839a3e429 pager: skip running the pager if it's set to 'cat'
Avoid useless uses of cat.
2017-03-15 20:34:26 -04:00
Augie Fackler
dd0af0f250 pager: avoid shell=True on subprocess.Popen for better errors (issue5491)
man(1) behaves as poorly as Mercurial without this change. This cribs
from git's run-command[0], which has a list of characters that imply a
string that needs to be run using 'sh -c'. If none of those characters
are present in the command string, we can use shell=False mode on
subprocess and get significantly better error messages (see the test)
when the pager process is invalid. With a complicated pager command
(that contains one of the unsafe characters), we behave as we do today
(which is no worse than git manages.)

I briefly tried tapdancing in a thread to catch early pager exits, but
it's just too perilous: you get races between fd duping operations and
a bad pager exiting, and it's too hard to differentiate between a
slow-bad-pager result and a fast-human-quit-pager-early result.

I've observed some weird variation in exit code handling in the "bad
experience" case in test-pager.t: on my Mac hg predictably exits
nonzero, but on Linux hg always exits zero in that case. For now,
we'll work around it with || true. :(

0: cddbda4bc8/run-command.c (L201)
2017-03-15 20:33:47 -04:00
Martijn Pieters
0344aed188 config: honour the trusted flag in ui.configbytes 2017-03-12 11:43:31 -07:00
Augie Fackler
5e07b24e52 ui: portably bytestring-ify url object 2017-03-12 01:59:23 -05:00
Augie Fackler
6ba88e41e4 ui: check for --debugger in sys.argv using r-string to avoid bytes on py3
Our source loader was errantly turning this --debugger into a bytes,
which was then causing me to still get a pager when I was using the
debugger on py3. That made life hard.
2017-03-11 20:51:09 -05:00
Yuya Nishihara
7c6e9b463e py3: factor out bytechr() function
I also changed xrange(127) to range(127) as the number is relatively small.
2017-03-08 22:30:12 +09:00
Augie Fackler
80c3da0d7d ui: fix ui.traceback on Python 3 2017-03-03 14:09:14 -05:00
Augie Fackler
85e23a6604 ui: fix opts labeling on ui.warn et al for Python 3
This is a step towards fixing extension load warnings on Python
3. Note that I suspect there are still some bugs in this area and that
things like color won't work, but the code at least executes and
prints text to the console correctly now.
2017-03-03 14:08:24 -05:00
Augie Fackler
e1ac204a83 ui: fix configlist on Python 3
Since we're working on bytestrings, we have to use [offset:offset+1]
to get consistent behavior on Python 2 and 3. I've only tested the
_parse_plain closure, not the _parse_quote one, but I have no real
reason to expect the latter to be broken since the fixes were fairly
mechanical.
2017-03-03 14:10:06 -05:00
Yuya Nishihara
794cd16369 ui: remove superfluous indent in _write() 2017-02-25 14:09:55 +09:00
Pierre-Yves David
6062a0018f config: suggest the 'ui.color' instead of the 'color' extension
The extensions is deprecated now so we should offer the core way to handle color
instead.
2017-02-21 22:17:33 +01:00
Martin von Zweigbergk
ef59d7b1fd merge with stable 2017-02-28 11:13:25 -08:00
Rishabh Madan
d0ac5a9dcb ui: replace obsolete default-push with default:pushurl (issue5485)
Default-push has been deprecated in favour of default:pushurl. But "hg clone" still
inserts this in every hgrc file it creates. This patch updates the message by replacing
default-push with default:pushurl and also makes the necessary changes to test files.
2017-02-25 16:57:21 +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
Pierre-Yves David
23a62914d0 color: move 'styles' definition on the 'ui' object
Same logic as for '_terminfoparams'. The content depends on the config so it
should be specific to each 'ui instance.
2016-11-06 20:16:01 +01:00
Pierre-Yves David
da62a3693e color: pass 'ui' to 'win32print'
Same logic as before,'win32print' relies on some data we will move on the 'ui'
object soon, we update the API beforehand for clarity.
2016-11-06 20:10:53 +01:00
Pierre-Yves David
ae9d790b11 color: move the dict with terminfo parameters on the ui object
This dictionnary is affected by the content of the config, so we should have
one for each ui config.

We rename the global dict to '_baseterminfoparams' to make the situation
clearer.
2017-02-25 15:00:51 +01:00
Yuya Nishihara
8072a1daee chg: deduplicate error handling of ui.system()
This moves 'onerr' handling from low-level util.system() to higher level,
which seems better API separation.
2017-02-19 01:16:45 +09:00
Yuya Nishihara
9a31b02cc4 chg: refactor ui.system() to be partly overridden
Since a33895509ccb changed the signature of ui.system(), chgui.system()
should have been updated. This patch factors out the util.system() call
so that chg can override how a shell command is executed.
2017-02-19 01:00:10 +09:00
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