Commit Graph

496 Commits

Author SHA1 Message Date
Boris Feld
04a3cbe923 ui: add the possiblity to get a date config field
Add the method configdate to read a date from configuration. It uses the
util.rawparsedate refactored earlier to support all standard date formats.
2017-05-19 12:07:41 +02:00
Pierre-Yves David
a5a7702af1 pager: drop the support for 'pager.enable=<bool>'
This option was never released except for a release candidate. Dropping
compatibility with this option will free the 'pager.enable' config option for
other usage in the future.
2017-05-02 17:18:13 +02:00
Pierre-Yves David
bf9fa9e05b pager: rename 'pager.enable' to 'ui.paginate'
This aligns with what we do for color (see cea7a760c58d). Pager is a central
enough notion that having the master config in the [ui] section makes senses. It
will helps with consistency, discoverability. It will also help having a simple
and clear example hgrc mentioning pager.

The previous form of the option had never been released in a non-rc version but
we keep it around for convenience. If both are set, 'ui.pager' take priority.
2017-05-01 16:36:50 +02:00
Pierre-Yves David
50e449e083 pager: advertise the config option in the default hgrc
Same as for 'ui.color', this is a critical part of the UI and we want user to
find this config knob easily.
2017-05-01 18:07:23 +02:00
Pierre-Yves David
0600a78b19 config: drop pager from the recommended extension
The extension is deprecated, we should having exposing it to users.
2017-05-01 15:51:57 +02:00
Pierre-Yves David
c674366f10 config: use "churn" as an example extension
"Churn" is not the useful example we have, but this is the one used in
'hg help config.extensions'. As we need something to replace the deprecated
'pager' extension in the example config, we are adding 'churn'.
2017-05-01 15:51:47 +02:00
Pierre-Yves David
39d62892b4 color: point to the global help in the example hgrc
This is probably the best way to have users learn more is they need too.
2017-05-01 15:40:41 +02:00
Pierre-Yves David
d8acfa70c4 color: reflect the new default in the example hgrc
Color is enabled by default so un-commenting the line would not have any effect.
We'll point to the help in the next changeset.
2017-05-01 15:39:50 +02:00
Yuya Nishihara
c11e91f8ff pager: use less as a fallback on Unix
This seems reasonable choice per discussion, and the default-default of Git.
See also the inline-comment for why.

https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-April/097042.html
2017-04-28 20:51:14 +09:00
Bryan O'Sullivan
60b68c00eb stdio: raise StdioError if something goes wrong in ui.flush
The prior code used to ignore all errors, which was intended to
deal with a decade-old problem with writing to broken pipes on
Windows.

However, that code inadvertantly went a lot further, making it
impossible to detect *all* I/O errors on stdio ... but only sometimes.

What actually happened was that if Mercurial wrote less than a stdio
buffer's worth of output (the overwhelmingly common case for most
commands), any error that occurred would get swallowed here.  But
if the buffering strategy changed, an unhandled IOError could be
raised from any number of other locations.

Because we now have a top-level StdioError handler, and ui._write
and ui._write_err (and now flush!) will raise that exception, we
have one rational place to detect and handle these errors.
2017-04-11 14:54:12 -07:00
Bryan O'Sullivan
dd48bd8237 stdio: raise StdioError if something goes wrong in ui._write_err
The prior code used to ignore certain classes of error, which was
not the right thing to do.
2017-04-11 14:54:12 -07:00
Bryan O'Sullivan
7b0fee3bf9 stdio: raise StdioError if something goes wrong in ui._write 2017-04-11 14:54:12 -07:00
Bryan O'Sullivan
287bd28acf atexit: switch to home-grown implementation 2017-04-11 14:54:12 -07:00
Bryan O'Sullivan
0c663fe04d ui: add special-purpose atexit functionality
In spite of its longstanding use, Python's built-in atexit code is
not suitable for Mercurial's purposes, for several reasons:

* Handlers run after application code has finished.

* Because of this, the code that runs handlers swallows exceptions
  (since there's no possible stacktrace to associate errors with).
  If we're lucky, we'll get something spat out to stderr (if stderr
  still works), which of course isn't any use in a big deployment
  where it's important that exceptions get logged and aggregated.

* Mercurial's current atexit handlers make unfortunate assumptions
  about process state (specifically stdio) that, coupled with the
  above problems, make it impossible to deal with certain categories
  of error (try "hg status > /dev/full" on a Linux box).

* In Python 3, the atexit implementation is completely hidden, so
  we can't hijack the platform's atexit code to run handlers at a
  time of our choosing.

As a result, here's a perfectly cromulent atexit-like implementation
over which we have control.  This lets us decide exactly when the
handlers run (after each request has completed), and control what
the process state is when that occurs (and afterwards).
2017-04-11 14:54:12 -07:00
Jun Wu
dcf42da6e9 pager: set some environment variables if they're not set
Git did this already [1] [2]. We want this behavior too [3].

This provides a better default user experience (like, supporting colors) if
users have things like "PAGER=less" set, which is not uncommon.

The environment variables are provided by a method so extensions can
override them on demand.

[1]: 6a5ff7acb5/pager.c (L87)
[2]: 6a5ff7acb5/Makefile (L1545)
[3]: https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-March/094780.html
2017-04-13 08:27:19 -07:00
Yuya Nishihara
33d687d3d1 ui: use bytes IO and convert EOL manually in ui.editor()
Text IO sucks on Python 3 as it must be a unicode stream. We could introduce
a wrapper that converts unicode back to bytes, but it wouldn't be simple to
handle offsets transparently from/to underlying IOBase API.

Fortunately, we don't need to process huge text files, so let's stick to
bytes IO and convert EOL in memory.
2017-03-29 21:43:38 +09:00
Yuya Nishihara
2f682a6206 pycompat: provide bytes os.linesep 2017-03-29 21:23:28 +09:00
Matt Harbison
ac12c54058 ui: rerun color.setup() once the pager has spawned to honor 'color.pagermode'
Otherwise, ui.pageractive is False when color is setup in dispatch.py (without
--pager=on), and this config option is ignored.
2017-03-25 19:17:11 -04:00
Matt Harbison
ca66dceee3 ui: defer setting pager related properties until the pager has spawned
When --pager=on is given, dispatch.py spawns a pager before setting up color.
If the pager failed to launch, ui.pageractive was left set to True, so color
configured itself based on 'color.pagermode'.  A typical MSYS setting would be
'color.mode=auto, color.pagermode=ansi'.  In the failure case, this would print
a warning, disable the pager, and then print the raw ANSI codes to the terminal.

Care needs to be taken, because it appears that leaving ui.pageractive=True was
the only thing that prevented an attempt at running the pager again from inside
the command.  This results in a double warning message, so pager is simply
disabled on failure.

The ui config settings didn't need to be moved to fix this, but it seemed like
the right thing to do for consistency.
2017-03-25 21:12:00 -04:00
Jun Wu
94b5d9fcfa pager: do not read from environment variable
$PAGER is converted to the pager.pager config item. So it's no longer
necessary to read $PAGER in ui.pager().
2017-03-26 21:43:47 -07:00
Jun Wu
371e8cfb4e ui: simplify geteditor
Now $EDITOR and $VISUAL will affect ui.editor directly. So it's no longer
necessary to test them in ui.geteditor.
2017-03-26 21:41:42 -07:00
Jun Wu
cc0447168c rcutil: let environ override system configs (BC)
This is BC because system configs won't be able to override $EDITOR, $PAGER.
The new behavior is arguably more rational.
2017-03-26 21:33:37 -07:00
Jun Wu
d4692f9619 rcutil: let rccomponents return different types of configs (API)
The next patches will convert environ to raw config items, and insert the
config items between systemrcpath and userrcpath. This patch teaches
rccomponents to return the type information so the caller could distinguish
between "path" and raw config "items".
2017-03-26 21:04:29 -07:00
Jun Wu
d63b24bd71 rcutil: rename rcpath to rccomponents (API) 2017-03-26 20:48:00 -07:00
Jun Wu
582704c32f rcutil: move scmutil.*rcpath to rcutil (API)
As discussed at [1], the logic around "actual config"s seem to be
non-trivial enough that it's worth a new module.

This patch creates the module and move "scmutil.*rcpath" functions there as
the first step. More methods will be moved to the module in the future.

The module is different from config.py because the latter only cares about
data structure and parsing, and does not care about special case, or system
config paths, or environment variables.

[1]: https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-March/095503.html
2017-03-26 20:18:42 -07:00
Matt Harbison
bbf17f3e32 pager: improve support for various flavors of more on Windows
Hardcoding 'more' -> 'more.com' means that 'more.exe' from MSYS would need to be
configured with its *.exe extension.  This will resolve to either one, as
cmd.exe would have done if the command ran through the shell.

Something that's maybe problematic with this is it comes after 'pageractive' and
various ui configs have been set by the calling method.  But the other early
exits in this method don't undo those changes either.
2017-03-24 22:40:08 -04:00
Matt Harbison
6b815a9943 pager: fix the invocation of more on Windows
After 6a86fe38f1f6, with 'shell' being (mostly) set to False, invoking `more` no
longer worked.  Instead, a warning was printed and the pager was disabled.
Invoking `more.com` works.  Since a user may have configured 'pager.pager=more',
do this substitution at the end.  Surprisingly, `more` does allow for arguments,
so those are preserved.  This also allows `more` to work in MSYS.

Setting 'shell=False' runs the executable via CreateProcess(), which has rather
wonky rules for resolving an executable without an extension [1].  Resolving to
*.com is not among them.  Since 'shell=True' yields a cryptic error for a bad
$PAGER, and a *.exe program will work without specifying the extension, sticking
with current 'shell=False' seems like the right thing to do.  I don't think
there are any other *.com pagers out there, so this one special case seems OK.

If somebody wants to do something crazy that requires cmd.exe, I was able to get
normal paged output with 'pager.pager="cmd.exe /c more"'.  I assume you can
replace `more` with *.bat, *.vbs or various other creatures listed in $PATHEXT.

[1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx
2017-03-20 00:19:33 -04:00
Martin von Zweigbergk
dc4c37c445 plain: ignore [commands] config
We only have commands.{update,rebase}.requiredest so far. We should
clearly ignore those two if HGPLAIN is in effect, and it seems like we
should ignore any future config that will be added in [commands] since
that is about changing the behavior of commands.

Thanks to Yuya for suggesting to centralize the code in ui.py.

While at it, remove the unnecessary False values passed to
ui.configbool() for the aforementioned config options.
2017-03-21 21:26:52 -07:00
Simon Farnsworth
0057b864bd ui: restrict length of autogenerated blocked tags
Long autogenerated blocked tags tend to be because the command has an absolute
path; at Facebook, we've had a few where the tag is thousands of characters
long (in association with the mergedriver).

Change the default to use a suffix of a command as the default tag, limiting us
to 85 characters (for a 100 character tag). This is long enough to overflow a
standard terminal (thus be obviously autogenerated), but short enough to be
readable.
2017-03-20 05:08:21 -07:00
Augie Fackler
e225c8919b ui: convert to/from Unicode on Python 3 in ui.editor()
I considered making this I/O be done in terms of bytes, but that would
cause an observable regression for Windows users, as non-binary-mode
open does EOL conversion there. There are probably new encoding
dragons lurking here, so we may want to switch to using binary mode
and doing EOL conversion ourselves.
2017-03-19 01:38:10 -04:00
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