Commit Graph

82 Commits

Author SHA1 Message Date
Martin von Zweigbergk
d32ca3644f pager: if old pager extensions is enabled, respect pager.attend
This patch makes us respect pager.attend again if the extension is
enabled. It also brings back the default attend list, so e.g. summary
is not paged by default, just like it used to be before pager was
moved into core.
2017-03-13 21:43:17 -07:00
Pierre-Yves David
677892a9d7 pager: drop the 'color' dependant code
The 'color' implementation is in core and no longer wrap '_runcommand'. We drop
the extra complexity.
2017-02-28 20:12:08 +01:00
Augie Fackler
2e832efca3 pager: move most help to a new help topic and deprecate extension 2017-02-07 00:07:53 -05:00
Augie Fackler
bcf9ea0406 qdiff: migrate to modern pager API
This results in the default pager-attend list being empty. Sadly, we
can't let the code be that way, because some legacy extensions depend
on hooking the pager's attend list at import time (and we'd like to
not break them), and if the list is actually *empty* that triggers
magic behavior in the extension that attends everything. Instead, we
put a long, improbable command name as the only entry in the attend
list.
2017-02-06 23:57:21 -05:00
Augie Fackler
31938f0650 log: migrate to modern pager API 2017-02-06 22:59:25 -05:00
Augie Fackler
776882e795 export: migrate to modern pager API 2017-02-06 22:58:54 -05:00
Augie Fackler
a057b6046c diff: migrate to modern pager API 2017-02-06 22:58:26 -05:00
Augie Fackler
4452f8a320 cat: migrate to modern pager API 2017-02-06 22:57:52 -05:00
Augie Fackler
c7eae9f3c3 annotate: migrate to modern pager API 2017-02-06 22:52:47 -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
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
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
5f644ba68a pager: exit cleanly on SIGPIPE (BC)
Changeset 8b50aee1f75c removes SIGPIPE handling completely. This is wrong,
as it means that Mercurial does not exit when the pager does. Instead, raise
SignalInterrupt when SIGPIPE happens with a pager attached, to trigger the
normal exit path.

This will cause "killed!" to be printed to stderr (hence the BC warning),
but in the normal pager use case (where the pager gets both stderr and
stdout), this message is lost as we only get SIGPIPE when the pager quits.
2017-02-08 07:44:10 -08:00
Simon Farnsworth
6a6899c4d4 util: always force line buffered stdout when stdout is a tty (BC)
pager replaced stdout with a line buffered version to work around glibc
deciding on a buffering strategy on the first write to stdout. This is going
to make my next patch hard, as replacing stdout will make tracking time
spent blocked on it more challenging.

Move the line buffering requirement to util.py, and remove it from pager.
This means that the abuse of ui.formatted=True and pager set to cat or equivalent
no longer results in a line-buffered output to a pipe, hence (BC), although
I don't expect anyone to be affected
2017-02-03 15:10:27 -08:00
Simon Farnsworth
591b9bb95d pager: don't terminate with extreme prejudice on SIGPIPE (BC)
The default SIGPIPE handler causes Mercurial to exit immediately, without
running any Python cleanup code (except and finally blocks, atexit handlers
etc). This creates problems if you want to do something at exit.

If we need a different exit code for broken pipe from pager, then we should
code that ourselves in Python; this appears to have been cargo-culted from
the fork implementation of pager that's no longer used, where it was needed
to stop Broken Pipe errors appearing on the user's terminal.
2017-02-02 11:17:36 -08:00
Yuya Nishihara
9979640f1d pager: wrap _runcommand() no matter if stdout is redirected
We've made chg utilize the common code path implemented in pager.py (by
e8fb65f5e551 and e97133c7a9dc), but the chg server does not always start
with a tty. Because of this, uisetup() of the pager extension could be
skipped on the chg server.

Kudos given to Sean Farley for dogfooding new chg and spotting this problem.
2017-01-19 23:01:32 +09:00
Jun Wu
46900cecad pager: do not special case chg
Since chg has its own _runpager implementation, it's no longer necessary to
special-case chg in the pager extension. This will effectively enable the
new chg pager code path that runs inside runcommand.
2017-01-10 06:59:49 +08:00
Jun Wu
d337e8bfd0 pager: wrap ui._runpager
As discussed at [1], ui._runpager will be the new low-level API accepting a
pager command to actually run the pager. And ui.pager is the high-level API
which reads config directly from self.

This change is necessary for chgserver to override _runpager cleanly.

[1]: www.mercurial-scm.org/pipermail/mercurial-devel/2016-December/091656.html
2016-12-26 00:25:44 +00:00
Pulkit Goyal
1a4248666b py3: replace os.environ with encoding.environ (part 2 of 5) 2016-12-18 01:46:39 +05:30
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
timeless
64dce2c2d7 pager: use single quotes in use warning 2016-09-20 23:44:49 +00: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
Yuya Nishihara
a5c934df3c py3: move up symbol imports to enforce import-checker rules
Since (b) is banned, we should do the same for (a) for consistency.

 a) from mercurial import hg
    from mercurial.i18n import _

 b) from . import hg
    from .i18n import _
2016-05-14 14:03:12 +09:00
Jun Wu
cbbb576b1c pager: skip uisetup if chg is detected
chg has its own pager implementation that it wants to skip pager's uisetup.
It is currently done by redirecting stdout to /dev/null, which has unintended
side effects. This patch makes pager aware of chg and skip uisetup directly
from pager. We may want to merge chg and pager's pager implementation to
make this unnecessary in the future.
2016-03-14 15:03:19 +00:00
Augie Fackler
e5e6b47d65 pager: use absolute_import 2016-02-28 22:15:00 -05:00
timeless
e4b7c3bfda pager: improve help for --pager=
try to clarify how to enable/disable the pager
2015-11-30 18:47:33 +00:00
Yuya Nishihara
1f3d02756b pager: recreate stdout to make it line-buffered
We want to see partial command results as soon as possible. But the buffering
mode of stdout (= pager's stdin) was set to fully-buffered because it isn't
associated with a tty. So, this patch recreates new stdout object to force its
buffering mode.

Because two file objects are associated with the same stdout fd and their
destructors will call close(), one of them must be closed carefully. Python
expects that the stdout fd never be closed even after sys.stdout.close() [1],
but newstdout has no such hack. So this patch calls newstdout.close()
immediately before duplicating the original stdout fd to sys.stdout.

  operation              sys.stdout  newstdout  fd
  ---------------------  ----------  ---------  --------
  newstdout.close()      open        closed     closed
  os.dup2(stdoutfd, ..)  open        closed     open
  del sys.stdout         closed      closed     open [1]

 [1]: https://hg.python.org/cpython/file/v2.7.10/Python/sysmodule.c#l1391
2015-10-03 15:16:33 +09:00
Yuya Nishihara
20505cecd5 pager: rename variables of backup fds
The next patch will add backup file objects, so the original variable names
would be confusing.
2015-10-03 18:48:21 +09:00
Yuya Nishihara
cadf85db0f pager: inline _pagersubprocess() into _runpager()
We don't need _pagersubprocess() because the fork version was removed
at 783efe565d9e.
2015-10-03 15:02:52 +09:00
Pierre-Yves David
54067fb1c4 pager: drop python 2.4 hack around subprocess
Farewell, we do not need you anymore.
2015-05-18 16:20:12 -05:00
Augie Fackler
f95a6caba1 extensions: document that testedwith = 'internal' is special
Extension authors (notably at companies using hg) have been
cargo-culting the `testedwith = 'internal'` bit from hg's own
extensions, which then defeats our "file bugs over here" logic in
dispatch. Let's be more aggressive about trying to give extension
authors a hint about what testedwith should say.
2015-04-28 16:44:37 -04:00
Gregory Szorc
b1321c4998 pager: ensure wrapped dispatch._runcommand runs before color's
An upcoming patch will teach color to potentially act differently if the
pager is active. Since both extensions wrap the same function
(dispatch._runcommand) to change behavior, we must guarantee that
pager's wrapped function runs before color's so color may read the
breadcrumb left by pager.
2015-02-06 12:09:09 -08:00
Gregory Szorc
df5acb8a96 pager: set an attribute on ui indicating that a pager is active
A subsequent patch will teach the color extension to do different things
depending on whether a pager is active. This patch leaves a breadcrumb
on the ui instance to allow it do that that.
2015-02-06 12:07:56 -08:00
Matt Mackall
8f271ab8db pager: add attend-<command> option
This lets users override attend settings locally on a command
granularity.
2014-05-09 13:32:56 -05:00
Matt Mackall
9f887e4452 pager: variable reorder 2014-05-09 13:10:23 -05:00
Matt Mackall
5c5576136a pager: break auto out of command check loop 2014-05-09 13:07:50 -05:00
Matt Mackall
e855b86a3a pager: break always out of command check loop 2014-05-09 13:05:52 -05:00
Matt Mackall
911703535d pager: break pager invocation out of command check loop 2014-05-09 12:58:53 -05:00
Mads Kiilerich
2629efac4f config: set a 'source' in most cases where config don't come from file but code
Some extensions set configuration settings that showed up in 'hg showconfig
--debug' with 'none' as source. That was confusing.

Instead, they will now tell which extension they come from.

This change tries to be consistent and specify a source everywhere - also where
it perhaps is less relevant.
2014-03-19 02:45:14 +01:00
David Soria Parra
d4d544f551 pager: honour internal aliases
If paging is configured for a command all it's internal defined aliases
will be paged as well. This will make attend=log cause 'hg history'
to run the pager. However custom aliases will not be paged by default.
2013-10-12 18:51:34 -07:00
Bryan O'Sullivan
4a4e45180d pager: add missing imports of errno and shlex
Found using Cython.
2013-04-12 17:35:56 -07:00
Matt Mackall
fb3c5e53c4 pager: catch ctrl-c on exit (issue3834) 2013-02-22 15:17:33 -06:00
Thomas Arendsen Hein
ef236f0ec1 pager: drop -S option for less in example for pager configuration
Using less -S will hide possibly important information when reviewing a
changeset, e.g. something wrong/dangerous after the 80th column, because
"less" will not give an indication that following characters are hidden.
2012-07-31 15:50:44 +02:00
Michael Bacarella
497a8d346f pager: work around bug in python 2.4's subprocess module (issue3533)
hg v2.2.2 fixed the pager on Windows, but broke it on Python 2.4.
This patch only uses the new behavior if Python >= 2.5 is detected.
2012-07-06 18:06:52 -04:00
Matt Mackall
99486917d1 pager: use ui._isatty infrastructure 2012-05-20 14:33:49 -05:00
Augie Fackler
96d44b39f7 hgext: mark all first-party extensions as such 2012-05-15 14:37:49 -05:00
David Soria Parra
7bbe0ff197 pager: check if signal.SIGPIPE exists
We have to check for signal.SIGPIPE before we attempt
to set it.
2012-05-12 09:43:12 +02:00
David Soria Parra
d6e40e51fb pager: remove quiet flag
With the pager running as a child process, exiting the pager doesn't
result in a broken pipe message. To distinguish the exit broken pipe code
from a mercurial abort we register the default action for SIGPIPE. This
results in a 141 exit code instead of a 255. On windows SIGPIPE doesn't
exists and a ValueError will be thrown.
2012-05-11 16:08:49 +02:00
Brodie Rao
6fdaf7d897 pager: preserve Hg's exit code (and fix Windows support) (issue3225)
This changes how the pager extension invokes the pager. Prior to this change,
the extension would fork Hg and exec the pager in the parent process. This
loses Hg exit code, and it doesn't work on Windows.

Now the pager is invoked using the subprocess library, and an atexit handler is
registered that makes Hg wait for the pager to exit before it exits itself.

Note that if you exit the pager before Hg is done running, you'll get an exit
code of 255, which is caused by Python blowing up due to a broken pipe. If you
set pager.quiet=True, you'll get the OS-level return code of 141.
2012-05-11 15:45:37 +02:00
Augie Fackler
3fddb45056 hgext: replace uses of hasattr with util.safehasattr 2011-07-25 20:37:12 -05:00