Mercurial > public > mercurial-scm > hg-stable
annotate mercurial/ui.py @ 52665:24ee91ba9aa8
pyupgrade: drop usage of py3 aliases for `OSError`
These were different classes in py2, but now a handful of error classes are just
an alias of `OSError`, like `IOError`, `EnvironmentError`, `WindowsError`, etc.
This is the result of running a hacked version of `pyupgrade` 3.19.1[1]
$ hg files -0 'relglob:**.py' | xargs -0 \
pyupgrade --py38-plus --keep-percent-format --keep-mock --keep-runtime-typing
The hack is because it doesn't have command line switches to disable most
changes, so it makes tons of unrelated changes all at once. The hack is to
1) patch `pyupgrade._main._fix_tokens()` to immediately return its content arg
2) change `pyupgrade._data.register_decorator()` to only register the function
if it's from the fixer we're interested in:
if func.__module__ in (
"pyupgrade._plugins.exceptions",
):
FUNCS[tp].append(func)
return func
[1] https://github.com/asottile/pyupgrade
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sun, 05 Jan 2025 21:03:17 -0500 |
parents | cc918741a22a |
children | e627cc25b6f3 |
rev | line source |
---|---|
207 | 1 # ui.py - user interface bits for mercurial |
2 # | |
46819
d4ba4d51f85f
contributor: change mentions of mpm to olivia
Rapha?l Gom?s <rgomes@octobus.net>
parents:
46734
diff
changeset
|
3 # Copyright 2005-2007 Olivia Mackall <olivia@selenic.com> |
207 | 4 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8222
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
10263 | 6 # GNU General Public License version 2 or any later version. |
207 | 7 |
51901
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51302
diff
changeset
|
8 from __future__ import annotations |
25989
2cc4e8385661
ui: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
9 |
30996
e92daf156d5c
ui: provide a mechanism to track and log blocked time
Simon Farnsworth <simonfar@fb.com>
parents:
30965
diff
changeset
|
10 import collections |
30489
b0a8337ba9af
ui: add configoverride context manager
Kostia Balytskyi <ikostia@fb.com>
parents:
30482
diff
changeset
|
11 import contextlib |
45035
24b1a8eb73aa
ui: add option to timestamp status and diagnostic messages
Joerg Sonnenberger <joerg@bec.de>
parents:
45012
diff
changeset
|
12 import datetime |
25989
2cc4e8385661
ui: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
13 import errno |
25629
52e5f68d8363
devel-warn: move the develwarn function as a method of the ui object
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25568
diff
changeset
|
14 import inspect |
25989
2cc4e8385661
ui: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
15 import os |
27392
00aa37c65e0a
ui: try to handle $$ more robustly in prompts (issue4970)
Matt Mackall <mpm@selenic.com>
parents:
26820
diff
changeset
|
16 import re |
31012
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
17 import signal |
25989
2cc4e8385661
ui: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
18 import socket |
31012
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
19 import subprocess |
25989
2cc4e8385661
ui: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
20 import sys |
2cc4e8385661
ui: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
21 import traceback |
51302
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51003
diff
changeset
|
22 import typing |
25989
2cc4e8385661
ui: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
23 |
49889
25fe689a4a64
typing: add type hints related to progress bars in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49888
diff
changeset
|
24 from typing import ( |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
25 Any, |
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
26 Callable, |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
27 Dict, |
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
28 List, |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
29 NoReturn, |
49889
25fe689a4a64
typing: add type hints related to progress bars in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49888
diff
changeset
|
30 Optional, |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
31 Tuple, |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
32 Type, |
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
33 TypeVar, |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
34 Union, |
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
35 cast, |
49894
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
36 overload, |
49889
25fe689a4a64
typing: add type hints related to progress bars in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49888
diff
changeset
|
37 ) |
25fe689a4a64
typing: add type hints related to progress bars in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49888
diff
changeset
|
38 |
25989
2cc4e8385661
ui: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
39 from .i18n import _ |
2cc4e8385661
ui: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
40 from .node import hex |
2cc4e8385661
ui: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
41 |
2cc4e8385661
ui: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
42 from . import ( |
31104
894bdcdc75df
color: move the 'colorlabel' call to the core 'ui' class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
43 color, |
25989
2cc4e8385661
ui: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
44 config, |
33002
6d983e8af49c
configitems: introduce a central registry for config option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32985
diff
changeset
|
45 configitems, |
30291
e9fca89c6d58
py3: use encoding.environ in ui.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29982
diff
changeset
|
46 encoding, |
25989
2cc4e8385661
ui: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
47 error, |
50804
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50487
diff
changeset
|
48 extensions, |
25989
2cc4e8385661
ui: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
49 formatter, |
41004
ab92e2111408
ui: install logger that sends debug.extensions messages to stderr
Yuya Nishihara <yuya@tcha.org>
parents:
40795
diff
changeset
|
50 loggingutil, |
25989
2cc4e8385661
ui: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
51 progress, |
30528
20a42325fdef
py3: use pycompat.getcwd() instead of os.getcwd()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30489
diff
changeset
|
52 pycompat, |
25989
2cc4e8385661
ui: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
53 scmutil, |
2cc4e8385661
ui: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
54 util, |
2cc4e8385661
ui: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
55 ) |
52447
0a81f3ef054c
config: move `rcutil` module under a new `mercurial.configuration` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52394
diff
changeset
|
56 from .configuration import rcutil |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36916
diff
changeset
|
57 from .utils import ( |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36916
diff
changeset
|
58 dateutil, |
37122
d4a2e0d5d042
procutil: bulk-replace util.std* to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37087
diff
changeset
|
59 procutil, |
44032
5ac0e6f19eb4
ui: refactor `readconfig()` into a form that can consume resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
44023
diff
changeset
|
60 resourceutil, |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36916
diff
changeset
|
61 stringutil, |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46828
diff
changeset
|
62 urlutil, |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36916
diff
changeset
|
63 ) |
207 | 64 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
65 _ConfigItems = Dict[Tuple[bytes, bytes], object] # {(section, name) : value} |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
66 # The **opts args of the various write() methods can be basically anything, but |
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
67 # there's no way to express it as "anything but str". So type it to be the |
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
68 # handful of known types that are used. |
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
69 _MsgOpts = Union[bytes, bool, List["_PromptChoice"]] |
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
70 _PromptChoice = Tuple[bytes, bytes] |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
71 _Tui = TypeVar('_Tui', bound="ui") |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
72 |
29378
fea71f66ebff
url: remember http password database in ui object
liscju <piotr.listkiewicz@gmail.com>
parents:
29366
diff
changeset
|
73 urlreq = util.urlreq |
fea71f66ebff
url: remember http password database in ui object
liscju <piotr.listkiewicz@gmail.com>
parents:
29366
diff
changeset
|
74 |
30999
fd598149112b
ui: time calls to ui.system
Simon Farnsworth <simonfar@fb.com>
parents:
30998
diff
changeset
|
75 # for use with str.translate(None, _keepalnum), to keep just alphanumerics |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
76 _keepalnum: bytes = b''.join( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
77 c for c in map(pycompat.bytechr, range(256)) if not c.isalnum() |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
78 ) |
30999
fd598149112b
ui: time calls to ui.system
Simon Farnsworth <simonfar@fb.com>
parents:
30998
diff
changeset
|
79 |
32890
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
80 # The config knobs that will be altered (if unset) by ui.tweakdefaults. |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
81 tweakrc: bytes = b""" |
32890
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
82 [ui] |
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
83 # The rollback command is dangerous. As a rule, don't use it. |
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
84 rollback = False |
35090
929858db4d22
tweakdefaults: turn on ui.statuscopies
Martin von Zweigbergk <martinvonz@google.com>
parents:
35013
diff
changeset
|
85 # Make `hg status` report copy information |
929858db4d22
tweakdefaults: turn on ui.statuscopies
Martin von Zweigbergk <martinvonz@google.com>
parents:
35013
diff
changeset
|
86 statuscopies = yes |
35315
03a83ace9816
ui: add curses interface to tweakdefaults
Augie Fackler <augie@google.com>
parents:
35197
diff
changeset
|
87 # Prefer curses UIs when available. Revert to plain-text with `text`. |
03a83ace9816
ui: add curses interface to tweakdefaults
Augie Fackler <augie@google.com>
parents:
35197
diff
changeset
|
88 interface = curses |
41507
97ab4cbb342e
tweakdefaults: set ui.relative-paths instead of command.status.relative
Martin von Zweigbergk <martinvonz@google.com>
parents:
41498
diff
changeset
|
89 # Make compatible commands emit cwd-relative paths by default. |
97ab4cbb342e
tweakdefaults: set ui.relative-paths instead of command.status.relative
Martin von Zweigbergk <martinvonz@google.com>
parents:
41498
diff
changeset
|
90 relative-paths = yes |
32890
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
91 |
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
92 [commands] |
38652
bfcd5c7cbf9a
grep: restore pre-9ef10437bb88 behavior, enable wdir search by tweakdefaults
Yuya Nishihara <yuya@tcha.org>
parents:
38623
diff
changeset
|
93 # Grep working directory by default. |
bfcd5c7cbf9a
grep: restore pre-9ef10437bb88 behavior, enable wdir search by tweakdefaults
Yuya Nishihara <yuya@tcha.org>
parents:
38623
diff
changeset
|
94 grep.all-files = True |
34707
6cd8d8203204
tweakdefaults: make commands.update.check be `noconflict`
Augie Fackler <augie@google.com>
parents:
34645
diff
changeset
|
95 # Refuse to perform an `hg update` that would cause a file content merge |
6cd8d8203204
tweakdefaults: make commands.update.check be `noconflict`
Augie Fackler <augie@google.com>
parents:
34645
diff
changeset
|
96 update.check = noconflict |
36916
98487ad0cf8b
tweakdefaults: add commands.status.verbose to tweakefaults
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36842
diff
changeset
|
97 # Show conflicts information in `hg status` |
98487ad0cf8b
tweakdefaults: add commands.status.verbose to tweakefaults
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36842
diff
changeset
|
98 status.verbose = True |
42564
44e99811bea7
tweakdefaults: make hg resolve require --re-merge flag to re-merge
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
42548
diff
changeset
|
99 # Make `hg resolve` with no action (like `-m`) fail instead of re-merging. |
44e99811bea7
tweakdefaults: make hg resolve require --re-merge flag to re-merge
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
42548
diff
changeset
|
100 resolve.explicit-re-merge = True |
32890
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
101 |
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
102 [diff] |
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
103 git = 1 |
35316
4caafe280488
ui: add diff.showfunc to tweakdefaults
Augie Fackler <augie@google.com>
parents:
35315
diff
changeset
|
104 showfunc = 1 |
38623
92c845c097aa
tweakdefaults: enable word-diff by default
Augie Fackler <augie@google.com>
parents:
38576
diff
changeset
|
105 word-diff = 1 |
32890
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
106 """ |
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
107 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
108 samplehgrcs: Dict[bytes, bytes] = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
109 b'user': b"""# example user config (see 'hg help config' for more info) |
22419
fdfc9faca273
ui: move samplehgrcs from config
Matt Mackall <mpm@selenic.com>
parents:
22291
diff
changeset
|
110 [ui] |
fdfc9faca273
ui: move samplehgrcs from config
Matt Mackall <mpm@selenic.com>
parents:
22291
diff
changeset
|
111 # name and email, e.g. |
fdfc9faca273
ui: move samplehgrcs from config
Matt Mackall <mpm@selenic.com>
parents:
22291
diff
changeset
|
112 # username = Jane Doe <jdoe@example.com> |
fdfc9faca273
ui: move samplehgrcs from config
Matt Mackall <mpm@selenic.com>
parents:
22291
diff
changeset
|
113 username = |
fdfc9faca273
ui: move samplehgrcs from config
Matt Mackall <mpm@selenic.com>
parents:
22291
diff
changeset
|
114 |
34568
63c19b7fa100
ui: recommend tweakdefaults in the default hgrc template
Augie Fackler <augie@google.com>
parents:
34482
diff
changeset
|
115 # We recommend enabling tweakdefaults to get slight improvements to |
63c19b7fa100
ui: recommend tweakdefaults in the default hgrc template
Augie Fackler <augie@google.com>
parents:
34482
diff
changeset
|
116 # the UI over time. Make sure to set HGPLAIN in the environment when |
63c19b7fa100
ui: recommend tweakdefaults in the default hgrc template
Augie Fackler <augie@google.com>
parents:
34482
diff
changeset
|
117 # writing scripts! |
63c19b7fa100
ui: recommend tweakdefaults in the default hgrc template
Augie Fackler <augie@google.com>
parents:
34482
diff
changeset
|
118 # tweakdefaults = True |
63c19b7fa100
ui: recommend tweakdefaults in the default hgrc template
Augie Fackler <augie@google.com>
parents:
34482
diff
changeset
|
119 |
32093
4d438efb825a
color: reflect the new default in the example hgrc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32078
diff
changeset
|
120 # uncomment to disable color in command output |
32094
2de67783dd31
color: point to the global help in the example hgrc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32093
diff
changeset
|
121 # (see 'hg help color' for details) |
32093
4d438efb825a
color: reflect the new default in the example hgrc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32078
diff
changeset
|
122 # color = never |
31139
791ea883fc44
config: suggest the 'ui.color' instead of the 'color' extension
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31134
diff
changeset
|
123 |
32100
21eb863187ea
pager: advertise the config option in the default hgrc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32097
diff
changeset
|
124 # uncomment to disable command output pagination |
21eb863187ea
pager: advertise the config option in the default hgrc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32097
diff
changeset
|
125 # (see 'hg help pager' for details) |
32104
f06d23af6cdf
pager: rename 'pager.enable' to 'ui.paginate'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32100
diff
changeset
|
126 # paginate = never |
32100
21eb863187ea
pager: advertise the config option in the default hgrc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32097
diff
changeset
|
127 |
22419
fdfc9faca273
ui: move samplehgrcs from config
Matt Mackall <mpm@selenic.com>
parents:
22291
diff
changeset
|
128 [extensions] |
41998
018acb7a3490
samplehgrcs: clarify which lines should be uncommented
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
41834
diff
changeset
|
129 # uncomment the lines below to enable some popular extensions |
29982
3d2ea1403c62
samplehgrcs: use single quotes in use warning
timeless <timeless@mozdev.org>
parents:
29774
diff
changeset
|
130 # (see 'hg help extensions' for more info) |
22419
fdfc9faca273
ui: move samplehgrcs from config
Matt Mackall <mpm@selenic.com>
parents:
22291
diff
changeset
|
131 # |
41999
ba064f95175e
samplehgrcs: update the list of suggested extensions
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
41998
diff
changeset
|
132 # histedit = |
ba064f95175e
samplehgrcs: update the list of suggested extensions
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
41998
diff
changeset
|
133 # rebase = |
ba064f95175e
samplehgrcs: update the list of suggested extensions
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
41998
diff
changeset
|
134 # uncommit = |
32097
601bfcddccdc
config: drop pager from the recommended extension
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32096
diff
changeset
|
135 """, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
136 b'cloned': b"""# example repository config (see 'hg help config' for more info) |
22837
2be7d5ebd4d0
config: use the same hgrc for a cloned repo as for an uninitted repo
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
22836
diff
changeset
|
137 [paths] |
2be7d5ebd4d0
config: use the same hgrc for a cloned repo as for an uninitted repo
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
22836
diff
changeset
|
138 default = %s |
2be7d5ebd4d0
config: use the same hgrc for a cloned repo as for an uninitted repo
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
22836
diff
changeset
|
139 |
2be7d5ebd4d0
config: use the same hgrc for a cloned repo as for an uninitted repo
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
22836
diff
changeset
|
140 # path aliases to other clones of this repo in URLs or filesystem paths |
29982
3d2ea1403c62
samplehgrcs: use single quotes in use warning
timeless <timeless@mozdev.org>
parents:
29774
diff
changeset
|
141 # (see 'hg help config.paths' for more info) |
22837
2be7d5ebd4d0
config: use the same hgrc for a cloned repo as for an uninitted repo
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
22836
diff
changeset
|
142 # |
30879
4431add9aef9
ui: replace obsolete default-push with default:pushurl (issue5485)
Rishabh Madan <rishabhmadan96@gmail.com>
parents:
30848
diff
changeset
|
143 # default:pushurl = ssh://jdoe@example.net/hg/jdoes-fork |
4431add9aef9
ui: replace obsolete default-push with default:pushurl (issue5485)
Rishabh Madan <rishabhmadan96@gmail.com>
parents:
30848
diff
changeset
|
144 # my-fork = ssh://jdoe@example.net/hg/jdoes-fork |
4431add9aef9
ui: replace obsolete default-push with default:pushurl (issue5485)
Rishabh Madan <rishabhmadan96@gmail.com>
parents:
30848
diff
changeset
|
145 # my-clone = /home/jdoe/jdoes-clone |
22837
2be7d5ebd4d0
config: use the same hgrc for a cloned repo as for an uninitted repo
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
22836
diff
changeset
|
146 |
2be7d5ebd4d0
config: use the same hgrc for a cloned repo as for an uninitted repo
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
22836
diff
changeset
|
147 [ui] |
2be7d5ebd4d0
config: use the same hgrc for a cloned repo as for an uninitted repo
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
22836
diff
changeset
|
148 # name and email (local to this repository, optional), e.g. |
2be7d5ebd4d0
config: use the same hgrc for a cloned repo as for an uninitted repo
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
22836
diff
changeset
|
149 # username = Jane Doe <jdoe@example.com> |
2be7d5ebd4d0
config: use the same hgrc for a cloned repo as for an uninitted repo
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
22836
diff
changeset
|
150 """, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
151 b'local': b"""# example repository config (see 'hg help config' for more info) |
22836
5a831e4e6d7a
config: give a more detailed sample repo config
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
22783
diff
changeset
|
152 [paths] |
5a831e4e6d7a
config: give a more detailed sample repo config
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
22783
diff
changeset
|
153 # path aliases to other clones of this repo in URLs or filesystem paths |
29982
3d2ea1403c62
samplehgrcs: use single quotes in use warning
timeless <timeless@mozdev.org>
parents:
29774
diff
changeset
|
154 # (see 'hg help config.paths' for more info) |
22836
5a831e4e6d7a
config: give a more detailed sample repo config
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
22783
diff
changeset
|
155 # |
30879
4431add9aef9
ui: replace obsolete default-push with default:pushurl (issue5485)
Rishabh Madan <rishabhmadan96@gmail.com>
parents:
30848
diff
changeset
|
156 # default = http://example.com/hg/example-repo |
4431add9aef9
ui: replace obsolete default-push with default:pushurl (issue5485)
Rishabh Madan <rishabhmadan96@gmail.com>
parents:
30848
diff
changeset
|
157 # default:pushurl = ssh://jdoe@example.net/hg/jdoes-fork |
4431add9aef9
ui: replace obsolete default-push with default:pushurl (issue5485)
Rishabh Madan <rishabhmadan96@gmail.com>
parents:
30848
diff
changeset
|
158 # my-fork = ssh://jdoe@example.net/hg/jdoes-fork |
4431add9aef9
ui: replace obsolete default-push with default:pushurl (issue5485)
Rishabh Madan <rishabhmadan96@gmail.com>
parents:
30848
diff
changeset
|
159 # my-clone = /home/jdoe/jdoes-clone |
22836
5a831e4e6d7a
config: give a more detailed sample repo config
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
22783
diff
changeset
|
160 |
5a831e4e6d7a
config: give a more detailed sample repo config
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
22783
diff
changeset
|
161 [ui] |
5a831e4e6d7a
config: give a more detailed sample repo config
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
22783
diff
changeset
|
162 # name and email (local to this repository, optional), e.g. |
5a831e4e6d7a
config: give a more detailed sample repo config
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
22783
diff
changeset
|
163 # username = Jane Doe <jdoe@example.com> |
22419
fdfc9faca273
ui: move samplehgrcs from config
Matt Mackall <mpm@selenic.com>
parents:
22291
diff
changeset
|
164 """, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
165 b'global': b"""# example system-wide hg config (see 'hg help config' for more info) |
22419
fdfc9faca273
ui: move samplehgrcs from config
Matt Mackall <mpm@selenic.com>
parents:
22291
diff
changeset
|
166 |
31139
791ea883fc44
config: suggest the 'ui.color' instead of the 'color' extension
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31134
diff
changeset
|
167 [ui] |
32093
4d438efb825a
color: reflect the new default in the example hgrc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32078
diff
changeset
|
168 # uncomment to disable color in command output |
32094
2de67783dd31
color: point to the global help in the example hgrc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32093
diff
changeset
|
169 # (see 'hg help color' for details) |
32093
4d438efb825a
color: reflect the new default in the example hgrc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32078
diff
changeset
|
170 # color = never |
31139
791ea883fc44
config: suggest the 'ui.color' instead of the 'color' extension
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31134
diff
changeset
|
171 |
32100
21eb863187ea
pager: advertise the config option in the default hgrc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32097
diff
changeset
|
172 # uncomment to disable command output pagination |
21eb863187ea
pager: advertise the config option in the default hgrc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32097
diff
changeset
|
173 # (see 'hg help pager' for details) |
32104
f06d23af6cdf
pager: rename 'pager.enable' to 'ui.paginate'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32100
diff
changeset
|
174 # paginate = never |
32100
21eb863187ea
pager: advertise the config option in the default hgrc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32097
diff
changeset
|
175 |
22419
fdfc9faca273
ui: move samplehgrcs from config
Matt Mackall <mpm@selenic.com>
parents:
22291
diff
changeset
|
176 [extensions] |
41998
018acb7a3490
samplehgrcs: clarify which lines should be uncommented
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
41834
diff
changeset
|
177 # uncomment the lines below to enable some popular extensions |
29982
3d2ea1403c62
samplehgrcs: use single quotes in use warning
timeless <timeless@mozdev.org>
parents:
29774
diff
changeset
|
178 # (see 'hg help extensions' for more info) |
22419
fdfc9faca273
ui: move samplehgrcs from config
Matt Mackall <mpm@selenic.com>
parents:
22291
diff
changeset
|
179 # |
fdfc9faca273
ui: move samplehgrcs from config
Matt Mackall <mpm@selenic.com>
parents:
22291
diff
changeset
|
180 # blackbox = |
32096
726121fa86e1
config: use "churn" as an example extension
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32094
diff
changeset
|
181 # churn = |
32097
601bfcddccdc
config: drop pager from the recommended extension
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32096
diff
changeset
|
182 """, |
22419
fdfc9faca273
ui: move samplehgrcs from config
Matt Mackall <mpm@selenic.com>
parents:
22291
diff
changeset
|
183 } |
fdfc9faca273
ui: move samplehgrcs from config
Matt Mackall <mpm@selenic.com>
parents:
22291
diff
changeset
|
184 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
185 |
34482
75de5d456b60
ui: convert to/from Optional[bytes] to Optional[str] in password manager
Augie Fackler <augie@google.com>
parents:
34427
diff
changeset
|
186 def _maybestrurl(maybebytes): |
38576
152f4822d210
pycompat: move rapply() from util
Yuya Nishihara <yuya@tcha.org>
parents:
38528
diff
changeset
|
187 return pycompat.rapply(pycompat.strurl, maybebytes) |
34482
75de5d456b60
ui: convert to/from Optional[bytes] to Optional[str] in password manager
Augie Fackler <augie@google.com>
parents:
34427
diff
changeset
|
188 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
189 |
34482
75de5d456b60
ui: convert to/from Optional[bytes] to Optional[str] in password manager
Augie Fackler <augie@google.com>
parents:
34427
diff
changeset
|
190 def _maybebytesurl(maybestr): |
38576
152f4822d210
pycompat: move rapply() from util
Yuya Nishihara <yuya@tcha.org>
parents:
38528
diff
changeset
|
191 return pycompat.rapply(pycompat.bytesurl, maybestr) |
30965
8b83b626fb1e
ui: remove urllib2 from being imported early
Kyle Lippincott <spectral@google.com>
parents:
30952
diff
changeset
|
192 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
193 |
49037
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49026
diff
changeset
|
194 class httppasswordmgrdbproxy: |
30965
8b83b626fb1e
ui: remove urllib2 from being imported early
Kyle Lippincott <spectral@google.com>
parents:
30952
diff
changeset
|
195 """Delays loading urllib2 until it's needed.""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
196 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
197 def __init__(self) -> None: |
30965
8b83b626fb1e
ui: remove urllib2 from being imported early
Kyle Lippincott <spectral@google.com>
parents:
30952
diff
changeset
|
198 self._mgr = None |
8b83b626fb1e
ui: remove urllib2 from being imported early
Kyle Lippincott <spectral@google.com>
parents:
30952
diff
changeset
|
199 |
8b83b626fb1e
ui: remove urllib2 from being imported early
Kyle Lippincott <spectral@google.com>
parents:
30952
diff
changeset
|
200 def _get_mgr(self): |
8b83b626fb1e
ui: remove urllib2 from being imported early
Kyle Lippincott <spectral@google.com>
parents:
30952
diff
changeset
|
201 if self._mgr is None: |
8b83b626fb1e
ui: remove urllib2 from being imported early
Kyle Lippincott <spectral@google.com>
parents:
30952
diff
changeset
|
202 self._mgr = urlreq.httppasswordmgrwithdefaultrealm() |
8b83b626fb1e
ui: remove urllib2 from being imported early
Kyle Lippincott <spectral@google.com>
parents:
30952
diff
changeset
|
203 return self._mgr |
8b83b626fb1e
ui: remove urllib2 from being imported early
Kyle Lippincott <spectral@google.com>
parents:
30952
diff
changeset
|
204 |
34427
ae2fcf7af409
httppasswordmgrdbproxy: specify exact arguments
Augie Fackler <augie@google.com>
parents:
34368
diff
changeset
|
205 def add_password(self, realm, uris, user, passwd): |
34482
75de5d456b60
ui: convert to/from Optional[bytes] to Optional[str] in password manager
Augie Fackler <augie@google.com>
parents:
34427
diff
changeset
|
206 return self._get_mgr().add_password( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
207 _maybestrurl(realm), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
208 _maybestrurl(uris), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
209 _maybestrurl(user), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
210 _maybestrurl(passwd), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
211 ) |
30965
8b83b626fb1e
ui: remove urllib2 from being imported early
Kyle Lippincott <spectral@google.com>
parents:
30952
diff
changeset
|
212 |
34427
ae2fcf7af409
httppasswordmgrdbproxy: specify exact arguments
Augie Fackler <augie@google.com>
parents:
34368
diff
changeset
|
213 def find_user_password(self, realm, uri): |
35940
72de5c504833
py3: factor out helpers to apply string conversion recursively
Yuya Nishihara <yuya@tcha.org>
parents:
35937
diff
changeset
|
214 mgr = self._get_mgr() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
215 return _maybebytesurl( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
216 mgr.find_user_password(_maybestrurl(realm), _maybestrurl(uri)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
217 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
218 |
30965
8b83b626fb1e
ui: remove urllib2 from being imported early
Kyle Lippincott <spectral@google.com>
parents:
30952
diff
changeset
|
219 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
220 def _catchterm(*args) -> NoReturn: |
31012
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
221 raise error.SignalInterrupt |
30965
8b83b626fb1e
ui: remove urllib2 from being imported early
Kyle Lippincott <spectral@google.com>
parents:
30952
diff
changeset
|
222 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
223 |
32976
4a3f1d362e5f
config: explicitly track the use of the standard default value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32890
diff
changeset
|
224 # unique object used to detect no default value has been provided when |
4a3f1d362e5f
config: explicitly track the use of the standard default value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32890
diff
changeset
|
225 # retrieving configuration value. |
4a3f1d362e5f
config: explicitly track the use of the standard default value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32890
diff
changeset
|
226 _unset = object() |
4a3f1d362e5f
config: explicitly track the use of the standard default value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32890
diff
changeset
|
227 |
34882
e9f320a40b44
ui: move request exit handlers to global state
Saurabh Singh <singhsrb@fb.com>
parents:
34858
diff
changeset
|
228 # _reqexithandlers: callbacks run at the end of a request |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
229 _reqexithandlers: List = [] |
34882
e9f320a40b44
ui: move request exit handlers to global state
Saurabh Singh <singhsrb@fb.com>
parents:
34858
diff
changeset
|
230 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
231 |
49037
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49026
diff
changeset
|
232 class ui: |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
233 def __init__(self, src: Optional["ui"] = None) -> None: |
30564
d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30546
diff
changeset
|
234 """Create a fresh new ui object if no src given |
d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30546
diff
changeset
|
235 |
d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30546
diff
changeset
|
236 Use uimod.ui.load() to create a ui which knows global and user configs. |
d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30546
diff
changeset
|
237 In most cases, you should use ui.copy() to create a copy of an existing |
d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30546
diff
changeset
|
238 ui object. |
d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30546
diff
changeset
|
239 """ |
21132
350dc24a553d
ui: pushbuffer can now also capture stderr
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20788
diff
changeset
|
240 # _buffers: used for temporary capture of output |
8202 | 241 self._buffers = [] |
27106
6ef17697b03d
ui: track label expansion when creating buffers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27068
diff
changeset
|
242 # 3-tuple describing how each buffer in the stack behaves. |
6ef17697b03d
ui: track label expansion when creating buffers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27068
diff
changeset
|
243 # Values are (capture stderr, capture subprocesses, apply labels). |
21132
350dc24a553d
ui: pushbuffer can now also capture stderr
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20788
diff
changeset
|
244 self._bufferstates = [] |
27106
6ef17697b03d
ui: track label expansion when creating buffers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27068
diff
changeset
|
245 # When a buffer is active, defines whether we are expanding labels. |
6ef17697b03d
ui: track label expansion when creating buffers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27068
diff
changeset
|
246 # This exists to prevent an extra list lookup. |
6ef17697b03d
ui: track label expansion when creating buffers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27068
diff
changeset
|
247 self._bufferapplylabels = None |
9851
9e7b2c49d25d
Make it possible to debug failed hook imports via use of --traceback
Bryan O'Sullivan <bos@serpentine.com>
parents:
9786
diff
changeset
|
248 self.quiet = self.verbose = self.debugflag = self.tracebackflag = False |
8208
32a2a1e244f1
ui: make interactive a method
Matt Mackall <mpm@selenic.com>
parents:
8206
diff
changeset
|
249 self._reportuntrusted = True |
33002
6d983e8af49c
configitems: introduce a central registry for config option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32985
diff
changeset
|
250 self._knownconfig = configitems.coreitems |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
251 self._ocfg = config.config() # overlay |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
252 self._tcfg = config.config() # trusted |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
253 self._ucfg = config.config() # untrusted |
8478
d728f126c1b7
ui: use set instead of dict
Martin Geisler <mg@lazybytes.net>
parents:
8409
diff
changeset
|
254 self._trustusers = set() |
d728f126c1b7
ui: use set instead of dict
Martin Geisler <mg@lazybytes.net>
parents:
8409
diff
changeset
|
255 self._trustgroups = set() |
17048
15d4d475de9e
ui: add a variable to control whether hooks should be called
Idan Kamara <idankk86@gmail.com>
parents:
16383
diff
changeset
|
256 self.callhooks = True |
47283
a671832a8e41
urlutil: move url "fixing" at the time of `ui.paths` initialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47244
diff
changeset
|
257 # hold the root to use for each [paths] entry |
a671832a8e41
urlutil: move url "fixing" at the time of `ui.paths` initialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47244
diff
changeset
|
258 self._path_to_root = {} |
29109
e9ce33c642e8
ui: add an instance flag to hold --insecure bit
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29096
diff
changeset
|
259 # Insecure server connections requested. |
e9ce33c642e8
ui: add an instance flag to hold --insecure bit
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29096
diff
changeset
|
260 self.insecureconnections = False |
30996
e92daf156d5c
ui: provide a mechanism to track and log blocked time
Simon Farnsworth <simonfar@fb.com>
parents:
30965
diff
changeset
|
261 # Blocked time |
e92daf156d5c
ui: provide a mechanism to track and log blocked time
Simon Farnsworth <simonfar@fb.com>
parents:
30965
diff
changeset
|
262 self.logblockedtimes = False |
31123
a185b903bda3
color: have the 'ui' object carry the '_colormode' directly
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31111
diff
changeset
|
263 # color mode: see mercurial/color.py for possible value |
a185b903bda3
color: have the 'ui' object carry the '_colormode' directly
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31111
diff
changeset
|
264 self._colormode = None |
31130
268caf97c38f
color: move the dict with terminfo parameters on the ui object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31125
diff
changeset
|
265 self._terminfoparams = {} |
31132
f5131d4f512a
color: move 'styles' definition on the 'ui' object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31131
diff
changeset
|
266 self._styles = {} |
38528
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
267 self._uninterruptible = False |
45035
24b1a8eb73aa
ui: add option to timestamp status and diagnostic messages
Joerg Sonnenberger <joerg@bec.de>
parents:
45012
diff
changeset
|
268 self.showtimestamp = False |
8136
6b5522cb2ad2
ui: refactor option setting
Matt Mackall <mpm@selenic.com>
parents:
8135
diff
changeset
|
269 |
8190
9b8ac5fb7760
ui: kill most users of parentui name and arg, replace with .copy()
Matt Mackall <mpm@selenic.com>
parents:
8189
diff
changeset
|
270 if src: |
40593
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
271 self._fout = src._fout |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
272 self._ferr = src._ferr |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
273 self._fin = src._fin |
40634
5542bc9125c9
dispatch: pass around ui.fmsg channel
Yuya Nishihara <yuya@tcha.org>
parents:
40625
diff
changeset
|
274 self._fmsg = src._fmsg |
40594
840cd57cde32
ui: add config knob to redirect status messages to stderr (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40593
diff
changeset
|
275 self._fmsgout = src._fmsgout |
840cd57cde32
ui: add config knob to redirect status messages to stderr (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40593
diff
changeset
|
276 self._fmsgerr = src._fmsgerr |
38801
23a00bc90a3c
chgserver: do not send system() back to client if stdio redirected (issue5992)
Yuya Nishihara <yuya@tcha.org>
parents:
38762
diff
changeset
|
277 self._finoutredirected = src._finoutredirected |
40764
55b053af7196
ui: manage logger instances and event filtering by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40717
diff
changeset
|
278 self._loggers = src._loggers.copy() |
31012
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
279 self.pageractive = src.pageractive |
31046
9c827087df38
ui: rename neverpager to disablepager
Augie Fackler <augie@google.com>
parents:
31034
diff
changeset
|
280 self._disablepager = src._disablepager |
32890
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
281 self._tweaked = src._tweaked |
14612 | 282 |
8203 | 283 self._tcfg = src._tcfg.copy() |
284 self._ucfg = src._ucfg.copy() | |
285 self._ocfg = src._ocfg.copy() | |
8201
7cf2b987acd3
ui: trusted_users -> _trustusers, trusted_groups -> _trustgroups
Matt Mackall <mpm@selenic.com>
parents:
8200
diff
changeset
|
286 self._trustusers = src._trustusers.copy() |
7cf2b987acd3
ui: trusted_users -> _trustusers, trusted_groups -> _trustgroups
Matt Mackall <mpm@selenic.com>
parents:
8200
diff
changeset
|
287 self._trustgroups = src._trustgroups.copy() |
9887
38170eeed18c
ui: add environ property to access os.environ or wsgirequest.environ
Sune Foldager <cryo@cyanite.org>
parents:
9851
diff
changeset
|
288 self.environ = src.environ |
17048
15d4d475de9e
ui: add a variable to control whether hooks should be called
Idan Kamara <idankk86@gmail.com>
parents:
16383
diff
changeset
|
289 self.callhooks = src.callhooks |
47283
a671832a8e41
urlutil: move url "fixing" at the time of `ui.paths` initialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47244
diff
changeset
|
290 self._path_to_root = src._path_to_root |
29109
e9ce33c642e8
ui: add an instance flag to hold --insecure bit
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29096
diff
changeset
|
291 self.insecureconnections = src.insecureconnections |
31123
a185b903bda3
color: have the 'ui' object carry the '_colormode' directly
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31111
diff
changeset
|
292 self._colormode = src._colormode |
31130
268caf97c38f
color: move the dict with terminfo parameters on the ui object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31125
diff
changeset
|
293 self._terminfoparams = src._terminfoparams.copy() |
31132
f5131d4f512a
color: move 'styles' definition on the 'ui' object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31131
diff
changeset
|
294 self._styles = src._styles.copy() |
31123
a185b903bda3
color: have the 'ui' object carry the '_colormode' directly
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31111
diff
changeset
|
295 |
8143
507c49e297e1
ui: simplify init, kill dupconfig
Matt Mackall <mpm@selenic.com>
parents:
8142
diff
changeset
|
296 self.fixconfig() |
29378
fea71f66ebff
url: remember http password database in ui object
liscju <piotr.listkiewicz@gmail.com>
parents:
29366
diff
changeset
|
297 |
fea71f66ebff
url: remember http password database in ui object
liscju <piotr.listkiewicz@gmail.com>
parents:
29366
diff
changeset
|
298 self.httppasswordmgrdb = src.httppasswordmgrdb |
30996
e92daf156d5c
ui: provide a mechanism to track and log blocked time
Simon Farnsworth <simonfar@fb.com>
parents:
30965
diff
changeset
|
299 self._blockedtimes = src._blockedtimes |
8143
507c49e297e1
ui: simplify init, kill dupconfig
Matt Mackall <mpm@selenic.com>
parents:
8142
diff
changeset
|
300 else: |
40593
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
301 self._fout = procutil.stdout |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
302 self._ferr = procutil.stderr |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
303 self._fin = procutil.stdin |
40634
5542bc9125c9
dispatch: pass around ui.fmsg channel
Yuya Nishihara <yuya@tcha.org>
parents:
40625
diff
changeset
|
304 self._fmsg = None |
40594
840cd57cde32
ui: add config knob to redirect status messages to stderr (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40593
diff
changeset
|
305 self._fmsgout = self.fout # configurable |
840cd57cde32
ui: add config knob to redirect status messages to stderr (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40593
diff
changeset
|
306 self._fmsgerr = self.ferr # configurable |
38801
23a00bc90a3c
chgserver: do not send system() back to client if stdio redirected (issue5992)
Yuya Nishihara <yuya@tcha.org>
parents:
38762
diff
changeset
|
307 self._finoutredirected = False |
40764
55b053af7196
ui: manage logger instances and event filtering by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40717
diff
changeset
|
308 self._loggers = {} |
31012
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
309 self.pageractive = False |
31046
9c827087df38
ui: rename neverpager to disablepager
Augie Fackler <augie@google.com>
parents:
31034
diff
changeset
|
310 self._disablepager = False |
32890
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
311 self._tweaked = False |
14612 | 312 |
9887
38170eeed18c
ui: add environ property to access os.environ or wsgirequest.environ
Sune Foldager <cryo@cyanite.org>
parents:
9851
diff
changeset
|
313 # shared read-only environment |
30642
344e68882cd3
py3: replace os.environ with encoding.environ (part 4 of 5)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30623
diff
changeset
|
314 self.environ = encoding.environ |
8222
d30a21594812
more whitespace cleanup and some other style nits
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8220
diff
changeset
|
315 |
30965
8b83b626fb1e
ui: remove urllib2 from being imported early
Kyle Lippincott <spectral@google.com>
parents:
30952
diff
changeset
|
316 self.httppasswordmgrdb = httppasswordmgrdbproxy() |
30996
e92daf156d5c
ui: provide a mechanism to track and log blocked time
Simon Farnsworth <simonfar@fb.com>
parents:
30965
diff
changeset
|
317 self._blockedtimes = collections.defaultdict(int) |
29378
fea71f66ebff
url: remember http password database in ui object
liscju <piotr.listkiewicz@gmail.com>
parents:
29366
diff
changeset
|
318 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
319 allowed = self.configlist(b'experimental', b'exportableenviron') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
320 if b'*' in allowed: |
30832
da5fa0f13a41
ui: introduce an experimental dict of exportable environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents:
30814
diff
changeset
|
321 self._exportableenviron = self.environ |
da5fa0f13a41
ui: introduce an experimental dict of exportable environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents:
30814
diff
changeset
|
322 else: |
da5fa0f13a41
ui: introduce an experimental dict of exportable environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents:
30814
diff
changeset
|
323 self._exportableenviron = {} |
da5fa0f13a41
ui: introduce an experimental dict of exportable environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents:
30814
diff
changeset
|
324 for k in allowed: |
da5fa0f13a41
ui: introduce an experimental dict of exportable environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents:
30814
diff
changeset
|
325 if k in self.environ: |
da5fa0f13a41
ui: introduce an experimental dict of exportable environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents:
30814
diff
changeset
|
326 self._exportableenviron[k] = self.environ[k] |
da5fa0f13a41
ui: introduce an experimental dict of exportable environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents:
30814
diff
changeset
|
327 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
328 def _new_source(self) -> None: |
46661
a3dced4b7b04
config: track the "level" of a value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46659
diff
changeset
|
329 self._ocfg.new_source() |
a3dced4b7b04
config: track the "level" of a value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46659
diff
changeset
|
330 self._tcfg.new_source() |
a3dced4b7b04
config: track the "level" of a value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46659
diff
changeset
|
331 self._ucfg.new_source() |
a3dced4b7b04
config: track the "level" of a value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46659
diff
changeset
|
332 |
30564
d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30546
diff
changeset
|
333 @classmethod |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
334 def load(cls: Type[_Tui]) -> _Tui: |
30564
d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30546
diff
changeset
|
335 """Create a ui and load global and user configs""" |
d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30546
diff
changeset
|
336 u = cls() |
31690
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
31688
diff
changeset
|
337 # we always trust global config files and environment variables |
52457
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52447
diff
changeset
|
338 for _lvl, t, f in rcutil.rccomponents(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
339 if t == b'path': |
31688
00e569a2da97
rcutil: let rccomponents return different types of configs (API)
Jun Wu <quark@fb.com>
parents:
31687
diff
changeset
|
340 u.readconfig(f, trust=True) |
44033
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
44032
diff
changeset
|
341 elif t == b'resource': |
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
44032
diff
changeset
|
342 u.read_resource_config(f, trust=True) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
343 elif t == b'items': |
46661
a3dced4b7b04
config: track the "level" of a value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46659
diff
changeset
|
344 u._new_source() |
31690
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
31688
diff
changeset
|
345 sections = set() |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
31688
diff
changeset
|
346 for section, name, value, source in f: |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
31688
diff
changeset
|
347 # do not set u._ocfg |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
31688
diff
changeset
|
348 # XXX clean this up once immutable config object is a thing |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
31688
diff
changeset
|
349 u._tcfg.set(section, name, value, source) |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
31688
diff
changeset
|
350 u._ucfg.set(section, name, value, source) |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
31688
diff
changeset
|
351 sections.add(section) |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
31688
diff
changeset
|
352 for section in sections: |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
31688
diff
changeset
|
353 u.fixconfig(section=section) |
31688
00e569a2da97
rcutil: let rccomponents return different types of configs (API)
Jun Wu <quark@fb.com>
parents:
31687
diff
changeset
|
354 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
355 raise error.ProgrammingError(b'unknown rctype: %s' % t) |
32890
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
356 u._maybetweakdefaults() |
46661
a3dced4b7b04
config: track the "level" of a value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46659
diff
changeset
|
357 u._new_source() # anything after that is a different level |
30564
d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30546
diff
changeset
|
358 return u |
d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30546
diff
changeset
|
359 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
360 def _maybetweakdefaults(self) -> None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
361 if not self.configbool(b'ui', b'tweakdefaults'): |
32890
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
362 return |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
363 if self._tweaked or self.plain(b'tweakdefaults'): |
32890
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
364 return |
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
365 |
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
366 # Note: it is SUPER IMPORTANT that you set self._tweaked to |
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
367 # True *before* any calls to setconfig(), otherwise you'll get |
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
368 # infinite recursion between setconfig and this method. |
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
369 # |
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
370 # TODO: We should extract an inner method in setconfig() to |
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
371 # avoid this weirdness. |
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
372 self._tweaked = True |
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
373 tmpcfg = config.config() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
374 tmpcfg.parse(b'<tweakdefaults>', tweakrc) |
32890
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
375 for section in tmpcfg: |
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
376 for name, value in tmpcfg.items(section): |
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
377 if not self.hasconfig(section, name): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
378 self.setconfig(section, name, value, b"<tweakdefaults>") |
32890
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
379 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
380 def copy(self: _Tui) -> _Tui: |
8220
6e6ebeb52899
ui: ui.copy() now takes the ui class into account
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
8208
diff
changeset
|
381 return self.__class__(self) |
1839
876e4e6ad82b
Create local ui object per repository, so .hg/hgrc don't get mixed.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1637
diff
changeset
|
382 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
383 def resetstate(self) -> None: |
29366
d269e7db2f55
ui: provide official way to reset internal state per command
Yuya Nishihara <yuya@tcha.org>
parents:
29109
diff
changeset
|
384 """Clear internal state that shouldn't persist across commands""" |
d269e7db2f55
ui: provide official way to reset internal state per command
Yuya Nishihara <yuya@tcha.org>
parents:
29109
diff
changeset
|
385 if self._progbar: |
d269e7db2f55
ui: provide official way to reset internal state per command
Yuya Nishihara <yuya@tcha.org>
parents:
29109
diff
changeset
|
386 self._progbar.resetstate() # reset last-print time of progress bar |
30965
8b83b626fb1e
ui: remove urllib2 from being imported early
Kyle Lippincott <spectral@google.com>
parents:
30952
diff
changeset
|
387 self.httppasswordmgrdb = httppasswordmgrdbproxy() |
29366
d269e7db2f55
ui: provide official way to reset internal state per command
Yuya Nishihara <yuya@tcha.org>
parents:
29109
diff
changeset
|
388 |
30996
e92daf156d5c
ui: provide a mechanism to track and log blocked time
Simon Farnsworth <simonfar@fb.com>
parents:
30965
diff
changeset
|
389 @contextlib.contextmanager |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
390 def timeblockedsection(self, key: bytes): |
30998
fdecd24ca4dc
ui: log time spent blocked on stdio
Simon Farnsworth <simonfar@fb.com>
parents:
30996
diff
changeset
|
391 # this is open-coded below - search for timeblockedsection to find them |
30996
e92daf156d5c
ui: provide a mechanism to track and log blocked time
Simon Farnsworth <simonfar@fb.com>
parents:
30965
diff
changeset
|
392 starttime = util.timer() |
e92daf156d5c
ui: provide a mechanism to track and log blocked time
Simon Farnsworth <simonfar@fb.com>
parents:
30965
diff
changeset
|
393 try: |
e92daf156d5c
ui: provide a mechanism to track and log blocked time
Simon Farnsworth <simonfar@fb.com>
parents:
30965
diff
changeset
|
394 yield |
e92daf156d5c
ui: provide a mechanism to track and log blocked time
Simon Farnsworth <simonfar@fb.com>
parents:
30965
diff
changeset
|
395 finally: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
396 self._blockedtimes[key + b'_blocked'] += ( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
397 util.timer() - starttime |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
398 ) * 1000 |
29366
d269e7db2f55
ui: provide official way to reset internal state per command
Yuya Nishihara <yuya@tcha.org>
parents:
29109
diff
changeset
|
399 |
38528
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
400 @contextlib.contextmanager |
41079
8ecb17b7f432
procutil: correct spelling of uninterruptable -> uninterruptible
Kyle Lippincott <spectral@google.com>
parents:
41066
diff
changeset
|
401 def uninterruptible(self): |
38528
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
402 """Mark an operation as unsafe. |
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
403 |
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
404 Most operations on a repository are safe to interrupt, but a |
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
405 few are risky (for example repair.strip). This context manager |
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
406 lets you advise Mercurial that something risky is happening so |
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
407 that control-C etc can be blocked if desired. |
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
408 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
409 enabled = self.configbool(b'experimental', b'nointerrupt') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
410 if enabled and self.configbool( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
411 b'experimental', b'nointerrupt-interactiveonly' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
412 ): |
38528
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
413 enabled = self.interactive() |
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
414 if self._uninterruptible or not enabled: |
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
415 # if nointerrupt support is turned off, the process isn't |
41079
8ecb17b7f432
procutil: correct spelling of uninterruptable -> uninterruptible
Kyle Lippincott <spectral@google.com>
parents:
41066
diff
changeset
|
416 # interactive, or we're already in an uninterruptible |
38528
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
417 # block, do nothing. |
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
418 yield |
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
419 return |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
420 |
38528
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
421 def warn(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
422 self.warn(_(b"shutting down cleanly\n")) |
38528
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
423 self.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
424 _(b"press ^C again to terminate immediately (dangerous)\n") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
425 ) |
38528
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
426 return True |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
427 |
41079
8ecb17b7f432
procutil: correct spelling of uninterruptable -> uninterruptible
Kyle Lippincott <spectral@google.com>
parents:
41066
diff
changeset
|
428 with procutil.uninterruptible(warn): |
38528
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
429 try: |
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
430 self._uninterruptible = True |
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
431 yield |
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
432 finally: |
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
433 self._uninterruptible = False |
313a940d49a3
ui: add an uninterruptable context manager that can block SIGINT
Augie Fackler <augie@google.com>
parents:
38351
diff
changeset
|
434 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
435 def formatter(self, topic: bytes, opts): |
32605
012e0da5b759
formatter: add option to redirect output to file object
Yuya Nishihara <yuya@tcha.org>
parents:
32496
diff
changeset
|
436 return formatter.formatter(self, self, topic, opts) |
16135 | 437 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
438 def _trusted(self, fp, f: bytes) -> bool: |
3677
1a0fa3914c46
Avoid looking up usernames if the current user owns the .hgrc file
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3676
diff
changeset
|
439 st = util.fstat(fp) |
8657
3fa92c618624
posix: do not use fstat in isowner
Martin Geisler <mg@lazybytes.net>
parents:
8656
diff
changeset
|
440 if util.isowner(st): |
3677
1a0fa3914c46
Avoid looking up usernames if the current user owns the .hgrc file
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3676
diff
changeset
|
441 return True |
8141
e40b629bedd1
ui: cleanup _is_trusted a bit
Matt Mackall <mpm@selenic.com>
parents:
8140
diff
changeset
|
442 |
8201
7cf2b987acd3
ui: trusted_users -> _trustusers, trusted_groups -> _trustgroups
Matt Mackall <mpm@selenic.com>
parents:
8200
diff
changeset
|
443 tusers, tgroups = self._trustusers, self._trustgroups |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
444 if b'*' in tusers or b'*' in tgroups: |
8141
e40b629bedd1
ui: cleanup _is_trusted a bit
Matt Mackall <mpm@selenic.com>
parents:
8140
diff
changeset
|
445 return True |
e40b629bedd1
ui: cleanup _is_trusted a bit
Matt Mackall <mpm@selenic.com>
parents:
8140
diff
changeset
|
446 |
e40b629bedd1
ui: cleanup _is_trusted a bit
Matt Mackall <mpm@selenic.com>
parents:
8140
diff
changeset
|
447 user = util.username(st.st_uid) |
e40b629bedd1
ui: cleanup _is_trusted a bit
Matt Mackall <mpm@selenic.com>
parents:
8140
diff
changeset
|
448 group = util.groupname(st.st_gid) |
e40b629bedd1
ui: cleanup _is_trusted a bit
Matt Mackall <mpm@selenic.com>
parents:
8140
diff
changeset
|
449 if user in tusers or group in tgroups or user == util.username(): |
e40b629bedd1
ui: cleanup _is_trusted a bit
Matt Mackall <mpm@selenic.com>
parents:
8140
diff
changeset
|
450 return True |
e40b629bedd1
ui: cleanup _is_trusted a bit
Matt Mackall <mpm@selenic.com>
parents:
8140
diff
changeset
|
451 |
8204 | 452 if self._reportuntrusted: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
453 self.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
454 _( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
455 b'not trusting file %s from untrusted ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
456 b'user %s, group %s\n' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
457 ) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
458 % (f, user, group) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
459 ) |
8141
e40b629bedd1
ui: cleanup _is_trusted a bit
Matt Mackall <mpm@selenic.com>
parents:
8140
diff
changeset
|
460 return False |
3551
3b07e223534b
Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3489
diff
changeset
|
461 |
44032
5ac0e6f19eb4
ui: refactor `readconfig()` into a form that can consume resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
44023
diff
changeset
|
462 def read_resource_config( |
5ac0e6f19eb4
ui: refactor `readconfig()` into a form that can consume resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
44023
diff
changeset
|
463 self, name, root=None, trust=False, sections=None, remap=None |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
464 ) -> None: |
44032
5ac0e6f19eb4
ui: refactor `readconfig()` into a form that can consume resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
44023
diff
changeset
|
465 try: |
5ac0e6f19eb4
ui: refactor `readconfig()` into a form that can consume resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
44023
diff
changeset
|
466 fp = resourceutil.open_resource(name[0], name[1]) |
52665
24ee91ba9aa8
pyupgrade: drop usage of py3 aliases for `OSError`
Matt Harbison <matt_harbison@yahoo.com>
parents:
52607
diff
changeset
|
467 except OSError: |
44032
5ac0e6f19eb4
ui: refactor `readconfig()` into a form that can consume resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
44023
diff
changeset
|
468 if not sections: # ignore unless we were looking for something |
5ac0e6f19eb4
ui: refactor `readconfig()` into a form that can consume resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
44023
diff
changeset
|
469 return |
5ac0e6f19eb4
ui: refactor `readconfig()` into a form that can consume resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
44023
diff
changeset
|
470 raise |
5ac0e6f19eb4
ui: refactor `readconfig()` into a form that can consume resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
44023
diff
changeset
|
471 |
5ac0e6f19eb4
ui: refactor `readconfig()` into a form that can consume resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
44023
diff
changeset
|
472 self._readconfig( |
5ac0e6f19eb4
ui: refactor `readconfig()` into a form that can consume resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
44023
diff
changeset
|
473 b'resource:%s.%s' % name, fp, root, trust, sections, remap |
5ac0e6f19eb4
ui: refactor `readconfig()` into a form that can consume resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
44023
diff
changeset
|
474 ) |
5ac0e6f19eb4
ui: refactor `readconfig()` into a form that can consume resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
44023
diff
changeset
|
475 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
476 def readconfig( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
477 self, filename, root=None, trust=False, sections=None, remap=None |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
478 ) -> None: |
8142
912bfef12ba6
ui: fold readsections into readconfig
Matt Mackall <mpm@selenic.com>
parents:
8141
diff
changeset
|
479 try: |
43554
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43377
diff
changeset
|
480 fp = open(filename, 'rb') |
52665
24ee91ba9aa8
pyupgrade: drop usage of py3 aliases for `OSError`
Matt Harbison <matt_harbison@yahoo.com>
parents:
52607
diff
changeset
|
481 except OSError: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
482 if not sections: # ignore unless we were looking for something |
8142
912bfef12ba6
ui: fold readsections into readconfig
Matt Mackall <mpm@selenic.com>
parents:
8141
diff
changeset
|
483 return |
912bfef12ba6
ui: fold readsections into readconfig
Matt Mackall <mpm@selenic.com>
parents:
8141
diff
changeset
|
484 raise |
8139 | 485 |
44032
5ac0e6f19eb4
ui: refactor `readconfig()` into a form that can consume resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
44023
diff
changeset
|
486 self._readconfig(filename, fp, root, trust, sections, remap) |
5ac0e6f19eb4
ui: refactor `readconfig()` into a form that can consume resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
44023
diff
changeset
|
487 |
5ac0e6f19eb4
ui: refactor `readconfig()` into a form that can consume resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
44023
diff
changeset
|
488 def _readconfig( |
5ac0e6f19eb4
ui: refactor `readconfig()` into a form that can consume resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
44023
diff
changeset
|
489 self, filename, fp, root=None, trust=False, sections=None, remap=None |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
490 ) -> None: |
43916
c41ed5d4f770
config: close file even if we fail to read it
Martin von Zweigbergk <martinvonz@google.com>
parents:
43915
diff
changeset
|
491 with fp: |
c41ed5d4f770
config: close file even if we fail to read it
Martin von Zweigbergk <martinvonz@google.com>
parents:
43915
diff
changeset
|
492 cfg = config.config() |
c41ed5d4f770
config: close file even if we fail to read it
Martin von Zweigbergk <martinvonz@google.com>
parents:
43915
diff
changeset
|
493 trusted = sections or trust or self._trusted(fp, filename) |
3552
9b52239dc740
save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3551
diff
changeset
|
494 |
43916
c41ed5d4f770
config: close file even if we fail to read it
Martin von Zweigbergk <martinvonz@google.com>
parents:
43915
diff
changeset
|
495 try: |
c41ed5d4f770
config: close file even if we fail to read it
Martin von Zweigbergk <martinvonz@google.com>
parents:
43915
diff
changeset
|
496 cfg.read(filename, fp, sections=sections, remap=remap) |
45909
9dc1351d0b5f
errors: raise ConfigError on failure to parse config file
Martin von Zweigbergk <martinvonz@google.com>
parents:
45904
diff
changeset
|
497 except error.ConfigError as inst: |
43916
c41ed5d4f770
config: close file even if we fail to read it
Martin von Zweigbergk <martinvonz@google.com>
parents:
43915
diff
changeset
|
498 if trusted: |
c41ed5d4f770
config: close file even if we fail to read it
Martin von Zweigbergk <martinvonz@google.com>
parents:
43915
diff
changeset
|
499 raise |
45904
e5a0efd26f7a
config: clean up message about ignored untrusted config
Martin von Zweigbergk <martinvonz@google.com>
parents:
45892
diff
changeset
|
500 self.warn( |
e5a0efd26f7a
config: clean up message about ignored untrusted config
Martin von Zweigbergk <martinvonz@google.com>
parents:
45892
diff
changeset
|
501 _(b'ignored %s: %s\n') % (inst.location, inst.message) |
e5a0efd26f7a
config: clean up message about ignored untrusted config
Martin von Zweigbergk <martinvonz@google.com>
parents:
45892
diff
changeset
|
502 ) |
3552
9b52239dc740
save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3551
diff
changeset
|
503 |
44126
e2278581b1c6
config: add a function to insert non-file based, but overridable settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
44033
diff
changeset
|
504 self._applyconfig(cfg, trusted, root) |
e2278581b1c6
config: add a function to insert non-file based, but overridable settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
44033
diff
changeset
|
505 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
506 def applyconfig( |
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
507 self, configitems: _ConfigItems, source=b"", root=None |
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
508 ) -> None: |
44126
e2278581b1c6
config: add a function to insert non-file based, but overridable settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
44033
diff
changeset
|
509 """Add configitems from a non-file source. Unlike with ``setconfig()``, |
e2278581b1c6
config: add a function to insert non-file based, but overridable settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
44033
diff
changeset
|
510 they can be overridden by subsequent config file reads. The items are |
e2278581b1c6
config: add a function to insert non-file based, but overridable settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
44033
diff
changeset
|
511 in the same format as ``configoverride()``, namely a dict of the |
e2278581b1c6
config: add a function to insert non-file based, but overridable settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
44033
diff
changeset
|
512 following structures: {(section, name) : value} |
e2278581b1c6
config: add a function to insert non-file based, but overridable settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
44033
diff
changeset
|
513 |
e2278581b1c6
config: add a function to insert non-file based, but overridable settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
44033
diff
changeset
|
514 Typically this is used by extensions that inject themselves into the |
e2278581b1c6
config: add a function to insert non-file based, but overridable settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
44033
diff
changeset
|
515 config file load procedure by monkeypatching ``localrepo.loadhgrc()``. |
e2278581b1c6
config: add a function to insert non-file based, but overridable settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
44033
diff
changeset
|
516 """ |
e2278581b1c6
config: add a function to insert non-file based, but overridable settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
44033
diff
changeset
|
517 cfg = config.config() |
e2278581b1c6
config: add a function to insert non-file based, but overridable settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
44033
diff
changeset
|
518 |
e2278581b1c6
config: add a function to insert non-file based, but overridable settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
44033
diff
changeset
|
519 for (section, name), value in configitems.items(): |
e2278581b1c6
config: add a function to insert non-file based, but overridable settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
44033
diff
changeset
|
520 cfg.set(section, name, value, source) |
e2278581b1c6
config: add a function to insert non-file based, but overridable settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
44033
diff
changeset
|
521 |
e2278581b1c6
config: add a function to insert non-file based, but overridable settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
44033
diff
changeset
|
522 self._applyconfig(cfg, True, root) |
e2278581b1c6
config: add a function to insert non-file based, but overridable settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
44033
diff
changeset
|
523 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
524 def _applyconfig(self, cfg, trusted, root) -> None: |
10455
40dfd46d098f
ui: add HGPLAIN environment variable for easier scripting
Brodie Rao <me+hg@dackz.net>
parents:
10426
diff
changeset
|
525 if self.plain(): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
526 for k in ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
527 b'debug', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
528 b'fallbackencoding', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
529 b'quiet', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
530 b'slash', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
531 b'logtemplate', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
532 b'message-output', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
533 b'statuscopies', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
534 b'style', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
535 b'traceback', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
536 b'verbose', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
537 ): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
538 if k in cfg[b'ui']: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
539 del cfg[b'ui'][k] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
540 for k, v in cfg.items(b'defaults'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
541 del cfg[b'defaults'][k] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
542 for k, v in cfg.items(b'commands'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
543 del cfg[b'commands'][k] |
45788
ed84a4d48910
config: add a new [command-templates] section for templates defined by hg
Martin von Zweigbergk <martinvonz@google.com>
parents:
45062
diff
changeset
|
544 for k, v in cfg.items(b'command-templates'): |
ed84a4d48910
config: add a new [command-templates] section for templates defined by hg
Martin von Zweigbergk <martinvonz@google.com>
parents:
45062
diff
changeset
|
545 del cfg[b'command-templates'][k] |
14373
a599431b0ab6
ui: enable alias exception when reading config in plain mode
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
14372
diff
changeset
|
546 # Don't remove aliases from the configuration if in the exceptionlist |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
547 if self.plain(b'alias'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
548 for k, v in cfg.items(b'alias'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
549 del cfg[b'alias'][k] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
550 if self.plain(b'revsetalias'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
551 for k, v in cfg.items(b'revsetalias'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
552 del cfg[b'revsetalias'][k] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
553 if self.plain(b'templatealias'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
554 for k, v in cfg.items(b'templatealias'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
555 del cfg[b'templatealias'][k] |
10455
40dfd46d098f
ui: add HGPLAIN environment variable for easier scripting
Brodie Rao <me+hg@dackz.net>
parents:
10426
diff
changeset
|
556 |
8142
912bfef12ba6
ui: fold readsections into readconfig
Matt Mackall <mpm@selenic.com>
parents:
8141
diff
changeset
|
557 if trusted: |
8203 | 558 self._tcfg.update(cfg) |
559 self._tcfg.update(self._ocfg) | |
560 self._ucfg.update(cfg) | |
561 self._ucfg.update(self._ocfg) | |
8139 | 562 |
3347
bce7c1b4c1c8
ui.py: normalize settings every time the configuration changes
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3346
diff
changeset
|
563 if root is None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
564 root = os.path.expanduser(b'~') |
3347
bce7c1b4c1c8
ui.py: normalize settings every time the configuration changes
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3346
diff
changeset
|
565 self.fixconfig(root=root) |
3014
01454af644b8
load extensions only after the ui object has been completely initialized
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3013
diff
changeset
|
566 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
567 def fixconfig(self, root=None, section=None) -> None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
568 if section in (None, b'paths'): |
12764
ad2506f097d3
ui: only fix config if the relevant section has changed
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12689
diff
changeset
|
569 # expand vars and ~ |
ad2506f097d3
ui: only fix config if the relevant section has changed
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12689
diff
changeset
|
570 # translate paths relative to root (or home) into absolute paths |
39823
24e493ec2229
py3: rename pycompat.getcwd() to encoding.getcwd() (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
39678
diff
changeset
|
571 root = root or encoding.getcwd() |
12764
ad2506f097d3
ui: only fix config if the relevant section has changed
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12689
diff
changeset
|
572 for c in self._tcfg, self._ucfg, self._ocfg: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
573 for n, p in c.items(b'paths'): |
47283
a671832a8e41
urlutil: move url "fixing" at the time of `ui.paths` initialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47244
diff
changeset
|
574 old_p = p |
a671832a8e41
urlutil: move url "fixing" at the time of `ui.paths` initialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47244
diff
changeset
|
575 s = self.configsource(b'paths', n) or b'none' |
a671832a8e41
urlutil: move url "fixing" at the time of `ui.paths` initialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47244
diff
changeset
|
576 root_key = (n, p, s) |
a671832a8e41
urlutil: move url "fixing" at the time of `ui.paths` initialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47244
diff
changeset
|
577 if root_key not in self._path_to_root: |
a671832a8e41
urlutil: move url "fixing" at the time of `ui.paths` initialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47244
diff
changeset
|
578 self._path_to_root[root_key] = root |
29412
b62bce819d0c
ui: don't fixup [paths] sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29378
diff
changeset
|
579 # Ignore sub-options. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
580 if b':' in n: |
29412
b62bce819d0c
ui: don't fixup [paths] sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29378
diff
changeset
|
581 continue |
12764
ad2506f097d3
ui: only fix config if the relevant section has changed
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12689
diff
changeset
|
582 if not p: |
ad2506f097d3
ui: only fix config if the relevant section has changed
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12689
diff
changeset
|
583 continue |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
584 if b'%%' in p: |
47283
a671832a8e41
urlutil: move url "fixing" at the time of `ui.paths` initialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47244
diff
changeset
|
585 if s is None: |
a671832a8e41
urlutil: move url "fixing" at the time of `ui.paths` initialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47244
diff
changeset
|
586 s = 'none' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
587 self.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
588 _(b"(deprecated '%%' in path %s=%s from %s)\n") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
589 % (n, p, s) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
590 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
591 p = p.replace(b'%%', b'%') |
47283
a671832a8e41
urlutil: move url "fixing" at the time of `ui.paths` initialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47244
diff
changeset
|
592 if p != old_p: |
a671832a8e41
urlutil: move url "fixing" at the time of `ui.paths` initialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47244
diff
changeset
|
593 c.alter(b"paths", n, p) |
3347
bce7c1b4c1c8
ui.py: normalize settings every time the configuration changes
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3346
diff
changeset
|
594 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
595 if section in (None, b'ui'): |
12764
ad2506f097d3
ui: only fix config if the relevant section has changed
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12689
diff
changeset
|
596 # update ui options |
40594
840cd57cde32
ui: add config knob to redirect status messages to stderr (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40593
diff
changeset
|
597 self._fmsgout, self._fmsgerr = _selectmsgdests(self) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
598 self.debugflag = self.configbool(b'ui', b'debug') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
599 self.verbose = self.debugflag or self.configbool(b'ui', b'verbose') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
600 self.quiet = not self.debugflag and self.configbool(b'ui', b'quiet') |
12764
ad2506f097d3
ui: only fix config if the relevant section has changed
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12689
diff
changeset
|
601 if self.verbose and self.quiet: |
ad2506f097d3
ui: only fix config if the relevant section has changed
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12689
diff
changeset
|
602 self.quiet = self.verbose = False |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
603 self._reportuntrusted = self.debugflag or self.configbool( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
604 b"ui", b"report_untrusted" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
605 ) |
45035
24b1a8eb73aa
ui: add option to timestamp status and diagnostic messages
Joerg Sonnenberger <joerg@bec.de>
parents:
45012
diff
changeset
|
606 self.showtimestamp = self.configbool(b'ui', b'timestamp-output') |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
607 self.tracebackflag = self.configbool(b'ui', b'traceback') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
608 self.logblockedtimes = self.configbool(b'ui', b'logblockedtimes') |
3350
ab900698b832
update ui.quiet/verbose/debug/interactive every time the config changes
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3349
diff
changeset
|
609 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
610 if section in (None, b'trusted'): |
12764
ad2506f097d3
ui: only fix config if the relevant section has changed
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12689
diff
changeset
|
611 # update trust information |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
612 self._trustusers.update(self.configlist(b'trusted', b'users')) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
613 self._trustgroups.update(self.configlist(b'trusted', b'groups')) |
3551
3b07e223534b
Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3489
diff
changeset
|
614 |
41004
ab92e2111408
ui: install logger that sends debug.extensions messages to stderr
Yuya Nishihara <yuya@tcha.org>
parents:
40795
diff
changeset
|
615 if section in (None, b'devel', b'ui') and self.debugflag: |
ab92e2111408
ui: install logger that sends debug.extensions messages to stderr
Yuya Nishihara <yuya@tcha.org>
parents:
40795
diff
changeset
|
616 tracked = set() |
ab92e2111408
ui: install logger that sends debug.extensions messages to stderr
Yuya Nishihara <yuya@tcha.org>
parents:
40795
diff
changeset
|
617 if self.configbool(b'devel', b'debug.extensions'): |
ab92e2111408
ui: install logger that sends debug.extensions messages to stderr
Yuya Nishihara <yuya@tcha.org>
parents:
40795
diff
changeset
|
618 tracked.add(b'extension') |
ab92e2111408
ui: install logger that sends debug.extensions messages to stderr
Yuya Nishihara <yuya@tcha.org>
parents:
40795
diff
changeset
|
619 if tracked: |
ab92e2111408
ui: install logger that sends debug.extensions messages to stderr
Yuya Nishihara <yuya@tcha.org>
parents:
40795
diff
changeset
|
620 logger = loggingutil.fileobjectlogger(self._ferr, tracked) |
ab92e2111408
ui: install logger that sends debug.extensions messages to stderr
Yuya Nishihara <yuya@tcha.org>
parents:
40795
diff
changeset
|
621 self.setlogger(b'debug', logger) |
ab92e2111408
ui: install logger that sends debug.extensions messages to stderr
Yuya Nishihara <yuya@tcha.org>
parents:
40795
diff
changeset
|
622 |
15919
69e792cf7851
config: have a way to backup and restore value in config
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
15407
diff
changeset
|
623 def backupconfig(self, section, item): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
624 return ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
625 self._ocfg.backup(section, item), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
626 self._tcfg.backup(section, item), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
627 self._ucfg.backup(section, item), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
628 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
629 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
630 def restoreconfig(self, data) -> None: |
15919
69e792cf7851
config: have a way to backup and restore value in config
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
15407
diff
changeset
|
631 self._ocfg.restore(data[0]) |
69e792cf7851
config: have a way to backup and restore value in config
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
15407
diff
changeset
|
632 self._tcfg.restore(data[1]) |
69e792cf7851
config: have a way to backup and restore value in config
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
15407
diff
changeset
|
633 self._ucfg.restore(data[2]) |
69e792cf7851
config: have a way to backup and restore value in config
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
15407
diff
changeset
|
634 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
635 def setconfig(self, section, name, value, source=b'') -> None: |
20787
be179da10d5f
config: backout 77f1f206e135 - 743daa601445 removed the only use of overlay
Mads Kiilerich <madski@unity3d.com>
parents:
20606
diff
changeset
|
636 for cfg in (self._ocfg, self._tcfg, self._ucfg): |
20788
f144928dd058
config: give a useful hint of source for the most common command line settings
Mads Kiilerich <madski@unity3d.com>
parents:
20787
diff
changeset
|
637 cfg.set(section, name, value, source) |
12764
ad2506f097d3
ui: only fix config if the relevant section has changed
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12689
diff
changeset
|
638 self.fixconfig(section=section) |
32890
9fcb6df413c9
ui: add support for a tweakdefaults knob
Augie Fackler <augie@google.com>
parents:
32605
diff
changeset
|
639 self._maybetweakdefaults() |
960 | 640 |
8199 | 641 def _data(self, untrusted): |
8203 | 642 return untrusted and self._ucfg or self._tcfg |
3552
9b52239dc740
save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3551
diff
changeset
|
643 |
8182
b97abc7c1135
showconfig: show source file and line with --debug
Matt Mackall <mpm@selenic.com>
parents:
8175
diff
changeset
|
644 def configsource(self, section, name, untrusted=False): |
30623
201b44c8875c
ui: do not translate empty configsource() to 'none' (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30574
diff
changeset
|
645 return self._data(untrusted).source(section, name) |
8182
b97abc7c1135
showconfig: show source file and line with --debug
Matt Mackall <mpm@selenic.com>
parents:
8175
diff
changeset
|
646 |
32976
4a3f1d362e5f
config: explicitly track the use of the standard default value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32890
diff
changeset
|
647 def config(self, section, name, default=_unset, untrusted=False): |
33070
1aa05203f7f6
config: extract the core config logic into a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33005
diff
changeset
|
648 """return the plain string version of a config""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
649 value = self._config( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
650 section, name, default=default, untrusted=untrusted |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
651 ) |
33070
1aa05203f7f6
config: extract the core config logic into a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33005
diff
changeset
|
652 if value is _unset: |
1aa05203f7f6
config: extract the core config logic into a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33005
diff
changeset
|
653 return None |
1aa05203f7f6
config: extract the core config logic into a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33005
diff
changeset
|
654 return value |
1aa05203f7f6
config: extract the core config logic into a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33005
diff
changeset
|
655 |
1aa05203f7f6
config: extract the core config logic into a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33005
diff
changeset
|
656 def _config(self, section, name, default=_unset, untrusted=False): |
34947
ff2110eadbfa
configitems: relax warning about unwanted default value
Yuya Nishihara <yuya@tcha.org>
parents:
34882
diff
changeset
|
657 value = itemdefault = default |
33329
e714159860fd
configitems: add alias support in config
David Demelier <demelier.david@gmail.com>
parents:
33156
diff
changeset
|
658 item = self._knownconfig.get(section, {}).get(name) |
e714159860fd
configitems: add alias support in config
David Demelier <demelier.david@gmail.com>
parents:
33156
diff
changeset
|
659 alternates = [(section, name)] |
e714159860fd
configitems: add alias support in config
David Demelier <demelier.david@gmail.com>
parents:
33156
diff
changeset
|
660 |
50804
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50487
diff
changeset
|
661 if item is not None and item.in_core_extension is not None: |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50487
diff
changeset
|
662 # Only return the default for an in-core extension item if said |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50487
diff
changeset
|
663 # extension is enabled |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50487
diff
changeset
|
664 if item.in_core_extension in extensions.extensions(self): |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50487
diff
changeset
|
665 item = None |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50487
diff
changeset
|
666 |
33329
e714159860fd
configitems: add alias support in config
David Demelier <demelier.david@gmail.com>
parents:
33156
diff
changeset
|
667 if item is not None: |
e714159860fd
configitems: add alias support in config
David Demelier <demelier.david@gmail.com>
parents:
33156
diff
changeset
|
668 alternates.extend(item.alias) |
34947
ff2110eadbfa
configitems: relax warning about unwanted default value
Yuya Nishihara <yuya@tcha.org>
parents:
34882
diff
changeset
|
669 if callable(item.default): |
ff2110eadbfa
configitems: relax warning about unwanted default value
Yuya Nishihara <yuya@tcha.org>
parents:
34882
diff
changeset
|
670 itemdefault = item.default() |
ff2110eadbfa
configitems: relax warning about unwanted default value
Yuya Nishihara <yuya@tcha.org>
parents:
34882
diff
changeset
|
671 else: |
ff2110eadbfa
configitems: relax warning about unwanted default value
Yuya Nishihara <yuya@tcha.org>
parents:
34882
diff
changeset
|
672 itemdefault = item.default |
34858
85a2db47ad50
configitems: adds a developer warning when accessing undeclared configuration
Boris Feld <boris.feld@octobus.net>
parents:
34849
diff
changeset
|
673 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
674 msg = b"accessing unregistered config item: '%s.%s'" |
34858
85a2db47ad50
configitems: adds a developer warning when accessing undeclared configuration
Boris Feld <boris.feld@octobus.net>
parents:
34849
diff
changeset
|
675 msg %= (section, name) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
676 self.develwarn(msg, 2, b'warn-config-unknown') |
33329
e714159860fd
configitems: add alias support in config
David Demelier <demelier.david@gmail.com>
parents:
33156
diff
changeset
|
677 |
e714159860fd
configitems: add alias support in config
David Demelier <demelier.david@gmail.com>
parents:
33156
diff
changeset
|
678 if default is _unset: |
e714159860fd
configitems: add alias support in config
David Demelier <demelier.david@gmail.com>
parents:
33156
diff
changeset
|
679 if item is None: |
e714159860fd
configitems: add alias support in config
David Demelier <demelier.david@gmail.com>
parents:
33156
diff
changeset
|
680 value = default |
33471
d74141ccfd8b
configitems: handle case were the default value is not static
Boris Feld <boris.feld@octobus.net>
parents:
33329
diff
changeset
|
681 elif item.default is configitems.dynamicdefault: |
d74141ccfd8b
configitems: handle case were the default value is not static
Boris Feld <boris.feld@octobus.net>
parents:
33329
diff
changeset
|
682 value = None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
683 msg = b"config item requires an explicit default value: '%s.%s'" |
33471
d74141ccfd8b
configitems: handle case were the default value is not static
Boris Feld <boris.feld@octobus.net>
parents:
33329
diff
changeset
|
684 msg %= (section, name) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
685 self.develwarn(msg, 2, b'warn-config-default') |
33329
e714159860fd
configitems: add alias support in config
David Demelier <demelier.david@gmail.com>
parents:
33156
diff
changeset
|
686 else: |
34947
ff2110eadbfa
configitems: relax warning about unwanted default value
Yuya Nishihara <yuya@tcha.org>
parents:
34882
diff
changeset
|
687 value = itemdefault |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
688 elif ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
689 item is not None |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
690 and item.default is not configitems.dynamicdefault |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
691 and default != itemdefault |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
692 ): |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
693 msg = ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
694 b"specifying a mismatched default value for a registered " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
695 b"config item: '%s.%s' '%s'" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
696 ) |
36164
8f5c7f906f9b
ui: use pycompat.bytestr() to get a bytes-repr of config default
Augie Fackler <augie@google.com>
parents:
36000
diff
changeset
|
697 msg %= (section, name, pycompat.bytestr(default)) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
698 self.develwarn(msg, 2, b'warn-config-default') |
33005
149b68224b08
configitems: issue a devel warning when overriding default config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33003
diff
changeset
|
699 |
46662
b91a695b3b08
config: use level to properly deal with value priority
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46661
diff
changeset
|
700 candidates = [] |
b91a695b3b08
config: use level to properly deal with value priority
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46661
diff
changeset
|
701 config = self._data(untrusted) |
33329
e714159860fd
configitems: add alias support in config
David Demelier <demelier.david@gmail.com>
parents:
33156
diff
changeset
|
702 for s, n in alternates: |
46662
b91a695b3b08
config: use level to properly deal with value priority
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46661
diff
changeset
|
703 candidate = config.get(s, n, None) |
33070
1aa05203f7f6
config: extract the core config logic into a private method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33005
diff
changeset
|
704 if candidate is not None: |
46662
b91a695b3b08
config: use level to properly deal with value priority
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46661
diff
changeset
|
705 candidates.append((s, n, candidate)) |
b91a695b3b08
config: use level to properly deal with value priority
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46661
diff
changeset
|
706 if candidates: |
b91a695b3b08
config: use level to properly deal with value priority
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46661
diff
changeset
|
707 |
b91a695b3b08
config: use level to properly deal with value priority
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46661
diff
changeset
|
708 def level(x): |
b91a695b3b08
config: use level to properly deal with value priority
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46661
diff
changeset
|
709 return config.level(x[0], x[1]) |
b91a695b3b08
config: use level to properly deal with value priority
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46661
diff
changeset
|
710 |
b91a695b3b08
config: use level to properly deal with value priority
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46661
diff
changeset
|
711 value = max(candidates, key=level)[2] |
15035
cc669e4fec95
ui: allow alternatives for config options
Matt Mackall <mpm@selenic.com>
parents:
15002
diff
changeset
|
712 |
8204 | 713 if self.debugflag and not untrusted and self._reportuntrusted: |
33329
e714159860fd
configitems: add alias support in config
David Demelier <demelier.david@gmail.com>
parents:
33156
diff
changeset
|
714 for s, n in alternates: |
e714159860fd
configitems: add alias support in config
David Demelier <demelier.david@gmail.com>
parents:
33156
diff
changeset
|
715 uvalue = self._ucfg.get(s, n) |
19536
ab3cf67740d6
ui.config: fix bug in config alternatives from cc669e4fec95
Augie Fackler <durin42@gmail.com>
parents:
19226
diff
changeset
|
716 if uvalue is not None and uvalue != value: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
717 self.debug( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
718 b"ignoring untrusted configuration option " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
719 b"%s.%s = %s\n" % (s, n, uvalue) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
720 ) |
3552
9b52239dc740
save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3551
diff
changeset
|
721 return value |
3341
a7cec14c9b40
ui.py: move common code out of config and configbool
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3340
diff
changeset
|
722 |
46267
b9b37418ac7e
ui: add a "config_default" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46034
diff
changeset
|
723 def config_default(self, section, name): |
b9b37418ac7e
ui: add a "config_default" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46034
diff
changeset
|
724 """return the default value for a config option |
b9b37418ac7e
ui: add a "config_default" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46034
diff
changeset
|
725 |
b9b37418ac7e
ui: add a "config_default" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46034
diff
changeset
|
726 The default is returned "raw", for example if it is a callable, the |
b9b37418ac7e
ui: add a "config_default" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46034
diff
changeset
|
727 callable was not called. |
b9b37418ac7e
ui: add a "config_default" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46034
diff
changeset
|
728 """ |
b9b37418ac7e
ui: add a "config_default" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46034
diff
changeset
|
729 item = self._knownconfig.get(section, {}).get(name) |
b9b37418ac7e
ui: add a "config_default" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46034
diff
changeset
|
730 |
b9b37418ac7e
ui: add a "config_default" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46034
diff
changeset
|
731 if item is None: |
b9b37418ac7e
ui: add a "config_default" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46034
diff
changeset
|
732 raise KeyError((section, name)) |
b9b37418ac7e
ui: add a "config_default" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46034
diff
changeset
|
733 return item.default |
b9b37418ac7e
ui: add a "config_default" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46034
diff
changeset
|
734 |
32985
cd2fd1765654
config: use the new '_unset' value for 'configsuboptions'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32984
diff
changeset
|
735 def configsuboptions(self, section, name, default=_unset, untrusted=False): |
27252
dccbebcff075
ui: add method to return option and all sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27153
diff
changeset
|
736 """Get a config option and all sub-options. |
dccbebcff075
ui: add method to return option and all sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27153
diff
changeset
|
737 |
dccbebcff075
ui: add method to return option and all sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27153
diff
changeset
|
738 Some config options have sub-options that are declared with the |
dccbebcff075
ui: add method to return option and all sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27153
diff
changeset
|
739 format "key:opt = value". This method is used to return the main |
dccbebcff075
ui: add method to return option and all sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27153
diff
changeset
|
740 option and all its declared sub-options. |
dccbebcff075
ui: add method to return option and all sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27153
diff
changeset
|
741 |
dccbebcff075
ui: add method to return option and all sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27153
diff
changeset
|
742 Returns a 2-tuple of ``(option, sub-options)``, where `sub-options`` |
dccbebcff075
ui: add method to return option and all sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27153
diff
changeset
|
743 is a dict of defined sub-options where keys and values are strings. |
dccbebcff075
ui: add method to return option and all sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27153
diff
changeset
|
744 """ |
32984
61a8321c9962
config: use the 'config' method in 'configsuboptions'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32983
diff
changeset
|
745 main = self.config(section, name, default, untrusted=untrusted) |
27252
dccbebcff075
ui: add method to return option and all sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27153
diff
changeset
|
746 data = self._data(untrusted) |
dccbebcff075
ui: add method to return option and all sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27153
diff
changeset
|
747 sub = {} |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
748 prefix = b'%s:' % name |
27252
dccbebcff075
ui: add method to return option and all sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27153
diff
changeset
|
749 for k, v in data.items(section): |
dccbebcff075
ui: add method to return option and all sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27153
diff
changeset
|
750 if k.startswith(prefix): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
751 sub[k[len(prefix) :]] = v |
27252
dccbebcff075
ui: add method to return option and all sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27153
diff
changeset
|
752 |
dccbebcff075
ui: add method to return option and all sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27153
diff
changeset
|
753 if self.debugflag and not untrusted and self._reportuntrusted: |
dccbebcff075
ui: add method to return option and all sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27153
diff
changeset
|
754 for k, v in sub.items(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
755 uvalue = self._ucfg.get(section, b'%s:%s' % (name, k)) |
27252
dccbebcff075
ui: add method to return option and all sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27153
diff
changeset
|
756 if uvalue is not None and uvalue != v: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
757 self.debug( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
758 b'ignoring untrusted configuration option ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
759 b'%s:%s.%s = %s\n' % (section, name, k, uvalue) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
760 ) |
27252
dccbebcff075
ui: add method to return option and all sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27153
diff
changeset
|
761 |
dccbebcff075
ui: add method to return option and all sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27153
diff
changeset
|
762 return main, sub |
dccbebcff075
ui: add method to return option and all sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27153
diff
changeset
|
763 |
32983
36e16797df32
config: use the new '_unset' value for 'configpath'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32982
diff
changeset
|
764 def configpath(self, section, name, default=_unset, untrusted=False): |
43807
be8552f25cab
cleanup: fix docstring formatting
Matt Harbison <matt_harbison@yahoo.com>
parents:
43554
diff
changeset
|
765 """get a path config item, expanded relative to repo root or config |
be8552f25cab
cleanup: fix docstring formatting
Matt Harbison <matt_harbison@yahoo.com>
parents:
43554
diff
changeset
|
766 file""" |
13238 | 767 v = self.config(section, name, default, untrusted) |
14923
351624f8f523
ui: providing no default value to configpath should not raise an Error
Simon Heimberg <simohe@besonet.ch>
parents:
14922
diff
changeset
|
768 if v is None: |
351624f8f523
ui: providing no default value to configpath should not raise an Error
Simon Heimberg <simohe@besonet.ch>
parents:
14922
diff
changeset
|
769 return None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
770 if not os.path.isabs(v) or b"://" not in v: |
13238 | 771 src = self.configsource(section, name, untrusted) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
772 if b':' in src: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
773 base = os.path.dirname(src.rsplit(b':')[0]) |
13238 | 774 v = os.path.join(base, os.path.expanduser(v)) |
775 return v | |
776 | |
32977
b39dafe681df
config: use the new '_unset' value for 'configbool'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32976
diff
changeset
|
777 def configbool(self, section, name, default=_unset, untrusted=False): |
14171
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
778 """parse a configuration element as a boolean |
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
779 |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
780 >>> u = ui(); s = b'foo' |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
781 >>> u.setconfig(s, b'true', b'yes') |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
782 >>> u.configbool(s, b'true') |
14171
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
783 True |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
784 >>> u.setconfig(s, b'false', b'no') |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
785 >>> u.configbool(s, b'false') |
14171
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
786 False |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
787 >>> u.configbool(s, b'unknown') |
14171
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
788 False |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
789 >>> u.configbool(s, b'unknown', True) |
14171
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
790 True |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
791 >>> u.setconfig(s, b'invalid', b'somevalue') |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
792 >>> u.configbool(s, b'invalid') |
14171
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
793 Traceback (most recent call last): |
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
794 ... |
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
795 ConfigError: foo.invalid is not a boolean ('somevalue') |
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
796 """ |
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
797 |
33071
1dc2ffe0123b
config: use '_config' within 'configbool'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33070
diff
changeset
|
798 v = self._config(section, name, default, untrusted=untrusted) |
8527
f9a80054dd3c
use 'x is None' instead of 'x == None'
Martin Geisler <mg@lazybytes.net>
parents:
8478
diff
changeset
|
799 if v is None: |
33071
1dc2ffe0123b
config: use '_config' within 'configbool'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33070
diff
changeset
|
800 return v |
1dc2ffe0123b
config: use '_config' within 'configbool'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33070
diff
changeset
|
801 if v is _unset: |
32977
b39dafe681df
config: use the new '_unset' value for 'configbool'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32976
diff
changeset
|
802 if default is _unset: |
b39dafe681df
config: use the new '_unset' value for 'configbool'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32976
diff
changeset
|
803 return False |
8144
fca54469480e
ui: introduce new config parser
Matt Mackall <mpm@selenic.com>
parents:
8143
diff
changeset
|
804 return default |
10243
cd3e5c47d663
ui: just return it if it's already a bool
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10220
diff
changeset
|
805 if isinstance(v, bool): |
cd3e5c47d663
ui: just return it if it's already a bool
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10220
diff
changeset
|
806 return v |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36916
diff
changeset
|
807 b = stringutil.parsebool(v) |
12087
a88a4720c2f0
parsebool: create new function and use it for config parsing
Augie Fackler <durin42@gmail.com>
parents:
11984
diff
changeset
|
808 if b is None: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
809 raise error.ConfigError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
810 _(b"%s.%s is not a boolean ('%s')") % (section, name, v) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
811 ) |
12087
a88a4720c2f0
parsebool: create new function and use it for config parsing
Augie Fackler <durin42@gmail.com>
parents:
11984
diff
changeset
|
812 return b |
3552
9b52239dc740
save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3551
diff
changeset
|
813 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
814 def configwith( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
815 self, convert, section, name, default=_unset, desc=None, untrusted=False |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
816 ): |
30946
120682fce099
ui: add a configwith method
Bryan O'Sullivan <bryano@fb.com>
parents:
30945
diff
changeset
|
817 """parse a configuration element with a conversion function |
120682fce099
ui: add a configwith method
Bryan O'Sullivan <bryano@fb.com>
parents:
30945
diff
changeset
|
818 |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
819 >>> u = ui(); s = b'foo' |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
820 >>> u.setconfig(s, b'float1', b'42') |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
821 >>> u.configwith(float, s, b'float1') |
30946
120682fce099
ui: add a configwith method
Bryan O'Sullivan <bryano@fb.com>
parents:
30945
diff
changeset
|
822 42.0 |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
823 >>> u.setconfig(s, b'float2', b'-4.25') |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
824 >>> u.configwith(float, s, b'float2') |
30952 | 825 -4.25 |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
826 >>> u.configwith(float, s, b'unknown', 7) |
32978
6ff6eb33f353
config: use the new '_unset' value for 'configwith'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32977
diff
changeset
|
827 7.0 |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
828 >>> u.setconfig(s, b'invalid', b'somevalue') |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
829 >>> u.configwith(float, s, b'invalid') |
30946
120682fce099
ui: add a configwith method
Bryan O'Sullivan <bryano@fb.com>
parents:
30945
diff
changeset
|
830 Traceback (most recent call last): |
120682fce099
ui: add a configwith method
Bryan O'Sullivan <bryano@fb.com>
parents:
30945
diff
changeset
|
831 ... |
120682fce099
ui: add a configwith method
Bryan O'Sullivan <bryano@fb.com>
parents:
30945
diff
changeset
|
832 ConfigError: foo.invalid is not a valid float ('somevalue') |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
833 >>> u.configwith(float, s, b'invalid', desc=b'womble') |
30946
120682fce099
ui: add a configwith method
Bryan O'Sullivan <bryano@fb.com>
parents:
30945
diff
changeset
|
834 Traceback (most recent call last): |
120682fce099
ui: add a configwith method
Bryan O'Sullivan <bryano@fb.com>
parents:
30945
diff
changeset
|
835 ... |
120682fce099
ui: add a configwith method
Bryan O'Sullivan <bryano@fb.com>
parents:
30945
diff
changeset
|
836 ConfigError: foo.invalid is not a valid womble ('somevalue') |
120682fce099
ui: add a configwith method
Bryan O'Sullivan <bryano@fb.com>
parents:
30945
diff
changeset
|
837 """ |
120682fce099
ui: add a configwith method
Bryan O'Sullivan <bryano@fb.com>
parents:
30945
diff
changeset
|
838 |
32978
6ff6eb33f353
config: use the new '_unset' value for 'configwith'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32977
diff
changeset
|
839 v = self.config(section, name, default, untrusted) |
30946
120682fce099
ui: add a configwith method
Bryan O'Sullivan <bryano@fb.com>
parents:
30945
diff
changeset
|
840 if v is None: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
841 return v # do not attempt to convert None |
30946
120682fce099
ui: add a configwith method
Bryan O'Sullivan <bryano@fb.com>
parents:
30945
diff
changeset
|
842 try: |
120682fce099
ui: add a configwith method
Bryan O'Sullivan <bryano@fb.com>
parents:
30945
diff
changeset
|
843 return convert(v) |
32496
bb18728ea617
util: raise ParseError when parsing dates (BC)
Boris Feld <boris.feld@octobus.net>
parents:
32487
diff
changeset
|
844 except (ValueError, error.ParseError): |
30946
120682fce099
ui: add a configwith method
Bryan O'Sullivan <bryano@fb.com>
parents:
30945
diff
changeset
|
845 if desc is None: |
34215
0a2fd3bfc704
py3: convert function name to bytes in ui.configwith()
Yuya Nishihara <yuya@tcha.org>
parents:
34146
diff
changeset
|
846 desc = pycompat.sysbytes(convert.__name__) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
847 raise error.ConfigError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
848 _(b"%s.%s is not a valid %s ('%s')") % (section, name, desc, v) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
849 ) |
30946
120682fce099
ui: add a configwith method
Bryan O'Sullivan <bryano@fb.com>
parents:
30945
diff
changeset
|
850 |
32979
24111157f967
config: use the new '_unset' value for 'configint'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32978
diff
changeset
|
851 def configint(self, section, name, default=_unset, untrusted=False): |
14171
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
852 """parse a configuration element as an integer |
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
853 |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
854 >>> u = ui(); s = b'foo' |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
855 >>> u.setconfig(s, b'int1', b'42') |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
856 >>> u.configint(s, b'int1') |
14171
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
857 42 |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
858 >>> u.setconfig(s, b'int2', b'-42') |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
859 >>> u.configint(s, b'int2') |
14171
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
860 -42 |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
861 >>> u.configint(s, b'unknown', 7) |
14171
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
862 7 |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
863 >>> u.setconfig(s, b'invalid', b'somevalue') |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
864 >>> u.configint(s, b'invalid') |
14171
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
865 Traceback (most recent call last): |
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
866 ... |
30947
8fa3ab6221b9
ui: rewrite configint in terms of configwith
Bryan O'Sullivan <bryano@fb.com>
parents:
30946
diff
changeset
|
867 ConfigError: foo.invalid is not a valid integer ('somevalue') |
14171
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
868 """ |
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
869 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
870 return self.configwith( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
871 int, section, name, default, b'integer', untrusted |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
872 ) |
14171
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
873 |
32980
0bf986cfa82b
config: use the new '_unset' value for 'configbytes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32979
diff
changeset
|
874 def configbytes(self, section, name, default=_unset, untrusted=False): |
19065
2c4cd1c42365
ui: add a configbytes method, for space configuration
Bryan O'Sullivan <bryano@fb.com>
parents:
18966
diff
changeset
|
875 """parse a configuration element as a quantity in bytes |
2c4cd1c42365
ui: add a configbytes method, for space configuration
Bryan O'Sullivan <bryano@fb.com>
parents:
18966
diff
changeset
|
876 |
2c4cd1c42365
ui: add a configbytes method, for space configuration
Bryan O'Sullivan <bryano@fb.com>
parents:
18966
diff
changeset
|
877 Units can be specified as b (bytes), k or kb (kilobytes), m or |
2c4cd1c42365
ui: add a configbytes method, for space configuration
Bryan O'Sullivan <bryano@fb.com>
parents:
18966
diff
changeset
|
878 mb (megabytes), g or gb (gigabytes). |
2c4cd1c42365
ui: add a configbytes method, for space configuration
Bryan O'Sullivan <bryano@fb.com>
parents:
18966
diff
changeset
|
879 |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
880 >>> u = ui(); s = b'foo' |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
881 >>> u.setconfig(s, b'val1', b'42') |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
882 >>> u.configbytes(s, b'val1') |
19065
2c4cd1c42365
ui: add a configbytes method, for space configuration
Bryan O'Sullivan <bryano@fb.com>
parents:
18966
diff
changeset
|
883 42 |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
884 >>> u.setconfig(s, b'val2', b'42.5 kb') |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
885 >>> u.configbytes(s, b'val2') |
19065
2c4cd1c42365
ui: add a configbytes method, for space configuration
Bryan O'Sullivan <bryano@fb.com>
parents:
18966
diff
changeset
|
886 43520 |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
887 >>> u.configbytes(s, b'unknown', b'7 MB') |
19065
2c4cd1c42365
ui: add a configbytes method, for space configuration
Bryan O'Sullivan <bryano@fb.com>
parents:
18966
diff
changeset
|
888 7340032 |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
889 >>> u.setconfig(s, b'invalid', b'somevalue') |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
890 >>> u.configbytes(s, b'invalid') |
19065
2c4cd1c42365
ui: add a configbytes method, for space configuration
Bryan O'Sullivan <bryano@fb.com>
parents:
18966
diff
changeset
|
891 Traceback (most recent call last): |
2c4cd1c42365
ui: add a configbytes method, for space configuration
Bryan O'Sullivan <bryano@fb.com>
parents:
18966
diff
changeset
|
892 ... |
2c4cd1c42365
ui: add a configbytes method, for space configuration
Bryan O'Sullivan <bryano@fb.com>
parents:
18966
diff
changeset
|
893 ConfigError: foo.invalid is not a byte quantity ('somevalue') |
2c4cd1c42365
ui: add a configbytes method, for space configuration
Bryan O'Sullivan <bryano@fb.com>
parents:
18966
diff
changeset
|
894 """ |
2c4cd1c42365
ui: add a configbytes method, for space configuration
Bryan O'Sullivan <bryano@fb.com>
parents:
18966
diff
changeset
|
895 |
33072
e70cbae4c4e6
config: use '_config' within 'configbytes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33071
diff
changeset
|
896 value = self._config(section, name, default, untrusted) |
e70cbae4c4e6
config: use '_config' within 'configbytes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33071
diff
changeset
|
897 if value is _unset: |
32980
0bf986cfa82b
config: use the new '_unset' value for 'configbytes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32979
diff
changeset
|
898 if default is _unset: |
0bf986cfa82b
config: use the new '_unset' value for 'configbytes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32979
diff
changeset
|
899 default = 0 |
19195
9311cd5c09ed
ui: use util.sizetoint in configbytes
Bryan O'Sullivan <bryano@fb.com>
parents:
19085
diff
changeset
|
900 value = default |
33585
d90f9e4704de
ui: fix configbytes isinstance check to look for bytes and not str
Augie Fackler <augie@google.com>
parents:
33499
diff
changeset
|
901 if not isinstance(value, bytes): |
32980
0bf986cfa82b
config: use the new '_unset' value for 'configbytes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32979
diff
changeset
|
902 return value |
19065
2c4cd1c42365
ui: add a configbytes method, for space configuration
Bryan O'Sullivan <bryano@fb.com>
parents:
18966
diff
changeset
|
903 try: |
19195
9311cd5c09ed
ui: use util.sizetoint in configbytes
Bryan O'Sullivan <bryano@fb.com>
parents:
19085
diff
changeset
|
904 return util.sizetoint(value) |
9311cd5c09ed
ui: use util.sizetoint in configbytes
Bryan O'Sullivan <bryano@fb.com>
parents:
19085
diff
changeset
|
905 except error.ParseError: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
906 raise error.ConfigError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
907 _(b"%s.%s is not a byte quantity ('%s')") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
908 % (section, name, value) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
909 ) |
19065
2c4cd1c42365
ui: add a configbytes method, for space configuration
Bryan O'Sullivan <bryano@fb.com>
parents:
18966
diff
changeset
|
910 |
32981
88b3a38d39e3
config: use the new '_unset' value for 'configlist'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32980
diff
changeset
|
911 def configlist(self, section, name, default=_unset, untrusted=False): |
14171
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
912 """parse a configuration element as a list of comma/space separated |
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
913 strings |
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
914 |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
915 >>> u = ui(); s = b'foo' |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
916 >>> u.setconfig(s, b'list1', b'this,is "a small" ,test') |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
917 >>> u.configlist(s, b'list1') |
14171
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
918 ['this', 'is', 'a small', 'test'] |
35013
58e7791e243b
ui: add configlist doctest to document a bit more of the whitespace behavior
Augie Fackler <augie@google.com>
parents:
34947
diff
changeset
|
919 >>> u.setconfig(s, b'list2', b'this, is "a small" , test ') |
58e7791e243b
ui: add configlist doctest to document a bit more of the whitespace behavior
Augie Fackler <augie@google.com>
parents:
34947
diff
changeset
|
920 >>> u.configlist(s, b'list2') |
58e7791e243b
ui: add configlist doctest to document a bit more of the whitespace behavior
Augie Fackler <augie@google.com>
parents:
34947
diff
changeset
|
921 ['this', 'is', 'a small', 'test'] |
14171
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
14076
diff
changeset
|
922 """ |
31488
a7c687c35119
ui: move configlist parser to config.py
Jun Wu <quark@fb.com>
parents:
31486
diff
changeset
|
923 # default is not always a list |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
924 v = self.configwith( |
47200
b0e92313107e
parselist: move the function from config to stringutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47070
diff
changeset
|
925 stringutil.parselist, section, name, default, b'list', untrusted |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
926 ) |
32981
88b3a38d39e3
config: use the new '_unset' value for 'configlist'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32980
diff
changeset
|
927 if isinstance(v, bytes): |
47200
b0e92313107e
parselist: move the function from config to stringutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47070
diff
changeset
|
928 return stringutil.parselist(v) |
32981
88b3a38d39e3
config: use the new '_unset' value for 'configlist'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32980
diff
changeset
|
929 elif v is None: |
88b3a38d39e3
config: use the new '_unset' value for 'configlist'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32980
diff
changeset
|
930 return [] |
88b3a38d39e3
config: use the new '_unset' value for 'configlist'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32980
diff
changeset
|
931 return v |
2499
894435215344
Added ui.configlist method to get comma/space separated lists of strings.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2498
diff
changeset
|
932 |
32982
6599b7372387
config: use the new '_unset' value for 'configdate'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32981
diff
changeset
|
933 def configdate(self, section, name, default=_unset, untrusted=False): |
32446
420e93b0d9dc
ui: add the possiblity to get a date config field
Boris Feld <boris.feld@octobus.net>
parents:
32105
diff
changeset
|
934 """parse a configuration element as a tuple of ints |
420e93b0d9dc
ui: add the possiblity to get a date config field
Boris Feld <boris.feld@octobus.net>
parents:
32105
diff
changeset
|
935 |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
936 >>> u = ui(); s = b'foo' |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
937 >>> u.setconfig(s, b'date', b'0 0') |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
938 >>> u.configdate(s, b'date') |
32446
420e93b0d9dc
ui: add the possiblity to get a date config field
Boris Feld <boris.feld@octobus.net>
parents:
32105
diff
changeset
|
939 (0, 0) |
420e93b0d9dc
ui: add the possiblity to get a date config field
Boris Feld <boris.feld@octobus.net>
parents:
32105
diff
changeset
|
940 """ |
420e93b0d9dc
ui: add the possiblity to get a date config field
Boris Feld <boris.feld@octobus.net>
parents:
32105
diff
changeset
|
941 if self.config(section, name, default, untrusted): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
942 return self.configwith( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
943 dateutil.parsedate, section, name, default, b'date', untrusted |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
944 ) |
32982
6599b7372387
config: use the new '_unset' value for 'configdate'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32981
diff
changeset
|
945 if default is _unset: |
6599b7372387
config: use the new '_unset' value for 'configdate'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32981
diff
changeset
|
946 return None |
32446
420e93b0d9dc
ui: add the possiblity to get a date config field
Boris Feld <boris.feld@octobus.net>
parents:
32105
diff
changeset
|
947 return default |
420e93b0d9dc
ui: add the possiblity to get a date config field
Boris Feld <boris.feld@octobus.net>
parents:
32105
diff
changeset
|
948 |
42699
51a2e3102db2
config: add defaultvalue template keyword
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42564
diff
changeset
|
949 def configdefault(self, section, name): |
51a2e3102db2
config: add defaultvalue template keyword
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42564
diff
changeset
|
950 """returns the default value of the config item""" |
51a2e3102db2
config: add defaultvalue template keyword
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42564
diff
changeset
|
951 item = self._knownconfig.get(section, {}).get(name) |
51a2e3102db2
config: add defaultvalue template keyword
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42564
diff
changeset
|
952 itemdefault = None |
51a2e3102db2
config: add defaultvalue template keyword
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42564
diff
changeset
|
953 if item is not None: |
51a2e3102db2
config: add defaultvalue template keyword
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42564
diff
changeset
|
954 if callable(item.default): |
51a2e3102db2
config: add defaultvalue template keyword
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42564
diff
changeset
|
955 itemdefault = item.default() |
51a2e3102db2
config: add defaultvalue template keyword
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42564
diff
changeset
|
956 else: |
51a2e3102db2
config: add defaultvalue template keyword
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42564
diff
changeset
|
957 itemdefault = item.default |
51a2e3102db2
config: add defaultvalue template keyword
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42564
diff
changeset
|
958 return itemdefault |
51a2e3102db2
config: add defaultvalue template keyword
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42564
diff
changeset
|
959 |
27696
e70c97cc9243
config: add hasconfig method and supporting plumbing
Bryan O'Sullivan <bos@serpentine.com>
parents:
27563
diff
changeset
|
960 def hasconfig(self, section, name, untrusted=False): |
e70c97cc9243
config: add hasconfig method and supporting plumbing
Bryan O'Sullivan <bos@serpentine.com>
parents:
27563
diff
changeset
|
961 return self._data(untrusted).hasitem(section, name) |
e70c97cc9243
config: add hasconfig method and supporting plumbing
Bryan O'Sullivan <bos@serpentine.com>
parents:
27563
diff
changeset
|
962 |
4487
1b5b98837bb5
ui: Rename has_config to has_section.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4258
diff
changeset
|
963 def has_section(self, section, untrusted=False): |
2343
af81d8770620
add ui.has_config method.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2335
diff
changeset
|
964 '''tell whether section exists in config.''' |
8199 | 965 return section in self._data(untrusted) |
3552
9b52239dc740
save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3551
diff
changeset
|
966 |
27253
f43988e5954c
ui: optionally ignore sub-options from configitems()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27252
diff
changeset
|
967 def configitems(self, section, untrusted=False, ignoresub=False): |
8199 | 968 items = self._data(untrusted).items(section) |
27253
f43988e5954c
ui: optionally ignore sub-options from configitems()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27252
diff
changeset
|
969 if ignoresub: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
970 items = [i for i in items if b':' not in i[0]] |
8204 | 971 if self.debugflag and not untrusted and self._reportuntrusted: |
8222
d30a21594812
more whitespace cleanup and some other style nits
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8220
diff
changeset
|
972 for k, v in self._ucfg.items(section): |
8203 | 973 if self._tcfg.get(section, k) != v: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
974 self.debug( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
975 b"ignoring untrusted configuration option " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
976 b"%s.%s = %s\n" % (section, k, v) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
977 ) |
8144
fca54469480e
ui: introduce new config parser
Matt Mackall <mpm@selenic.com>
parents:
8143
diff
changeset
|
978 return items |
285 | 979 |
47421
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
980 def walkconfig(self, untrusted=False, all_known=False): |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
981 defined = self._walk_config(untrusted) |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
982 if not all_known: |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
983 for d in defined: |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
984 yield d |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
985 return |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
986 known = self._walk_known() |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
987 current_defined = next(defined, None) |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
988 current_known = next(known, None) |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
989 while current_defined is not None or current_known is not None: |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
990 if current_defined is None: |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
991 yield current_known |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
992 current_known = next(known, None) |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
993 elif current_known is None: |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
994 yield current_defined |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
995 current_defined = next(defined, None) |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
996 elif current_known[0:2] == current_defined[0:2]: |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
997 yield current_defined |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
998 current_defined = next(defined, None) |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
999 current_known = next(known, None) |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
1000 elif current_known[0:2] < current_defined[0:2]: |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
1001 yield current_known |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
1002 current_known = next(known, None) |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
1003 else: |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
1004 yield current_defined |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
1005 current_defined = next(defined, None) |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
1006 |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
1007 def _walk_known(self): |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
1008 for section, items in sorted(self._knownconfig.items()): |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
1009 for k, i in sorted(items.items()): |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
1010 # We don't have a way to display generic well, so skip them |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
1011 if i.generic: |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
1012 continue |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
1013 if callable(i.default): |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
1014 default = i.default() |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
1015 elif i.default is configitems.dynamicdefault: |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
1016 default = b'<DYNAMIC>' |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
1017 else: |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
1018 default = i.default |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
1019 yield section, i.name, default |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
1020 |
b1b3127227be
config: add an experimental option to list all known config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
1021 def _walk_config(self, untrusted): |
8203 | 1022 cfg = self._data(untrusted) |
1023 for section in cfg.sections(): | |
3552
9b52239dc740
save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3551
diff
changeset
|
1024 for name, value in self.configitems(section, untrusted): |
13576
edd06611a7c6
ui: yield unchanged values in walkconfig
Martin Geisler <mg@aragost.com>
parents:
13493
diff
changeset
|
1025 yield section, name, value |
1028
25e7ea0f2cff
Add commands.debugconfig.
Bryan O'Sullivan <bos@serpentine.com>
parents:
981
diff
changeset
|
1026 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1027 def plain(self, feature: Optional[bytes] = None) -> bool: |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1028 """is plain mode active? |
11325
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1029 |
13849
9f97de157aad
HGPLAIN: allow exceptions to plain mode, like i18n, via HGPLAINEXCEPT
Brodie Rao <brodie@bitheap.org>
parents:
13827
diff
changeset
|
1030 Plain mode means that all configuration variables which affect |
9f97de157aad
HGPLAIN: allow exceptions to plain mode, like i18n, via HGPLAINEXCEPT
Brodie Rao <brodie@bitheap.org>
parents:
13827
diff
changeset
|
1031 the behavior and output of Mercurial should be |
9f97de157aad
HGPLAIN: allow exceptions to plain mode, like i18n, via HGPLAINEXCEPT
Brodie Rao <brodie@bitheap.org>
parents:
13827
diff
changeset
|
1032 ignored. Additionally, the output should be stable, |
9f97de157aad
HGPLAIN: allow exceptions to plain mode, like i18n, via HGPLAINEXCEPT
Brodie Rao <brodie@bitheap.org>
parents:
13827
diff
changeset
|
1033 reproducible and suitable for use in scripts or applications. |
9f97de157aad
HGPLAIN: allow exceptions to plain mode, like i18n, via HGPLAINEXCEPT
Brodie Rao <brodie@bitheap.org>
parents:
13827
diff
changeset
|
1034 |
9f97de157aad
HGPLAIN: allow exceptions to plain mode, like i18n, via HGPLAINEXCEPT
Brodie Rao <brodie@bitheap.org>
parents:
13827
diff
changeset
|
1035 The only way to trigger plain mode is by setting either the |
9f97de157aad
HGPLAIN: allow exceptions to plain mode, like i18n, via HGPLAINEXCEPT
Brodie Rao <brodie@bitheap.org>
parents:
13827
diff
changeset
|
1036 `HGPLAIN' or `HGPLAINEXCEPT' environment variables. |
11325
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1037 |
14372
be0daa0eeb3e
ui: test plain mode against exceptions
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
14171
diff
changeset
|
1038 The return value can either be |
be0daa0eeb3e
ui: test plain mode against exceptions
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
14171
diff
changeset
|
1039 - False if HGPLAIN is not set, or feature is in HGPLAINEXCEPT |
34996
c9740b69b9b7
dispatch: add HGPLAIN=+strictflags to restrict early parsing of global options
Yuya Nishihara <yuya@tcha.org>
parents:
34947
diff
changeset
|
1040 - False if feature is disabled by default and not included in HGPLAIN |
14372
be0daa0eeb3e
ui: test plain mode against exceptions
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
14171
diff
changeset
|
1041 - True otherwise |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1042 """ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1043 if ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1044 b'HGPLAIN' not in encoding.environ |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1045 and b'HGPLAINEXCEPT' not in encoding.environ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1046 ): |
13849
9f97de157aad
HGPLAIN: allow exceptions to plain mode, like i18n, via HGPLAINEXCEPT
Brodie Rao <brodie@bitheap.org>
parents:
13827
diff
changeset
|
1047 return False |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1048 exceptions = ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1049 encoding.environ.get(b'HGPLAINEXCEPT', b'').strip().split(b',') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1050 ) |
34996
c9740b69b9b7
dispatch: add HGPLAIN=+strictflags to restrict early parsing of global options
Yuya Nishihara <yuya@tcha.org>
parents:
34947
diff
changeset
|
1051 # TODO: add support for HGPLAIN=+feature,-feature syntax |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1052 if b'+strictflags' not in encoding.environ.get(b'HGPLAIN', b'').split( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1053 b',' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1054 ): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1055 exceptions.append(b'strictflags') |
14372
be0daa0eeb3e
ui: test plain mode against exceptions
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
14171
diff
changeset
|
1056 if feature and exceptions: |
be0daa0eeb3e
ui: test plain mode against exceptions
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
14171
diff
changeset
|
1057 return feature not in exceptions |
be0daa0eeb3e
ui: test plain mode against exceptions
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
14171
diff
changeset
|
1058 return True |
10455
40dfd46d098f
ui: add HGPLAIN environment variable for easier scripting
Brodie Rao <me+hg@dackz.net>
parents:
10426
diff
changeset
|
1059 |
34849
9f2891fb426c
ui: add the possibility to returns None as username in ui
Boris Feld <boris.feld@octobus.net>
parents:
34707
diff
changeset
|
1060 def username(self, acceptempty=False): |
1985
c577689006fa
Adapted behaviour of ui.username() to documentation and mention it explicitly:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1984
diff
changeset
|
1061 """Return default username to be used in commits. |
c577689006fa
Adapted behaviour of ui.username() to documentation and mention it explicitly:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1984
diff
changeset
|
1062 |
c577689006fa
Adapted behaviour of ui.username() to documentation and mention it explicitly:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1984
diff
changeset
|
1063 Searched in this order: $HGUSER, [ui] section of hgrcs, $EMAIL |
c577689006fa
Adapted behaviour of ui.username() to documentation and mention it explicitly:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1984
diff
changeset
|
1064 and stop searching if one of these is set. |
34849
9f2891fb426c
ui: add the possibility to returns None as username in ui
Boris Feld <boris.feld@octobus.net>
parents:
34707
diff
changeset
|
1065 If not found and acceptempty is True, returns None. |
6862
7192876ac329
ui: add an option to prompt for the username when it isn't provided
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6762
diff
changeset
|
1066 If not found and ui.askusername is True, ask the user, else use |
7192876ac329
ui: add an option to prompt for the username when it isn't provided
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6762
diff
changeset
|
1067 ($LOGNAME or $USER or $LNAME or $USERNAME) + "@full.hostname". |
34849
9f2891fb426c
ui: add the possibility to returns None as username in ui
Boris Feld <boris.feld@octobus.net>
parents:
34707
diff
changeset
|
1068 If no username could be found, raise an Abort error. |
1985
c577689006fa
Adapted behaviour of ui.username() to documentation and mention it explicitly:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1984
diff
changeset
|
1069 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1070 user = encoding.environ.get(b"HGUSER") |
1985
c577689006fa
Adapted behaviour of ui.username() to documentation and mention it explicitly:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1984
diff
changeset
|
1071 if user is None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1072 user = self.config(b"ui", b"username") |
11225
d6dbd5e4ee72
ui.username(): expand environment variables in username configuration value.
Chad Dombrova <chadrik@gmail.com>
parents:
11036
diff
changeset
|
1073 if user is not None: |
d6dbd5e4ee72
ui.username(): expand environment variables in username configuration value.
Chad Dombrova <chadrik@gmail.com>
parents:
11036
diff
changeset
|
1074 user = os.path.expandvars(user) |
1985
c577689006fa
Adapted behaviour of ui.username() to documentation and mention it explicitly:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1984
diff
changeset
|
1075 if user is None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1076 user = encoding.environ.get(b"EMAIL") |
34849
9f2891fb426c
ui: add the possibility to returns None as username in ui
Boris Feld <boris.feld@octobus.net>
parents:
34707
diff
changeset
|
1077 if user is None and acceptempty: |
9f2891fb426c
ui: add the possibility to returns None as username in ui
Boris Feld <boris.feld@octobus.net>
parents:
34707
diff
changeset
|
1078 return user |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1079 if user is None and self.configbool(b"ui", b"askusername"): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1080 user = self.prompt(_(b"enter a commit username:"), default=None) |
9613
c63c336ee2f7
ui: only use "user@host" as username in noninteractive mode
Martin Geisler <mg@lazybytes.net>
parents:
9610
diff
changeset
|
1081 if user is None and not self.interactive(): |
3721
98f2507c5551
only print a warning when no username is specified
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3678
diff
changeset
|
1082 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1083 user = b'%s@%s' % ( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1084 procutil.getuser(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1085 encoding.strtolocal(socket.getfqdn()), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1086 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1087 self.warn(_(b"no username found, using '%s' instead\n") % user) |
3721
98f2507c5551
only print a warning when no username is specified
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3678
diff
changeset
|
1088 except KeyError: |
4044
78a0dd93db0b
Abort on empty username so specifying a username can be forced.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3984
diff
changeset
|
1089 pass |
78a0dd93db0b
Abort on empty username so specifying a username can be forced.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3984
diff
changeset
|
1090 if not user: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1091 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1092 _(b'no username supplied'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1093 hint=_(b"use 'hg config --edit' " b'to set your username'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1094 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1095 if b"\n" in user: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1096 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1097 _(b"username %r contains a newline\n") % pycompat.bytestr(user) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1098 ) |
1985
c577689006fa
Adapted behaviour of ui.username() to documentation and mention it explicitly:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1984
diff
changeset
|
1099 return user |
608
d2994b5298fb
Add username/merge/editor to .hgrc
Matt Mackall <mpm@selenic.com>
parents:
565
diff
changeset
|
1100 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1101 def shortuser(self, user: bytes) -> bytes: |
1129
ee4f60abad93
Move generating short username to display in hg/hgweb annotate to ui module.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1071
diff
changeset
|
1102 """Return a short representation of a user name or email address.""" |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1103 if not self.verbose: |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36916
diff
changeset
|
1104 user = stringutil.shortuser(user) |
1129
ee4f60abad93
Move generating short username to display in hg/hgweb annotate to ui module.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1071
diff
changeset
|
1105 return user |
ee4f60abad93
Move generating short username to display in hg/hgweb annotate to ui module.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1071
diff
changeset
|
1106 |
24250
9c32eea2ca04
ui: represent paths as classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23269
diff
changeset
|
1107 @util.propertycache |
9c32eea2ca04
ui: represent paths as classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23269
diff
changeset
|
1108 def paths(self): |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46828
diff
changeset
|
1109 return urlutil.paths(self) |
506 | 1110 |
40593
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1111 @property |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1112 def fout(self): |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1113 return self._fout |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1114 |
50487
7f0f3b274d1e
ui: keep the progress bar around when writing if stdout is not a tty
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50253
diff
changeset
|
1115 @util.propertycache |
7f0f3b274d1e
ui: keep the progress bar around when writing if stdout is not a tty
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50253
diff
changeset
|
1116 def _fout_is_a_tty(self): |
7f0f3b274d1e
ui: keep the progress bar around when writing if stdout is not a tty
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50253
diff
changeset
|
1117 self._isatty(self._fout) |
7f0f3b274d1e
ui: keep the progress bar around when writing if stdout is not a tty
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50253
diff
changeset
|
1118 |
40593
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1119 @fout.setter |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1120 def fout(self, f): |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1121 self._fout = f |
40594
840cd57cde32
ui: add config knob to redirect status messages to stderr (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40593
diff
changeset
|
1122 self._fmsgout, self._fmsgerr = _selectmsgdests(self) |
50487
7f0f3b274d1e
ui: keep the progress bar around when writing if stdout is not a tty
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50253
diff
changeset
|
1123 if '_fout_is_a_tty' in vars(self): |
7f0f3b274d1e
ui: keep the progress bar around when writing if stdout is not a tty
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50253
diff
changeset
|
1124 del self._fout_is_a_tty |
40593
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1125 |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1126 @property |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1127 def ferr(self): |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1128 return self._ferr |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1129 |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1130 @ferr.setter |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1131 def ferr(self, f): |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1132 self._ferr = f |
40594
840cd57cde32
ui: add config knob to redirect status messages to stderr (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40593
diff
changeset
|
1133 self._fmsgout, self._fmsgerr = _selectmsgdests(self) |
40593
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1134 |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1135 @property |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1136 def fin(self): |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1137 return self._fin |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1138 |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1139 @fin.setter |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1140 def fin(self, f): |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1141 self._fin = f |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1142 |
40634
5542bc9125c9
dispatch: pass around ui.fmsg channel
Yuya Nishihara <yuya@tcha.org>
parents:
40625
diff
changeset
|
1143 @property |
5542bc9125c9
dispatch: pass around ui.fmsg channel
Yuya Nishihara <yuya@tcha.org>
parents:
40625
diff
changeset
|
1144 def fmsg(self): |
5542bc9125c9
dispatch: pass around ui.fmsg channel
Yuya Nishihara <yuya@tcha.org>
parents:
40625
diff
changeset
|
1145 """Stream dedicated for status/error messages; may be None if |
5542bc9125c9
dispatch: pass around ui.fmsg channel
Yuya Nishihara <yuya@tcha.org>
parents:
40625
diff
changeset
|
1146 fout/ferr are used""" |
5542bc9125c9
dispatch: pass around ui.fmsg channel
Yuya Nishihara <yuya@tcha.org>
parents:
40625
diff
changeset
|
1147 return self._fmsg |
5542bc9125c9
dispatch: pass around ui.fmsg channel
Yuya Nishihara <yuya@tcha.org>
parents:
40625
diff
changeset
|
1148 |
5542bc9125c9
dispatch: pass around ui.fmsg channel
Yuya Nishihara <yuya@tcha.org>
parents:
40625
diff
changeset
|
1149 @fmsg.setter |
5542bc9125c9
dispatch: pass around ui.fmsg channel
Yuya Nishihara <yuya@tcha.org>
parents:
40625
diff
changeset
|
1150 def fmsg(self, f): |
5542bc9125c9
dispatch: pass around ui.fmsg channel
Yuya Nishihara <yuya@tcha.org>
parents:
40625
diff
changeset
|
1151 self._fmsg = f |
5542bc9125c9
dispatch: pass around ui.fmsg channel
Yuya Nishihara <yuya@tcha.org>
parents:
40625
diff
changeset
|
1152 self._fmsgout, self._fmsgerr = _selectmsgdests(self) |
5542bc9125c9
dispatch: pass around ui.fmsg channel
Yuya Nishihara <yuya@tcha.org>
parents:
40625
diff
changeset
|
1153 |
47443
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
47421
diff
changeset
|
1154 @contextlib.contextmanager |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1155 def silent( |
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1156 self, error: bool = False, subproc: bool = False, labeled: bool = False |
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1157 ): |
47443
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
47421
diff
changeset
|
1158 self.pushbuffer(error=error, subproc=subproc, labeled=labeled) |
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
47421
diff
changeset
|
1159 try: |
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
47421
diff
changeset
|
1160 yield |
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
47421
diff
changeset
|
1161 finally: |
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
47421
diff
changeset
|
1162 self.popbuffer() |
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
47421
diff
changeset
|
1163 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1164 def pushbuffer( |
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1165 self, error: bool = False, subproc: bool = False, labeled: bool = False |
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1166 ) -> None: |
23139
e53f6b72a0e4
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
23053
diff
changeset
|
1167 """install a buffer to capture standard output of the ui object |
21132
350dc24a553d
ui: pushbuffer can now also capture stderr
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20788
diff
changeset
|
1168 |
24848
2f88821856eb
ui: allow capture of subprocess output
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24687
diff
changeset
|
1169 If error is True, the error output will be captured too. |
2f88821856eb
ui: allow capture of subprocess output
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24687
diff
changeset
|
1170 |
2f88821856eb
ui: allow capture of subprocess output
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24687
diff
changeset
|
1171 If subproc is True, output from subprocesses (typically hooks) will be |
27106
6ef17697b03d
ui: track label expansion when creating buffers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27068
diff
changeset
|
1172 captured too. |
10815
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
1173 |
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
1174 If labeled is True, any labels associated with buffered |
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
1175 output will be handled. By default, this has no effect |
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
1176 on the output returned, but extensions and GUI tools may |
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
1177 handle this argument and returned styled output. If output |
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
1178 is being buffered so it can be captured and parsed or |
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
1179 processed, labeled should not be set to True. |
27106
6ef17697b03d
ui: track label expansion when creating buffers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27068
diff
changeset
|
1180 """ |
8202 | 1181 self._buffers.append([]) |
27106
6ef17697b03d
ui: track label expansion when creating buffers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27068
diff
changeset
|
1182 self._bufferstates.append((error, subproc, labeled)) |
6ef17697b03d
ui: track label expansion when creating buffers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27068
diff
changeset
|
1183 self._bufferapplylabels = labeled |
3737
9f5c46c50118
add a simple nested buffering scheme to ui
Matt Mackall <mpm@selenic.com>
parents:
3721
diff
changeset
|
1184 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1185 def popbuffer(self) -> bytes: |
27109
a93d53f79e6e
ui: remove labeled argument from popbuffer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27106
diff
changeset
|
1186 '''pop the last buffer and return the buffered output''' |
21132
350dc24a553d
ui: pushbuffer can now also capture stderr
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20788
diff
changeset
|
1187 self._bufferstates.pop() |
27106
6ef17697b03d
ui: track label expansion when creating buffers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27068
diff
changeset
|
1188 if self._bufferstates: |
6ef17697b03d
ui: track label expansion when creating buffers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27068
diff
changeset
|
1189 self._bufferapplylabels = self._bufferstates[-1][2] |
6ef17697b03d
ui: track label expansion when creating buffers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27068
diff
changeset
|
1190 else: |
6ef17697b03d
ui: track label expansion when creating buffers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27068
diff
changeset
|
1191 self._bufferapplylabels = None |
6ef17697b03d
ui: track label expansion when creating buffers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27068
diff
changeset
|
1192 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1193 return b"".join(self._buffers.pop()) |
3737
9f5c46c50118
add a simple nested buffering scheme to ui
Matt Mackall <mpm@selenic.com>
parents:
3721
diff
changeset
|
1194 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1195 def _isbuffered(self, dest) -> bool: |
40593
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1196 if dest is self._fout: |
40591
c2aea007130b
ui: add inner function to select write destination
Yuya Nishihara <yuya@tcha.org>
parents:
40590
diff
changeset
|
1197 return bool(self._buffers) |
40593
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1198 if dest is self._ferr: |
40591
c2aea007130b
ui: add inner function to select write destination
Yuya Nishihara <yuya@tcha.org>
parents:
40590
diff
changeset
|
1199 return bool(self._bufferstates and self._bufferstates[-1][0]) |
c2aea007130b
ui: add inner function to select write destination
Yuya Nishihara <yuya@tcha.org>
parents:
40590
diff
changeset
|
1200 return False |
c2aea007130b
ui: add inner function to select write destination
Yuya Nishihara <yuya@tcha.org>
parents:
40590
diff
changeset
|
1201 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1202 def canwritewithoutlabels(self) -> bool: |
36000
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35996
diff
changeset
|
1203 '''check if write skips the label''' |
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35996
diff
changeset
|
1204 if self._buffers and not self._bufferapplylabels: |
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35996
diff
changeset
|
1205 return True |
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35996
diff
changeset
|
1206 return self._colormode is None |
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35996
diff
changeset
|
1207 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1208 def canbatchlabeledwrites(self) -> bool: |
36000
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35996
diff
changeset
|
1209 '''check if write calls with labels are batchable''' |
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35996
diff
changeset
|
1210 # Windows color printing is special, see ``write``. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1211 return self._colormode != b'win32' |
36000
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35996
diff
changeset
|
1212 |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
1213 def write(self, *args: bytes, **opts: _MsgOpts) -> None: |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1214 """write args to output |
10815
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
1215 |
31108
ad074f900907
color: move 'write' logic to the core ui class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31107
diff
changeset
|
1216 By default, this method simply writes to the buffer or stdout. |
ad074f900907
color: move 'write' logic to the core ui class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31107
diff
changeset
|
1217 Color mode can be set on the UI class to have the output decorated |
ad074f900907
color: move 'write' logic to the core ui class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31107
diff
changeset
|
1218 with color modifier before being written to stdout. |
10815
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
1219 |
31108
ad074f900907
color: move 'write' logic to the core ui class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31107
diff
changeset
|
1220 The color used is controlled by an optional keyword argument, "label". |
ad074f900907
color: move 'write' logic to the core ui class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31107
diff
changeset
|
1221 This should be a string containing label names separated by space. |
ad074f900907
color: move 'write' logic to the core ui class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31107
diff
changeset
|
1222 Label names take the form of "topic.type". For example, ui.debug() |
ad074f900907
color: move 'write' logic to the core ui class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31107
diff
changeset
|
1223 issues a label of "ui.debug". |
10815
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
1224 |
43265
82879e06c926
ui: option to preserve the progress bar
Joerg Sonnenberger <joerg@bec.de>
parents:
43118
diff
changeset
|
1225 Progress reports via stderr are normally cleared before writing as |
82879e06c926
ui: option to preserve the progress bar
Joerg Sonnenberger <joerg@bec.de>
parents:
43118
diff
changeset
|
1226 stdout and stderr go to the same terminal. This can be skipped with |
82879e06c926
ui: option to preserve the progress bar
Joerg Sonnenberger <joerg@bec.de>
parents:
43118
diff
changeset
|
1227 the optional keyword argument "keepprogressbar". The progress bar |
82879e06c926
ui: option to preserve the progress bar
Joerg Sonnenberger <joerg@bec.de>
parents:
43118
diff
changeset
|
1228 will continue to occupy a partial line on stderr in that case. |
82879e06c926
ui: option to preserve the progress bar
Joerg Sonnenberger <joerg@bec.de>
parents:
43118
diff
changeset
|
1229 This functionality is intended when Mercurial acts as data source |
82879e06c926
ui: option to preserve the progress bar
Joerg Sonnenberger <joerg@bec.de>
parents:
43118
diff
changeset
|
1230 in a pipe. |
82879e06c926
ui: option to preserve the progress bar
Joerg Sonnenberger <joerg@bec.de>
parents:
43118
diff
changeset
|
1231 |
10815
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
1232 When labeling output for a specific command, a label of |
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
1233 "cmdname.type" is recommended. For example, status issues |
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
1234 a label of "status.modified" for modified files. |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1235 """ |
41305
b4a3abdc790d
ui: inline _write() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41304
diff
changeset
|
1236 dest = self._fout |
b4a3abdc790d
ui: inline _write() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41304
diff
changeset
|
1237 |
b4a3abdc790d
ui: inline _write() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41304
diff
changeset
|
1238 # inlined _write() for speed |
41307
26ee61c33dee
ui: remove unreachable branches and function calls from write() (issue6059)
Yuya Nishihara <yuya@tcha.org>
parents:
41306
diff
changeset
|
1239 if self._buffers: |
43554
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43377
diff
changeset
|
1240 label = opts.get('label', b'') |
41305
b4a3abdc790d
ui: inline _write() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41304
diff
changeset
|
1241 if label and self._bufferapplylabels: |
b4a3abdc790d
ui: inline _write() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41304
diff
changeset
|
1242 self._buffers[-1].extend(self.label(a, label) for a in args) |
b4a3abdc790d
ui: inline _write() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41304
diff
changeset
|
1243 else: |
b4a3abdc790d
ui: inline _write() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41304
diff
changeset
|
1244 self._buffers[-1].extend(args) |
41306
e8273eaa0726
ui: inline _writenobuf() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41305
diff
changeset
|
1245 return |
e8273eaa0726
ui: inline _writenobuf() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41305
diff
changeset
|
1246 |
43265
82879e06c926
ui: option to preserve the progress bar
Joerg Sonnenberger <joerg@bec.de>
parents:
43118
diff
changeset
|
1247 # inlined _writenobuf() for speed |
50487
7f0f3b274d1e
ui: keep the progress bar around when writing if stdout is not a tty
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50253
diff
changeset
|
1248 if not opts.get('keepprogressbar', self._fout_is_a_tty): |
43265
82879e06c926
ui: option to preserve the progress bar
Joerg Sonnenberger <joerg@bec.de>
parents:
43118
diff
changeset
|
1249 self._progclear() |
41306
e8273eaa0726
ui: inline _writenobuf() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41305
diff
changeset
|
1250 msg = b''.join(args) |
e8273eaa0726
ui: inline _writenobuf() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41305
diff
changeset
|
1251 |
e8273eaa0726
ui: inline _writenobuf() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41305
diff
changeset
|
1252 # opencode timeblockedsection because this is a critical path |
e8273eaa0726
ui: inline _writenobuf() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41305
diff
changeset
|
1253 starttime = util.timer() |
e8273eaa0726
ui: inline _writenobuf() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41305
diff
changeset
|
1254 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1255 if self._colormode == b'win32': |
41306
e8273eaa0726
ui: inline _writenobuf() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41305
diff
changeset
|
1256 # windows color printing is its own can of crab, defer to |
e8273eaa0726
ui: inline _writenobuf() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41305
diff
changeset
|
1257 # the color module and that is it. |
e8273eaa0726
ui: inline _writenobuf() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41305
diff
changeset
|
1258 color.win32print(self, dest.write, msg, **opts) |
e8273eaa0726
ui: inline _writenobuf() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41305
diff
changeset
|
1259 else: |
e8273eaa0726
ui: inline _writenobuf() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41305
diff
changeset
|
1260 if self._colormode is not None: |
43554
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43377
diff
changeset
|
1261 label = opts.get('label', b'') |
41306
e8273eaa0726
ui: inline _writenobuf() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41305
diff
changeset
|
1262 msg = self.label(msg, label) |
e8273eaa0726
ui: inline _writenobuf() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41305
diff
changeset
|
1263 dest.write(msg) |
52665
24ee91ba9aa8
pyupgrade: drop usage of py3 aliases for `OSError`
Matt Harbison <matt_harbison@yahoo.com>
parents:
52607
diff
changeset
|
1264 except OSError as err: |
41306
e8273eaa0726
ui: inline _writenobuf() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41305
diff
changeset
|
1265 raise error.StdioError(err) |
e8273eaa0726
ui: inline _writenobuf() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41305
diff
changeset
|
1266 finally: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1267 self._blockedtimes[b'stdio_blocked'] += ( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1268 util.timer() - starttime |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1269 ) * 1000 |
40591
c2aea007130b
ui: add inner function to select write destination
Yuya Nishihara <yuya@tcha.org>
parents:
40590
diff
changeset
|
1270 |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
1271 def write_err(self, *args: bytes, **opts: _MsgOpts) -> None: |
40593
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1272 self._write(self._ferr, *args, **opts) |
40591
c2aea007130b
ui: add inner function to select write destination
Yuya Nishihara <yuya@tcha.org>
parents:
40590
diff
changeset
|
1273 |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
1274 def _write(self, dest, *args: bytes, **opts: _MsgOpts) -> None: |
41305
b4a3abdc790d
ui: inline _write() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41304
diff
changeset
|
1275 # update write() as well if you touch this code |
40591
c2aea007130b
ui: add inner function to select write destination
Yuya Nishihara <yuya@tcha.org>
parents:
40590
diff
changeset
|
1276 if self._isbuffered(dest): |
43554
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43377
diff
changeset
|
1277 label = opts.get('label', b'') |
41304
ff927ecb12f9
ui: optimize buffered write with no label
Yuya Nishihara <yuya@tcha.org>
parents:
41285
diff
changeset
|
1278 if label and self._bufferapplylabels: |
31108
ad074f900907
color: move 'write' logic to the core ui class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31107
diff
changeset
|
1279 self._buffers[-1].extend(self.label(a, label) for a in args) |
ad074f900907
color: move 'write' logic to the core ui class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31107
diff
changeset
|
1280 else: |
ad074f900907
color: move 'write' logic to the core ui class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31107
diff
changeset
|
1281 self._buffers[-1].extend(args) |
35996
b62c4154bb28
ui: add explicit path to write prompt text bypassing buffers
Yuya Nishihara <yuya@tcha.org>
parents:
35995
diff
changeset
|
1282 else: |
40591
c2aea007130b
ui: add inner function to select write destination
Yuya Nishihara <yuya@tcha.org>
parents:
40590
diff
changeset
|
1283 self._writenobuf(dest, *args, **opts) |
35996
b62c4154bb28
ui: add explicit path to write prompt text bypassing buffers
Yuya Nishihara <yuya@tcha.org>
parents:
35995
diff
changeset
|
1284 |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
1285 def _writenobuf(self, dest, *args: bytes, **opts: _MsgOpts) -> None: |
41306
e8273eaa0726
ui: inline _writenobuf() into write() due to performance issue
Yuya Nishihara <yuya@tcha.org>
parents:
41305
diff
changeset
|
1286 # update write() as well if you touch this code |
50487
7f0f3b274d1e
ui: keep the progress bar around when writing if stdout is not a tty
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50253
diff
changeset
|
1287 if not opts.get('keepprogressbar', self._fout_is_a_tty): |
43265
82879e06c926
ui: option to preserve the progress bar
Joerg Sonnenberger <joerg@bec.de>
parents:
43118
diff
changeset
|
1288 self._progclear() |
40572
51091816a355
ui: simply concatenate messages before applying color labels
Yuya Nishihara <yuya@tcha.org>
parents:
40571
diff
changeset
|
1289 msg = b''.join(args) |
31107
e9f96ccf36a6
ui: extract the low level part of 'write' in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31104
diff
changeset
|
1290 |
31143
0bb3089fe735
ui: remove superfluous indent in _write()
Yuya Nishihara <yuya@tcha.org>
parents:
31139
diff
changeset
|
1291 # opencode timeblockedsection because this is a critical path |
0bb3089fe735
ui: remove superfluous indent in _write()
Yuya Nishihara <yuya@tcha.org>
parents:
31139
diff
changeset
|
1292 starttime = util.timer() |
0bb3089fe735
ui: remove superfluous indent in _write()
Yuya Nishihara <yuya@tcha.org>
parents:
31139
diff
changeset
|
1293 try: |
40593
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1294 if dest is self._ferr and not getattr(self._fout, 'closed', False): |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1295 self._fout.flush() |
40636
054d0fcba2c4
commandserver: add experimental option to use separate message channel
Yuya Nishihara <yuya@tcha.org>
parents:
40634
diff
changeset
|
1296 if getattr(dest, 'structured', False): |
054d0fcba2c4
commandserver: add experimental option to use separate message channel
Yuya Nishihara <yuya@tcha.org>
parents:
40634
diff
changeset
|
1297 # channel for machine-readable output with metadata, where |
054d0fcba2c4
commandserver: add experimental option to use separate message channel
Yuya Nishihara <yuya@tcha.org>
parents:
40634
diff
changeset
|
1298 # no extra colorization is necessary. |
054d0fcba2c4
commandserver: add experimental option to use separate message channel
Yuya Nishihara <yuya@tcha.org>
parents:
40634
diff
changeset
|
1299 dest.write(msg, **opts) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1300 elif self._colormode == b'win32': |
40573
0c7b2035a604
ui: indent _writenobuf() to prepare moving bits from _write() functions
Yuya Nishihara <yuya@tcha.org>
parents:
40572
diff
changeset
|
1301 # windows color printing is its own can of crab, defer to |
0c7b2035a604
ui: indent _writenobuf() to prepare moving bits from _write() functions
Yuya Nishihara <yuya@tcha.org>
parents:
40572
diff
changeset
|
1302 # the color module and that is it. |
40590
06e841e72523
ui: remove _write() and _write_err() functions
Yuya Nishihara <yuya@tcha.org>
parents:
40589
diff
changeset
|
1303 color.win32print(self, dest.write, msg, **opts) |
40573
0c7b2035a604
ui: indent _writenobuf() to prepare moving bits from _write() functions
Yuya Nishihara <yuya@tcha.org>
parents:
40572
diff
changeset
|
1304 else: |
0c7b2035a604
ui: indent _writenobuf() to prepare moving bits from _write() functions
Yuya Nishihara <yuya@tcha.org>
parents:
40572
diff
changeset
|
1305 if self._colormode is not None: |
43554
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43377
diff
changeset
|
1306 label = opts.get('label', b'') |
40573
0c7b2035a604
ui: indent _writenobuf() to prepare moving bits from _write() functions
Yuya Nishihara <yuya@tcha.org>
parents:
40572
diff
changeset
|
1307 msg = self.label(msg, label) |
40590
06e841e72523
ui: remove _write() and _write_err() functions
Yuya Nishihara <yuya@tcha.org>
parents:
40589
diff
changeset
|
1308 dest.write(msg) |
40589
04a9dd8da959
ui: move pre/post processes from low-level write()s to _writenobuf()
Yuya Nishihara <yuya@tcha.org>
parents:
40588
diff
changeset
|
1309 # stderr may be buffered under win32 when redirected to files, |
04a9dd8da959
ui: move pre/post processes from low-level write()s to _writenobuf()
Yuya Nishihara <yuya@tcha.org>
parents:
40588
diff
changeset
|
1310 # including stdout. |
45012
484e04dc7f42
ui: replace `self._ferr` with identical `dest`
Manuel Jacob <me@manueljacob.de>
parents:
44663
diff
changeset
|
1311 if dest is self._ferr and not getattr(dest, 'closed', False): |
40589
04a9dd8da959
ui: move pre/post processes from low-level write()s to _writenobuf()
Yuya Nishihara <yuya@tcha.org>
parents:
40588
diff
changeset
|
1312 dest.flush() |
52665
24ee91ba9aa8
pyupgrade: drop usage of py3 aliases for `OSError`
Matt Harbison <matt_harbison@yahoo.com>
parents:
52607
diff
changeset
|
1313 except OSError as err: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1314 if dest is self._ferr and err.errno in ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1315 errno.EPIPE, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1316 errno.EIO, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1317 errno.EBADF, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1318 ): |
40589
04a9dd8da959
ui: move pre/post processes from low-level write()s to _writenobuf()
Yuya Nishihara <yuya@tcha.org>
parents:
40588
diff
changeset
|
1319 # no way to report the error, so ignore it |
04a9dd8da959
ui: move pre/post processes from low-level write()s to _writenobuf()
Yuya Nishihara <yuya@tcha.org>
parents:
40588
diff
changeset
|
1320 return |
31961
db823e38a61c
stdio: raise StdioError if something goes wrong in ui._write
Bryan O'Sullivan <bryano@fb.com>
parents:
31958
diff
changeset
|
1321 raise error.StdioError(err) |
31143
0bb3089fe735
ui: remove superfluous indent in _write()
Yuya Nishihara <yuya@tcha.org>
parents:
31139
diff
changeset
|
1322 finally: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1323 self._blockedtimes[b'stdio_blocked'] += ( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1324 util.timer() - starttime |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1325 ) * 1000 |
565 | 1326 |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
1327 def _writemsg(self, dest, *args: bytes, **opts: _MsgOpts) -> None: |
45035
24b1a8eb73aa
ui: add option to timestamp status and diagnostic messages
Joerg Sonnenberger <joerg@bec.de>
parents:
45012
diff
changeset
|
1328 timestamp = self.showtimestamp and opts.get('type') in { |
24b1a8eb73aa
ui: add option to timestamp status and diagnostic messages
Joerg Sonnenberger <joerg@bec.de>
parents:
45012
diff
changeset
|
1329 b'debug', |
24b1a8eb73aa
ui: add option to timestamp status and diagnostic messages
Joerg Sonnenberger <joerg@bec.de>
parents:
45012
diff
changeset
|
1330 b'error', |
24b1a8eb73aa
ui: add option to timestamp status and diagnostic messages
Joerg Sonnenberger <joerg@bec.de>
parents:
45012
diff
changeset
|
1331 b'note', |
24b1a8eb73aa
ui: add option to timestamp status and diagnostic messages
Joerg Sonnenberger <joerg@bec.de>
parents:
45012
diff
changeset
|
1332 b'status', |
24b1a8eb73aa
ui: add option to timestamp status and diagnostic messages
Joerg Sonnenberger <joerg@bec.de>
parents:
45012
diff
changeset
|
1333 b'warning', |
24b1a8eb73aa
ui: add option to timestamp status and diagnostic messages
Joerg Sonnenberger <joerg@bec.de>
parents:
45012
diff
changeset
|
1334 } |
24b1a8eb73aa
ui: add option to timestamp status and diagnostic messages
Joerg Sonnenberger <joerg@bec.de>
parents:
45012
diff
changeset
|
1335 if timestamp: |
24b1a8eb73aa
ui: add option to timestamp status and diagnostic messages
Joerg Sonnenberger <joerg@bec.de>
parents:
45012
diff
changeset
|
1336 args = ( |
45037
b4b6ff83ed9c
ui: fix Python 2.7 support for ui.timestamp-output
Joerg Sonnenberger <joerg@bec.de>
parents:
45035
diff
changeset
|
1337 b'[%s] ' |
b4b6ff83ed9c
ui: fix Python 2.7 support for ui.timestamp-output
Joerg Sonnenberger <joerg@bec.de>
parents:
45035
diff
changeset
|
1338 % pycompat.bytestr(datetime.datetime.now().isoformat()), |
45035
24b1a8eb73aa
ui: add option to timestamp status and diagnostic messages
Joerg Sonnenberger <joerg@bec.de>
parents:
45012
diff
changeset
|
1339 ) + args |
40637
83dd8c63a0c6
ui: extract helpers to write message with type or label
Yuya Nishihara <yuya@tcha.org>
parents:
40636
diff
changeset
|
1340 _writemsgwith(self._write, dest, *args, **opts) |
45035
24b1a8eb73aa
ui: add option to timestamp status and diagnostic messages
Joerg Sonnenberger <joerg@bec.de>
parents:
45012
diff
changeset
|
1341 if timestamp: |
24b1a8eb73aa
ui: add option to timestamp status and diagnostic messages
Joerg Sonnenberger <joerg@bec.de>
parents:
45012
diff
changeset
|
1342 dest.flush() |
40637
83dd8c63a0c6
ui: extract helpers to write message with type or label
Yuya Nishihara <yuya@tcha.org>
parents:
40636
diff
changeset
|
1343 |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
1344 def _writemsgnobuf(self, dest, *args: bytes, **opts: _MsgOpts) -> None: |
40637
83dd8c63a0c6
ui: extract helpers to write message with type or label
Yuya Nishihara <yuya@tcha.org>
parents:
40636
diff
changeset
|
1345 _writemsgwith(self._writenobuf, dest, *args, **opts) |
83dd8c63a0c6
ui: extract helpers to write message with type or label
Yuya Nishihara <yuya@tcha.org>
parents:
40636
diff
changeset
|
1346 |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
1347 def flush(self) -> None: |
30998
fdecd24ca4dc
ui: log time spent blocked on stdio
Simon Farnsworth <simonfar@fb.com>
parents:
30996
diff
changeset
|
1348 # opencode timeblockedsection because this is a critical path |
fdecd24ca4dc
ui: log time spent blocked on stdio
Simon Farnsworth <simonfar@fb.com>
parents:
30996
diff
changeset
|
1349 starttime = util.timer() |
fdecd24ca4dc
ui: log time spent blocked on stdio
Simon Farnsworth <simonfar@fb.com>
parents:
30996
diff
changeset
|
1350 try: |
31963
1bfb9a63b98e
stdio: raise StdioError if something goes wrong in ui.flush
Bryan O'Sullivan <bryano@fb.com>
parents:
31962
diff
changeset
|
1351 try: |
40593
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1352 self._fout.flush() |
52665
24ee91ba9aa8
pyupgrade: drop usage of py3 aliases for `OSError`
Matt Harbison <matt_harbison@yahoo.com>
parents:
52607
diff
changeset
|
1353 except OSError as err: |
33668
cde4cfeb6e3e
ui: restore behavior to ignore some I/O errors (issue5658)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33625
diff
changeset
|
1354 if err.errno not in (errno.EPIPE, errno.EIO, errno.EBADF): |
cde4cfeb6e3e
ui: restore behavior to ignore some I/O errors (issue5658)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33625
diff
changeset
|
1355 raise error.StdioError(err) |
31963
1bfb9a63b98e
stdio: raise StdioError if something goes wrong in ui.flush
Bryan O'Sullivan <bryano@fb.com>
parents:
31962
diff
changeset
|
1356 finally: |
1bfb9a63b98e
stdio: raise StdioError if something goes wrong in ui.flush
Bryan O'Sullivan <bryano@fb.com>
parents:
31962
diff
changeset
|
1357 try: |
40593
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1358 self._ferr.flush() |
52665
24ee91ba9aa8
pyupgrade: drop usage of py3 aliases for `OSError`
Matt Harbison <matt_harbison@yahoo.com>
parents:
52607
diff
changeset
|
1359 except OSError as err: |
33668
cde4cfeb6e3e
ui: restore behavior to ignore some I/O errors (issue5658)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33625
diff
changeset
|
1360 if err.errno not in (errno.EPIPE, errno.EIO, errno.EBADF): |
cde4cfeb6e3e
ui: restore behavior to ignore some I/O errors (issue5658)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33625
diff
changeset
|
1361 raise error.StdioError(err) |
30998
fdecd24ca4dc
ui: log time spent blocked on stdio
Simon Farnsworth <simonfar@fb.com>
parents:
30996
diff
changeset
|
1362 finally: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1363 self._blockedtimes[b'stdio_blocked'] += ( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1364 util.timer() - starttime |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1365 ) * 1000 |
1837
6f67a4c93493
make ui flush output. this makes error happen if printing to /dev/full.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1637
diff
changeset
|
1366 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1367 def _isatty(self, fh) -> bool: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1368 if self.configbool(b'ui', b'nontty'): |
16751
2d432a1fc0db
ui: add _isatty method to easily disable cooked I/O
Matt Mackall <mpm@selenic.com>
parents:
16703
diff
changeset
|
1369 return False |
37123
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37122
diff
changeset
|
1370 return procutil.isatty(fh) |
1837
6f67a4c93493
make ui flush output. this makes error happen if printing to /dev/full.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1637
diff
changeset
|
1371 |
41285
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1372 def protectfinout(self): |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1373 """Duplicate ui streams and redirect original if they are stdio |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1374 |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1375 Returns (fin, fout) which point to the original ui fds, but may be |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1376 copy of them. The returned streams can be considered "owned" in that |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1377 print(), exec(), etc. never reach to them. |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1378 """ |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1379 if self._finoutredirected: |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1380 # if already redirected, protectstdio() would just create another |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1381 # nullfd pair, which is equivalent to returning self._fin/_fout. |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1382 return self._fin, self._fout |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1383 fin, fout = procutil.protectstdio(self._fin, self._fout) |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1384 self._finoutredirected = (fin, fout) != (self._fin, self._fout) |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1385 return fin, fout |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1386 |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1387 def restorefinout(self, fin, fout): |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1388 """Restore ui streams from possibly duplicated (fin, fout)""" |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1389 if (fin, fout) == (self._fin, self._fout): |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1390 return |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1391 procutil.restorestdio(self._fin, self._fout, fin, fout) |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1392 # protectfinout() won't create more than one duplicated streams, |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1393 # so we can just turn the redirection flag off. |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1394 self._finoutredirected = False |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1395 |
41284
b0e3f2d7c143
ui: move protectedstdio() context manager from procutil
Yuya Nishihara <yuya@tcha.org>
parents:
41225
diff
changeset
|
1396 @contextlib.contextmanager |
b0e3f2d7c143
ui: move protectedstdio() context manager from procutil
Yuya Nishihara <yuya@tcha.org>
parents:
41225
diff
changeset
|
1397 def protectedfinout(self): |
b0e3f2d7c143
ui: move protectedstdio() context manager from procutil
Yuya Nishihara <yuya@tcha.org>
parents:
41225
diff
changeset
|
1398 """Run code block with protected standard streams""" |
41285
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1399 fin, fout = self.protectfinout() |
41284
b0e3f2d7c143
ui: move protectedstdio() context manager from procutil
Yuya Nishihara <yuya@tcha.org>
parents:
41225
diff
changeset
|
1400 try: |
b0e3f2d7c143
ui: move protectedstdio() context manager from procutil
Yuya Nishihara <yuya@tcha.org>
parents:
41225
diff
changeset
|
1401 yield fin, fout |
b0e3f2d7c143
ui: move protectedstdio() context manager from procutil
Yuya Nishihara <yuya@tcha.org>
parents:
41225
diff
changeset
|
1402 finally: |
41285
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
41284
diff
changeset
|
1403 self.restorefinout(fin, fout) |
41284
b0e3f2d7c143
ui: move protectedstdio() context manager from procutil
Yuya Nishihara <yuya@tcha.org>
parents:
41225
diff
changeset
|
1404 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1405 def disablepager(self) -> None: |
31046
9c827087df38
ui: rename neverpager to disablepager
Augie Fackler <augie@google.com>
parents:
31034
diff
changeset
|
1406 self._disablepager = True |
31014
3ed6e43998df
ui: introduce neverpager() call
Augie Fackler <augie@google.com>
parents:
31012
diff
changeset
|
1407 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1408 def pager(self, command: bytes) -> None: |
31012
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1409 """Start a pager for subsequent command output. |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1410 |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1411 Commands which produce a long stream of output should call |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1412 this function to activate the user's preferred pagination |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1413 mechanism (which may be no pager). Calling this function |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1414 precludes any future use of interactive functionality, such as |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1415 prompting the user or activating curses. |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1416 |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1417 Args: |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1418 command: The full, non-aliased name of the command. That is, "log" |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1419 not "history, "summary" not "summ", etc. |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1420 """ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1421 if self._disablepager or self.pageractive: |
33618
cc047a733f69
ui: enable pager always for explicit --pager=on (issue5580)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33585
diff
changeset
|
1422 # how pager should do is already determined |
cc047a733f69
ui: enable pager always for explicit --pager=on (issue5580)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33585
diff
changeset
|
1423 return |
cc047a733f69
ui: enable pager always for explicit --pager=on (issue5580)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33585
diff
changeset
|
1424 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1425 if not command.startswith(b'internal-always-') and ( |
33618
cc047a733f69
ui: enable pager always for explicit --pager=on (issue5580)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33585
diff
changeset
|
1426 # explicit --pager=on (= 'internal-always-' prefix) should |
cc047a733f69
ui: enable pager always for explicit --pager=on (issue5580)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33585
diff
changeset
|
1427 # take precedence over disabling factors below |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1428 command in self.configlist(b'pager', b'ignore') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1429 or not self.configbool(b'ui', b'paginate') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1430 or not self.configbool(b'pager', b'attend-' + command, True) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1431 or encoding.environ.get(b'TERM') == b'dumb' |
31012
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1432 # TODO: if we want to allow HGPLAINEXCEPT=pager, |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1433 # formatted() will need some adjustment. |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1434 or not self.formatted() |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1435 or self.plain() |
34039
31a2eb0f74e5
pager: do not start pager if `ui` has been `pushbuffer`-ed
Jun Wu <quark@fb.com>
parents:
33884
diff
changeset
|
1436 or self._buffers |
31012
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1437 # TODO: expose debugger-enabled on the UI object |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1438 or b'--debugger' in pycompat.sysargv |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1439 ): |
31012
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1440 # We only want to paginate if the ui appears to be |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1441 # interactive, the user didn't say HGPLAIN or |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1442 # HGPLAINEXCEPT=pager, and the user didn't specify --debug. |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1443 return |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1444 |
49130
7afa96d3b484
windows: disable pager when packaged with py2exe
Matt Harbison <matt_harbison@yahoo.com>
parents:
49037
diff
changeset
|
1445 # py2exe doesn't appear to be able to use legacy I/O, and nothing is |
7afa96d3b484
windows: disable pager when packaged with py2exe
Matt Harbison <matt_harbison@yahoo.com>
parents:
49037
diff
changeset
|
1446 # output to the pager for paged commands. Piping to `more` in cmd.exe |
7afa96d3b484
windows: disable pager when packaged with py2exe
Matt Harbison <matt_harbison@yahoo.com>
parents:
49037
diff
changeset
|
1447 # works, but is easy to forget. Just disable pager for py2exe, but |
7afa96d3b484
windows: disable pager when packaged with py2exe
Matt Harbison <matt_harbison@yahoo.com>
parents:
49037
diff
changeset
|
1448 # leave it working for pyoxidizer and exewrapper builds. |
7afa96d3b484
windows: disable pager when packaged with py2exe
Matt Harbison <matt_harbison@yahoo.com>
parents:
49037
diff
changeset
|
1449 if pycompat.iswindows and getattr(sys, "frozen", None) == "console_exe": |
7afa96d3b484
windows: disable pager when packaged with py2exe
Matt Harbison <matt_harbison@yahoo.com>
parents:
49037
diff
changeset
|
1450 self.debug(b"pager is unavailable with py2exe packaging\n") |
7afa96d3b484
windows: disable pager when packaged with py2exe
Matt Harbison <matt_harbison@yahoo.com>
parents:
49037
diff
changeset
|
1451 return |
7afa96d3b484
windows: disable pager when packaged with py2exe
Matt Harbison <matt_harbison@yahoo.com>
parents:
49037
diff
changeset
|
1452 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1453 pagercmd = self.config(b'pager', b'pager', rcutil.fallbackpager) |
31096
873ebdd6e84d
pager: do not try to run an empty pager command
Yuya Nishihara <yuya@tcha.org>
parents:
31082
diff
changeset
|
1454 if not pagercmd: |
873ebdd6e84d
pager: do not try to run an empty pager command
Yuya Nishihara <yuya@tcha.org>
parents:
31082
diff
changeset
|
1455 return |
873ebdd6e84d
pager: do not try to run an empty pager command
Yuya Nishihara <yuya@tcha.org>
parents:
31082
diff
changeset
|
1456 |
31954
e518192d6bac
pager: set some environment variables if they're not set
Jun Wu <quark@fb.com>
parents:
31781
diff
changeset
|
1457 pagerenv = {} |
e518192d6bac
pager: set some environment variables if they're not set
Jun Wu <quark@fb.com>
parents:
31781
diff
changeset
|
1458 for name, value in rcutil.defaultpagerenv().items(): |
e518192d6bac
pager: set some environment variables if they're not set
Jun Wu <quark@fb.com>
parents:
31781
diff
changeset
|
1459 if name not in encoding.environ: |
e518192d6bac
pager: set some environment variables if they're not set
Jun Wu <quark@fb.com>
parents:
31781
diff
changeset
|
1460 pagerenv[name] = value |
e518192d6bac
pager: set some environment variables if they're not set
Jun Wu <quark@fb.com>
parents:
31781
diff
changeset
|
1461 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1462 self.debug( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1463 b'starting pager for command %s\n' % stringutil.pprint(command) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1464 ) |
31497
8122cc5cb543
pager: flush outputs before firing pager process
Yuya Nishihara <yuya@tcha.org>
parents:
31488
diff
changeset
|
1465 self.flush() |
31695
2d11d278279a
ui: defer setting pager related properties until the pager has spawned
Matt Harbison <matt_harbison@yahoo.com>
parents:
31693
diff
changeset
|
1466 |
2d11d278279a
ui: defer setting pager related properties until the pager has spawned
Matt Harbison <matt_harbison@yahoo.com>
parents:
31693
diff
changeset
|
1467 wasformatted = self.formatted() |
50951
d718eddf01d9
safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50921
diff
changeset
|
1468 if hasattr(signal, "SIGPIPE"): |
31012
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1469 signal.signal(signal.SIGPIPE, _catchterm) |
31954
e518192d6bac
pager: set some environment variables if they're not set
Jun Wu <quark@fb.com>
parents:
31781
diff
changeset
|
1470 if self._runpager(pagercmd, pagerenv): |
31695
2d11d278279a
ui: defer setting pager related properties until the pager has spawned
Matt Harbison <matt_harbison@yahoo.com>
parents:
31693
diff
changeset
|
1471 self.pageractive = True |
2d11d278279a
ui: defer setting pager related properties until the pager has spawned
Matt Harbison <matt_harbison@yahoo.com>
parents:
31693
diff
changeset
|
1472 # Preserve the formatted-ness of the UI. This is important |
2d11d278279a
ui: defer setting pager related properties until the pager has spawned
Matt Harbison <matt_harbison@yahoo.com>
parents:
31693
diff
changeset
|
1473 # because we mess with stdout, which might confuse |
2d11d278279a
ui: defer setting pager related properties until the pager has spawned
Matt Harbison <matt_harbison@yahoo.com>
parents:
31693
diff
changeset
|
1474 # auto-detection of things being formatted. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1475 self.setconfig(b'ui', b'formatted', wasformatted, b'pager') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1476 self.setconfig(b'ui', b'interactive', False, b'pager') |
31696
c3ca0ad8ab9c
ui: rerun color.setup() once the pager has spawned to honor 'color.pagermode'
Matt Harbison <matt_harbison@yahoo.com>
parents:
31695
diff
changeset
|
1477 |
c3ca0ad8ab9c
ui: rerun color.setup() once the pager has spawned to honor 'color.pagermode'
Matt Harbison <matt_harbison@yahoo.com>
parents:
31695
diff
changeset
|
1478 # If pagermode differs from color.mode, reconfigure color now that |
c3ca0ad8ab9c
ui: rerun color.setup() once the pager has spawned to honor 'color.pagermode'
Matt Harbison <matt_harbison@yahoo.com>
parents:
31695
diff
changeset
|
1479 # pageractive is set. |
c3ca0ad8ab9c
ui: rerun color.setup() once the pager has spawned to honor 'color.pagermode'
Matt Harbison <matt_harbison@yahoo.com>
parents:
31695
diff
changeset
|
1480 cm = self._colormode |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1481 if cm != self.config(b'color', b'pagermode', cm): |
31696
c3ca0ad8ab9c
ui: rerun color.setup() once the pager has spawned to honor 'color.pagermode'
Matt Harbison <matt_harbison@yahoo.com>
parents:
31695
diff
changeset
|
1482 color.setup(self) |
31695
2d11d278279a
ui: defer setting pager related properties until the pager has spawned
Matt Harbison <matt_harbison@yahoo.com>
parents:
31693
diff
changeset
|
1483 else: |
2d11d278279a
ui: defer setting pager related properties until the pager has spawned
Matt Harbison <matt_harbison@yahoo.com>
parents:
31693
diff
changeset
|
1484 # If the pager can't be spawned in dispatch when --pager=on is |
2d11d278279a
ui: defer setting pager related properties until the pager has spawned
Matt Harbison <matt_harbison@yahoo.com>
parents:
31693
diff
changeset
|
1485 # given, don't try again when the command runs, to avoid a duplicate |
2d11d278279a
ui: defer setting pager related properties until the pager has spawned
Matt Harbison <matt_harbison@yahoo.com>
parents:
31693
diff
changeset
|
1486 # warning about a missing pager command. |
2d11d278279a
ui: defer setting pager related properties until the pager has spawned
Matt Harbison <matt_harbison@yahoo.com>
parents:
31693
diff
changeset
|
1487 self.disablepager() |
31012
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1488 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1489 def _runpager(self, command: bytes, env=None) -> bool: |
31012
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1490 """Actually start the pager and set up file descriptors. |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1491 |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1492 This is separate in part so that extensions (like chg) can |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1493 override how a pager is invoked. |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1494 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1495 if command == b'cat': |
31486
96929bd6e58d
pager: skip running the pager if it's set to 'cat'
Augie Fackler <augie@google.com>
parents:
31485
diff
changeset
|
1496 # Save ourselves some work. |
31695
2d11d278279a
ui: defer setting pager related properties until the pager has spawned
Matt Harbison <matt_harbison@yahoo.com>
parents:
31693
diff
changeset
|
1497 return False |
31485
9335dc6b2a9c
pager: avoid shell=True on subprocess.Popen for better errors (issue5491)
Augie Fackler <augie@google.com>
parents:
31481
diff
changeset
|
1498 # If the command doesn't contain any of these characters, we |
9335dc6b2a9c
pager: avoid shell=True on subprocess.Popen for better errors (issue5491)
Augie Fackler <augie@google.com>
parents:
31481
diff
changeset
|
1499 # assume it's a binary and exec it directly. This means for |
9335dc6b2a9c
pager: avoid shell=True on subprocess.Popen for better errors (issue5491)
Augie Fackler <augie@google.com>
parents:
31481
diff
changeset
|
1500 # simple pager command configurations, we can degrade |
9335dc6b2a9c
pager: avoid shell=True on subprocess.Popen for better errors (issue5491)
Augie Fackler <augie@google.com>
parents:
31481
diff
changeset
|
1501 # gracefully and tell the user about their broken pager. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1502 shell = any(c in command for c in b"|&;<>()$`\\\"' \t\n*?[#~=%") |
31629
c60091fa1426
pager: improve support for various flavors of `more` on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
31597
diff
changeset
|
1503 |
34645 | 1504 if pycompat.iswindows and not shell: |
31629
c60091fa1426
pager: improve support for various flavors of `more` on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
31597
diff
changeset
|
1505 # Window's built-in `more` cannot be invoked with shell=False, but |
c60091fa1426
pager: improve support for various flavors of `more` on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
31597
diff
changeset
|
1506 # its `more.com` can. Hide this implementation detail from the |
c60091fa1426
pager: improve support for various flavors of `more` on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
31597
diff
changeset
|
1507 # user so we can also get sane bad PAGER behavior. MSYS has |
c60091fa1426
pager: improve support for various flavors of `more` on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
31597
diff
changeset
|
1508 # `more.exe`, so do a cmd.exe style resolution of the executable to |
c60091fa1426
pager: improve support for various flavors of `more` on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
31597
diff
changeset
|
1509 # determine which one to use. |
37123
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37122
diff
changeset
|
1510 fullcmd = procutil.findexe(command) |
31629
c60091fa1426
pager: improve support for various flavors of `more` on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
31597
diff
changeset
|
1511 if not fullcmd: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1512 self.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1513 _(b"missing pager command '%s', skipping pager\n") % command |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1514 ) |
31695
2d11d278279a
ui: defer setting pager related properties until the pager has spawned
Matt Harbison <matt_harbison@yahoo.com>
parents:
31693
diff
changeset
|
1515 return False |
31629
c60091fa1426
pager: improve support for various flavors of `more` on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
31597
diff
changeset
|
1516 |
c60091fa1426
pager: improve support for various flavors of `more` on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
31597
diff
changeset
|
1517 command = fullcmd |
c60091fa1426
pager: improve support for various flavors of `more` on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
31597
diff
changeset
|
1518 |
31485
9335dc6b2a9c
pager: avoid shell=True on subprocess.Popen for better errors (issue5491)
Augie Fackler <augie@google.com>
parents:
31481
diff
changeset
|
1519 try: |
9335dc6b2a9c
pager: avoid shell=True on subprocess.Popen for better errors (issue5491)
Augie Fackler <augie@google.com>
parents:
31481
diff
changeset
|
1520 pager = subprocess.Popen( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1521 procutil.tonativestr(command), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1522 shell=shell, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1523 bufsize=-1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1524 close_fds=procutil.closefds, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1525 stdin=subprocess.PIPE, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1526 stdout=procutil.stdout, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1527 stderr=procutil.stderr, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1528 env=procutil.tonativeenv(procutil.shellenviron(env)), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1529 ) |
49314
2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents:
49130
diff
changeset
|
1530 except FileNotFoundError: |
2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents:
49130
diff
changeset
|
1531 if not shell: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1532 self.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1533 _(b"missing pager command '%s', skipping pager\n") % command |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1534 ) |
31695
2d11d278279a
ui: defer setting pager related properties until the pager has spawned
Matt Harbison <matt_harbison@yahoo.com>
parents:
31693
diff
changeset
|
1535 return False |
31485
9335dc6b2a9c
pager: avoid shell=True on subprocess.Popen for better errors (issue5491)
Augie Fackler <augie@google.com>
parents:
31481
diff
changeset
|
1536 raise |
31012
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1537 |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1538 # back up original file descriptors |
51003
ce9cb12ca8c9
openvms: fix the pager spawning and cleanup
Jean-Francois Pieronne <jf.pieronne@laposte.net>
parents:
50952
diff
changeset
|
1539 if pycompat.sysplatform != b'OpenVMS': |
ce9cb12ca8c9
openvms: fix the pager spawning and cleanup
Jean-Francois Pieronne <jf.pieronne@laposte.net>
parents:
50952
diff
changeset
|
1540 stdoutfd = os.dup(procutil.stdout.fileno()) |
ce9cb12ca8c9
openvms: fix the pager spawning and cleanup
Jean-Francois Pieronne <jf.pieronne@laposte.net>
parents:
50952
diff
changeset
|
1541 stderrfd = os.dup(procutil.stderr.fileno()) |
31012
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1542 |
37122
d4a2e0d5d042
procutil: bulk-replace util.std* to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37087
diff
changeset
|
1543 os.dup2(pager.stdin.fileno(), procutil.stdout.fileno()) |
d4a2e0d5d042
procutil: bulk-replace util.std* to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37087
diff
changeset
|
1544 if self._isatty(procutil.stderr): |
d4a2e0d5d042
procutil: bulk-replace util.std* to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37087
diff
changeset
|
1545 os.dup2(pager.stdin.fileno(), procutil.stderr.fileno()) |
31012
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1546 |
31958
de5c9d0e02ea
atexit: switch to home-grown implementation
Bryan O'Sullivan <bryano@fb.com>
parents:
31956
diff
changeset
|
1547 @self.atexit |
31012
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1548 def killpager(): |
50951
d718eddf01d9
safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50921
diff
changeset
|
1549 if hasattr(signal, "SIGINT"): |
31012
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1550 signal.signal(signal.SIGINT, signal.SIG_IGN) |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1551 # restore original fds, closing pager.stdin copies in the process |
51003
ce9cb12ca8c9
openvms: fix the pager spawning and cleanup
Jean-Francois Pieronne <jf.pieronne@laposte.net>
parents:
50952
diff
changeset
|
1552 if pycompat.sysplatform == b'OpenVMS': |
ce9cb12ca8c9
openvms: fix the pager spawning and cleanup
Jean-Francois Pieronne <jf.pieronne@laposte.net>
parents:
50952
diff
changeset
|
1553 pager.kill() |
37122
d4a2e0d5d042
procutil: bulk-replace util.std* to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37087
diff
changeset
|
1554 os.dup2(stdoutfd, procutil.stdout.fileno()) |
d4a2e0d5d042
procutil: bulk-replace util.std* to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37087
diff
changeset
|
1555 os.dup2(stderrfd, procutil.stderr.fileno()) |
31012
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1556 pager.stdin.close() |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1557 pager.wait() |
61b4122019d3
pager: move pager-initiating code into core
Augie Fackler <augie@google.com>
parents:
31000
diff
changeset
|
1558 |
31695
2d11d278279a
ui: defer setting pager related properties until the pager has spawned
Matt Harbison <matt_harbison@yahoo.com>
parents:
31693
diff
changeset
|
1559 return True |
2d11d278279a
ui: defer setting pager related properties until the pager has spawned
Matt Harbison <matt_harbison@yahoo.com>
parents:
31693
diff
changeset
|
1560 |
34882
e9f320a40b44
ui: move request exit handlers to global state
Saurabh Singh <singhsrb@fb.com>
parents:
34858
diff
changeset
|
1561 @property |
e9f320a40b44
ui: move request exit handlers to global state
Saurabh Singh <singhsrb@fb.com>
parents:
34858
diff
changeset
|
1562 def _exithandlers(self): |
e9f320a40b44
ui: move request exit handlers to global state
Saurabh Singh <singhsrb@fb.com>
parents:
34858
diff
changeset
|
1563 return _reqexithandlers |
e9f320a40b44
ui: move request exit handlers to global state
Saurabh Singh <singhsrb@fb.com>
parents:
34858
diff
changeset
|
1564 |
31956
c13ff31818b0
ui: add special-purpose atexit functionality
Bryan O'Sullivan <bryano@fb.com>
parents:
31954
diff
changeset
|
1565 def atexit(self, func, *args, **kwargs): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1566 """register a function to run after dispatching a request |
31956
c13ff31818b0
ui: add special-purpose atexit functionality
Bryan O'Sullivan <bryano@fb.com>
parents:
31954
diff
changeset
|
1567 |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1568 Handlers do not stay registered across request boundaries.""" |
31956
c13ff31818b0
ui: add special-purpose atexit functionality
Bryan O'Sullivan <bryano@fb.com>
parents:
31954
diff
changeset
|
1569 self._exithandlers.append((func, args, kwargs)) |
c13ff31818b0
ui: add special-purpose atexit functionality
Bryan O'Sullivan <bryano@fb.com>
parents:
31954
diff
changeset
|
1570 return func |
c13ff31818b0
ui: add special-purpose atexit functionality
Bryan O'Sullivan <bryano@fb.com>
parents:
31954
diff
changeset
|
1571 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1572 def interface(self, feature: bytes) -> bytes: |
28542
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1573 """what interface to use for interactive console features? |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1574 |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1575 The interface is controlled by the value of `ui.interface` but also by |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1576 the value of feature-specific configuration. For example: |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1577 |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1578 ui.interface.histedit = text |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1579 ui.interface.chunkselector = curses |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1580 |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1581 Here the features are "histedit" and "chunkselector". |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1582 |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1583 The configuration above means that the default interfaces for commands |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1584 is curses, the interface for histedit is text and the interface for |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1585 selecting chunk is crecord (the best curses interface available). |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1586 |
30342
318a24b52eeb
spelling: fixes of non-dictionary words
Mads Kiilerich <madski@unity3d.com>
parents:
30327
diff
changeset
|
1587 Consider the following example: |
28542
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1588 ui.interface = curses |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1589 ui.interface.histedit = text |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1590 |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1591 Then histedit will use the text interface and chunkselector will use |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1592 the default curses interface (crecord at the moment). |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1593 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1594 alldefaults = frozenset([b"text", b"curses"]) |
28542
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1595 |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1596 featureinterfaces = { |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1597 b"chunkselector": [ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1598 b"text", |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1599 b"curses", |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1600 ], |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1601 b"histedit": [ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1602 b"text", |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1603 b"curses", |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1604 ], |
28542
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1605 } |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1606 |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1607 # Feature-specific interface |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1608 if feature not in featureinterfaces.keys(): |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1609 # Programming error, not user error |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1610 raise ValueError(b"Unknown feature requested %s" % feature) |
28542
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1611 |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1612 availableinterfaces = frozenset(featureinterfaces[feature]) |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1613 if alldefaults > availableinterfaces: |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1614 # Programming error, not user error. We need a use case to |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1615 # define the right thing to do here. |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1616 raise ValueError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1617 b"Feature %s does not handle all default interfaces" % feature |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1618 ) |
28542
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1619 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1620 if self.plain() or encoding.environ.get(b'TERM') == b'dumb': |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1621 return b"text" |
28542
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1622 |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1623 # Default interface for all the features |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1624 defaultinterface = b"text" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1625 i = self.config(b"ui", b"interface") |
28542
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1626 if i in alldefaults: |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1627 defaultinterface = cast(bytes, i) # cast to help pytype |
28542
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1628 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1629 choseninterface: bytes = defaultinterface |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1630 f = self.config(b"ui", b"interface.%s" % feature) |
28542
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1631 if f in availableinterfaces: |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1632 choseninterface = cast(bytes, f) # cast to help pytype |
28542
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1633 |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1634 if i is not None and defaultinterface != i: |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1635 if f is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1636 self.warn(_(b"invalid value for ui.interface: %s\n") % (i,)) |
28542
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1637 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1638 self.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1639 _(b"invalid value for ui.interface: %s (using %s)\n") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1640 % (i, choseninterface) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1641 ) |
28542
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1642 if f is not None and choseninterface != f: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1643 self.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1644 _(b"invalid value for ui.interface.%s: %s (using %s)\n") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1645 % (feature, f, choseninterface) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1646 ) |
28542
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1647 |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1648 return choseninterface |
71e12fc53b80
ui: add new config flag for interface selection
Simon Farnsworth <simonfar@fb.com>
parents:
28498
diff
changeset
|
1649 |
8208
32a2a1e244f1
ui: make interactive a method
Matt Mackall <mpm@selenic.com>
parents:
8206
diff
changeset
|
1650 def interactive(self): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1651 """is interactive input allowed? |
11325
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1652 |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1653 An interactive session is a session where input can be reasonably read |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1654 from `sys.stdin'. If this function returns false, any attempt to read |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1655 from stdin should fail with an error, unless a sensible default has been |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1656 specified. |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1657 |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1658 Interactiveness is triggered by the value of the `ui.interactive' |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1659 configuration variable or - if it is unset - when `sys.stdin' points |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1660 to a terminal device. |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1661 |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1662 This function refers to input only; for output, see `ui.formatted()'. |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1663 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1664 i = self.configbool(b"ui", b"interactive") |
8538
6419bc7b3d9c
ui: honor interactive=off even if isatty()
Patrick Mezard <pmezard@gmail.com>
parents:
8527
diff
changeset
|
1665 if i is None: |
14515
76f295eaed86
util: add helper function isatty(fd) to check for tty-ness
Idan Kamara <idankk86@gmail.com>
parents:
14373
diff
changeset
|
1666 # some environments replace stdin without implementing isatty |
76f295eaed86
util: add helper function isatty(fd) to check for tty-ness
Idan Kamara <idankk86@gmail.com>
parents:
14373
diff
changeset
|
1667 # usually those are non-interactive |
40593
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1668 return self._isatty(self._fin) |
10077
89617aacb495
make ui.interactive() return false in case stdin lacks isatty
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
9887
diff
changeset
|
1669 |
8538
6419bc7b3d9c
ui: honor interactive=off even if isatty()
Patrick Mezard <pmezard@gmail.com>
parents:
8527
diff
changeset
|
1670 return i |
8208
32a2a1e244f1
ui: make interactive a method
Matt Mackall <mpm@selenic.com>
parents:
8206
diff
changeset
|
1671 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1672 def termwidth(self) -> int: |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1673 """how wide is the terminal in columns?""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1674 if b'COLUMNS' in encoding.environ: |
12689
c52c629ce19e
termwidth: move to ui.ui from util
Augie Fackler <durin42@gmail.com>
parents:
12665
diff
changeset
|
1675 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1676 return int(encoding.environ[b'COLUMNS']) |
12689
c52c629ce19e
termwidth: move to ui.ui from util
Augie Fackler <durin42@gmail.com>
parents:
12665
diff
changeset
|
1677 except ValueError: |
c52c629ce19e
termwidth: move to ui.ui from util
Augie Fackler <durin42@gmail.com>
parents:
12665
diff
changeset
|
1678 pass |
30327
365812902904
scmutil: extend termwidth() to return terminal height, renamed to termsize()
Yuya Nishihara <yuya@tcha.org>
parents:
30323
diff
changeset
|
1679 return scmutil.termsize(self)[0] |
12689
c52c629ce19e
termwidth: move to ui.ui from util
Augie Fackler <durin42@gmail.com>
parents:
12665
diff
changeset
|
1680 |
11324
cdf6d861b207
ui: add ui.formatted configuration variable and accessor function.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11311
diff
changeset
|
1681 def formatted(self): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1682 """should formatted output be used? |
11325
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1683 |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1684 It is often desirable to format the output to suite the output medium. |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1685 Examples of this are truncating long lines or colorizing messages. |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1686 However, this is not often not desirable when piping output into other |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1687 utilities, e.g. `grep'. |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1688 |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1689 Formatted output is triggered by the value of the `ui.formatted' |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1690 configuration variable or - if it is unset - when `sys.stdout' points |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1691 to a terminal device. Please note that `ui.formatted' should be |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1692 considered an implementation detail; it is not intended for use outside |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1693 Mercurial or its extensions. |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1694 |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1695 This function refers to output only; for input, see `ui.interactive()'. |
22a737306ba5
ui: document the formatted(), interactive() & plain() functions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11324
diff
changeset
|
1696 This function always returns false when in plain mode, see `ui.plain()'. |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1697 """ |
11324
cdf6d861b207
ui: add ui.formatted configuration variable and accessor function.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11311
diff
changeset
|
1698 if self.plain(): |
cdf6d861b207
ui: add ui.formatted configuration variable and accessor function.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11311
diff
changeset
|
1699 return False |
cdf6d861b207
ui: add ui.formatted configuration variable and accessor function.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11311
diff
changeset
|
1700 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1701 i = self.configbool(b"ui", b"formatted") |
11324
cdf6d861b207
ui: add ui.formatted configuration variable and accessor function.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11311
diff
changeset
|
1702 if i is None: |
14515
76f295eaed86
util: add helper function isatty(fd) to check for tty-ness
Idan Kamara <idankk86@gmail.com>
parents:
14373
diff
changeset
|
1703 # some environments replace stdout without implementing isatty |
76f295eaed86
util: add helper function isatty(fd) to check for tty-ness
Idan Kamara <idankk86@gmail.com>
parents:
14373
diff
changeset
|
1704 # usually those are non-interactive |
40593
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1705 return self._isatty(self._fout) |
11324
cdf6d861b207
ui: add ui.formatted configuration variable and accessor function.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11311
diff
changeset
|
1706 |
cdf6d861b207
ui: add ui.formatted configuration variable and accessor function.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11311
diff
changeset
|
1707 return i |
cdf6d861b207
ui: add ui.formatted configuration variable and accessor function.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
11311
diff
changeset
|
1708 |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
1709 def _readline( |
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
1710 self, |
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
1711 prompt: bytes = b' ', |
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
1712 promptopts: Optional[Dict[str, _MsgOpts]] = None, |
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
1713 ) -> bytes: |
36803
9b513888ea23
ui: do not use rawinput() when we have to replace sys.stdin/stdout
Yuya Nishihara <yuya@tcha.org>
parents:
36802
diff
changeset
|
1714 # Replacing stdin/stdout temporarily is a hard problem on Python 3 |
9b513888ea23
ui: do not use rawinput() when we have to replace sys.stdin/stdout
Yuya Nishihara <yuya@tcha.org>
parents:
36802
diff
changeset
|
1715 # because they have to be text streams with *no buffering*. Instead, |
9b513888ea23
ui: do not use rawinput() when we have to replace sys.stdin/stdout
Yuya Nishihara <yuya@tcha.org>
parents:
36802
diff
changeset
|
1716 # we use rawinput() only if call_readline() will be invoked by |
9b513888ea23
ui: do not use rawinput() when we have to replace sys.stdin/stdout
Yuya Nishihara <yuya@tcha.org>
parents:
36802
diff
changeset
|
1717 # PyOS_Readline(), so no I/O will be made at Python layer. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1718 usereadline = ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1719 self._isatty(self._fin) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1720 and self._isatty(self._fout) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1721 and procutil.isstdin(self._fin) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1722 and procutil.isstdout(self._fout) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1723 ) |
36802
fa53a1d1f16e
ui: do not try readline support if fin/fout aren't standard streams
Yuya Nishihara <yuya@tcha.org>
parents:
36799
diff
changeset
|
1724 if usereadline: |
5036
ca0d02222d6a
ui: get readline and prompt to behave better depending on interactivity
Bryan O'Sullivan <bos@serpentine.com>
parents:
4729
diff
changeset
|
1725 try: |
ca0d02222d6a
ui: get readline and prompt to behave better depending on interactivity
Bryan O'Sullivan <bos@serpentine.com>
parents:
4729
diff
changeset
|
1726 # magically add command line editing support, where |
ca0d02222d6a
ui: get readline and prompt to behave better depending on interactivity
Bryan O'Sullivan <bos@serpentine.com>
parents:
4729
diff
changeset
|
1727 # available |
ca0d02222d6a
ui: get readline and prompt to behave better depending on interactivity
Bryan O'Sullivan <bos@serpentine.com>
parents:
4729
diff
changeset
|
1728 import readline |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1729 |
5036
ca0d02222d6a
ui: get readline and prompt to behave better depending on interactivity
Bryan O'Sullivan <bos@serpentine.com>
parents:
4729
diff
changeset
|
1730 # force demandimport to really load the module |
ca0d02222d6a
ui: get readline and prompt to behave better depending on interactivity
Bryan O'Sullivan <bos@serpentine.com>
parents:
4729
diff
changeset
|
1731 readline.read_history_file |
7496
0a27d0db256d
issue1419: catch strange readline import error on windows
Brendan Cully <brendan@kublai.com>
parents:
7320
diff
changeset
|
1732 # windows sometimes raises something other than ImportError |
0a27d0db256d
issue1419: catch strange readline import error on windows
Brendan Cully <brendan@kublai.com>
parents:
7320
diff
changeset
|
1733 except Exception: |
36802
fa53a1d1f16e
ui: do not try readline support if fin/fout aren't standard streams
Yuya Nishihara <yuya@tcha.org>
parents:
36799
diff
changeset
|
1734 usereadline = False |
14614
afccc64eea73
ui: use I/O descriptors internally
Idan Kamara <idankk86@gmail.com>
parents:
14612
diff
changeset
|
1735 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1736 if self._colormode == b'win32' or not usereadline: |
42119
2d428b859282
readline: provide styled prompt to readline (issue6070)
Kyle Lippincott <spectral@google.com>
parents:
41999
diff
changeset
|
1737 if not promptopts: |
2d428b859282
readline: provide styled prompt to readline (issue6070)
Kyle Lippincott <spectral@google.com>
parents:
41999
diff
changeset
|
1738 promptopts = {} |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1739 self._writemsgnobuf( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1740 self._fmsgout, prompt, type=b'prompt', **promptopts |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1741 ) |
42119
2d428b859282
readline: provide styled prompt to readline (issue6070)
Kyle Lippincott <spectral@google.com>
parents:
41999
diff
changeset
|
1742 self.flush() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1743 prompt = b' ' |
42119
2d428b859282
readline: provide styled prompt to readline (issue6070)
Kyle Lippincott <spectral@google.com>
parents:
41999
diff
changeset
|
1744 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1745 prompt = self.label(prompt, b'ui.prompt') + b' ' |
42119
2d428b859282
readline: provide styled prompt to readline (issue6070)
Kyle Lippincott <spectral@google.com>
parents:
41999
diff
changeset
|
1746 |
22291
3b39e1522d8f
ui: add brief comment why raw_input() needs dummy ' ' prompt string
Yuya Nishihara <yuya@tcha.org>
parents:
22205
diff
changeset
|
1747 # prompt ' ' must exist; otherwise readline may delete entire line |
3b39e1522d8f
ui: add brief comment why raw_input() needs dummy ' ' prompt string
Yuya Nishihara <yuya@tcha.org>
parents:
22205
diff
changeset
|
1748 # - http://bugs.python.org/issue12833 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1749 with self.timeblockedsection(b'stdio'): |
36803
9b513888ea23
ui: do not use rawinput() when we have to replace sys.stdin/stdout
Yuya Nishihara <yuya@tcha.org>
parents:
36802
diff
changeset
|
1750 if usereadline: |
43377
aaa046919043
ui: flush before prompting for input with readline
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43265
diff
changeset
|
1751 self.flush() |
43118
57efd5bd2ca2
py3: decode prompt string before calling rawinput
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
43106
diff
changeset
|
1752 prompt = encoding.strfromlocal(prompt) |
49024
78f1de3f4be7
ui: use input() directly
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48966
diff
changeset
|
1753 line = encoding.strtolocal(input(prompt)) |
36804
aa0fc12743c7
ui: adjust Windows workaround to new _readline() code
Yuya Nishihara <yuya@tcha.org>
parents:
36803
diff
changeset
|
1754 # When stdin is in binary mode on Windows, it can cause |
49024
78f1de3f4be7
ui: use input() directly
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48966
diff
changeset
|
1755 # input() to emit an extra trailing carriage return |
36804
aa0fc12743c7
ui: adjust Windows workaround to new _readline() code
Yuya Nishihara <yuya@tcha.org>
parents:
36803
diff
changeset
|
1756 if pycompat.oslinesep == b'\r\n' and line.endswith(b'\r'): |
aa0fc12743c7
ui: adjust Windows workaround to new _readline() code
Yuya Nishihara <yuya@tcha.org>
parents:
36803
diff
changeset
|
1757 line = line[:-1] |
36803
9b513888ea23
ui: do not use rawinput() when we have to replace sys.stdin/stdout
Yuya Nishihara <yuya@tcha.org>
parents:
36802
diff
changeset
|
1758 else: |
42119
2d428b859282
readline: provide styled prompt to readline (issue6070)
Kyle Lippincott <spectral@google.com>
parents:
41999
diff
changeset
|
1759 self._fout.write(pycompat.bytestr(prompt)) |
40593
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1760 self._fout.flush() |
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1761 line = self._fin.readline() |
36803
9b513888ea23
ui: do not use rawinput() when we have to replace sys.stdin/stdout
Yuya Nishihara <yuya@tcha.org>
parents:
36802
diff
changeset
|
1762 if not line: |
9b513888ea23
ui: do not use rawinput() when we have to replace sys.stdin/stdout
Yuya Nishihara <yuya@tcha.org>
parents:
36802
diff
changeset
|
1763 raise EOFError |
36842
1527f40de3b3
ui: remove any combinations of CR|LF from prompt response
Yuya Nishihara <yuya@tcha.org>
parents:
36804
diff
changeset
|
1764 line = line.rstrip(pycompat.oslinesep) |
14614
afccc64eea73
ui: use I/O descriptors internally
Idan Kamara <idankk86@gmail.com>
parents:
14612
diff
changeset
|
1765 |
5613
2e76e5a23c2b
workaround for raw_input() on Windows
Steve Borho <steve@borho.org>
parents:
5337
diff
changeset
|
1766 return line |
5036
ca0d02222d6a
ui: get readline and prompt to behave better depending on interactivity
Bryan O'Sullivan <bos@serpentine.com>
parents:
4729
diff
changeset
|
1767 |
51302
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51003
diff
changeset
|
1768 if typing.TYPE_CHECKING: |
49894
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
1769 |
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
1770 @overload |
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
1771 def prompt(self, msg: bytes, default: bytes) -> bytes: |
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
1772 pass |
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
1773 |
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
1774 @overload |
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
1775 def prompt(self, msg: bytes, default: None) -> Optional[bytes]: |
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
1776 pass |
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
1777 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1778 def prompt(self, msg, default=b"y"): |
9048
86b4a9b0ddda
ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents:
8940
diff
changeset
|
1779 """Prompt user with msg, read response. |
86b4a9b0ddda
ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents:
8940
diff
changeset
|
1780 If ui is not interactive, the default is returned. |
5751 | 1781 """ |
40639
83e571ea06a9
commandserver: attach prompt default and choices to message
Yuya Nishihara <yuya@tcha.org>
parents:
40637
diff
changeset
|
1782 return self._prompt(msg, default=default) |
83e571ea06a9
commandserver: attach prompt default and choices to message
Yuya Nishihara <yuya@tcha.org>
parents:
40637
diff
changeset
|
1783 |
51302
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51003
diff
changeset
|
1784 if typing.TYPE_CHECKING: |
49894
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
1785 |
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
1786 @overload |
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
1787 def _prompt( |
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
1788 self, msg: bytes, default: bytes, **opts: _MsgOpts |
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
1789 ) -> bytes: |
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
1790 pass |
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
1791 |
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
1792 @overload |
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
1793 def _prompt( |
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
1794 self, msg: bytes, default: None, **opts: _MsgOpts |
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
1795 ) -> Optional[bytes]: |
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
1796 pass |
de284a0b5614
typing: add type hints to the prompt methods in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49893
diff
changeset
|
1797 |
49893
a51328ba33ca
ui: split the `default` arg out of **kwargs for the internal prompt method
Matt Harbison <matt_harbison@yahoo.com>
parents:
49892
diff
changeset
|
1798 def _prompt(self, msg, default=b'y', **opts): |
a51328ba33ca
ui: split the `default` arg out of **kwargs for the internal prompt method
Matt Harbison <matt_harbison@yahoo.com>
parents:
49892
diff
changeset
|
1799 opts = {**opts, 'default': default} |
8208
32a2a1e244f1
ui: make interactive a method
Matt Mackall <mpm@selenic.com>
parents:
8206
diff
changeset
|
1800 if not self.interactive(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1801 self._writemsg(self._fmsgout, msg, b' ', type=b'prompt', **opts) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1802 self._writemsg( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1803 self._fmsgout, default or b'', b"\n", type=b'promptecho' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1804 ) |
7320
8dca507e56ce
ui: log non-interactive default response to stdout when verbose
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
6862
diff
changeset
|
1805 return default |
9048
86b4a9b0ddda
ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents:
8940
diff
changeset
|
1806 try: |
42119
2d428b859282
readline: provide styled prompt to readline (issue6070)
Kyle Lippincott <spectral@google.com>
parents:
41999
diff
changeset
|
1807 r = self._readline(prompt=msg, promptopts=opts) |
9048
86b4a9b0ddda
ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents:
8940
diff
changeset
|
1808 if not r: |
22589
9ab18a912c44
ui: show prompt choice if input is not a tty but is forced to be interactive
Mads Kiilerich <madski@unity3d.com>
parents:
22419
diff
changeset
|
1809 r = default |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1810 if self.configbool(b'ui', b'promptecho'): |
45757
14ac6a74e7e7
ui: fix echo back of ui.prompt() to not concatenate None as bytes
Yuya Nishihara <yuya@tcha.org>
parents:
45062
diff
changeset
|
1811 self._writemsg( |
14ac6a74e7e7
ui: fix echo back of ui.prompt() to not concatenate None as bytes
Yuya Nishihara <yuya@tcha.org>
parents:
45062
diff
changeset
|
1812 self._fmsgout, r or b'', b"\n", type=b'promptecho' |
14ac6a74e7e7
ui: fix echo back of ui.prompt() to not concatenate None as bytes
Yuya Nishihara <yuya@tcha.org>
parents:
45062
diff
changeset
|
1813 ) |
9048
86b4a9b0ddda
ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents:
8940
diff
changeset
|
1814 return r |
86b4a9b0ddda
ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents:
8940
diff
changeset
|
1815 except EOFError: |
26896
5e46123e6c35
error: add structured exception for EOF at prompt
Siddharth Agarwal <sid0@fb.com>
parents:
26820
diff
changeset
|
1816 raise error.ResponseExpected() |
9048
86b4a9b0ddda
ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents:
8940
diff
changeset
|
1817 |
20265
e5803150ea1d
ui: add "extractchoices()" to share the logic to extract choices from prompt
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19886
diff
changeset
|
1818 @staticmethod |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
1819 def extractchoices(prompt: bytes) -> Tuple[bytes, List[_PromptChoice]]: |
20265
e5803150ea1d
ui: add "extractchoices()" to share the logic to extract choices from prompt
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19886
diff
changeset
|
1820 """Extract prompt message and list of choices from specified prompt. |
e5803150ea1d
ui: add "extractchoices()" to share the logic to extract choices from prompt
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19886
diff
changeset
|
1821 |
e5803150ea1d
ui: add "extractchoices()" to share the logic to extract choices from prompt
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19886
diff
changeset
|
1822 This returns tuple "(message, choices)", and "choices" is the |
e5803150ea1d
ui: add "extractchoices()" to share the logic to extract choices from prompt
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19886
diff
changeset
|
1823 list of tuple "(response character, text without &)". |
27392
00aa37c65e0a
ui: try to handle $$ more robustly in prompts (issue4970)
Matt Mackall <mpm@selenic.com>
parents:
26820
diff
changeset
|
1824 |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
1825 >>> ui.extractchoices(b"awake? $$ &Yes $$ &No") |
27392
00aa37c65e0a
ui: try to handle $$ more robustly in prompts (issue4970)
Matt Mackall <mpm@selenic.com>
parents:
26820
diff
changeset
|
1826 ('awake? ', [('y', 'Yes'), ('n', 'No')]) |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
1827 >>> ui.extractchoices(b"line\\nbreak? $$ &Yes $$ &No") |
27392
00aa37c65e0a
ui: try to handle $$ more robustly in prompts (issue4970)
Matt Mackall <mpm@selenic.com>
parents:
26820
diff
changeset
|
1828 ('line\\nbreak? ', [('y', 'Yes'), ('n', 'No')]) |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34071
diff
changeset
|
1829 >>> ui.extractchoices(b"want lots of $$money$$?$$Ye&s$$N&o") |
27392
00aa37c65e0a
ui: try to handle $$ more robustly in prompts (issue4970)
Matt Mackall <mpm@selenic.com>
parents:
26820
diff
changeset
|
1830 ('want lots of $$money$$?', [('s', 'Yes'), ('o', 'No')]) |
20265
e5803150ea1d
ui: add "extractchoices()" to share the logic to extract choices from prompt
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19886
diff
changeset
|
1831 """ |
27392
00aa37c65e0a
ui: try to handle $$ more robustly in prompts (issue4970)
Matt Mackall <mpm@selenic.com>
parents:
26820
diff
changeset
|
1832 |
00aa37c65e0a
ui: try to handle $$ more robustly in prompts (issue4970)
Matt Mackall <mpm@selenic.com>
parents:
26820
diff
changeset
|
1833 # Sadly, the prompt string may have been built with a filename |
00aa37c65e0a
ui: try to handle $$ more robustly in prompts (issue4970)
Matt Mackall <mpm@selenic.com>
parents:
26820
diff
changeset
|
1834 # containing "$$" so let's try to find the first valid-looking |
00aa37c65e0a
ui: try to handle $$ more robustly in prompts (issue4970)
Matt Mackall <mpm@selenic.com>
parents:
26820
diff
changeset
|
1835 # prompt to start parsing. Sadly, we also can't rely on |
00aa37c65e0a
ui: try to handle $$ more robustly in prompts (issue4970)
Matt Mackall <mpm@selenic.com>
parents:
26820
diff
changeset
|
1836 # choices containing spaces, ASCII, or basically anything |
00aa37c65e0a
ui: try to handle $$ more robustly in prompts (issue4970)
Matt Mackall <mpm@selenic.com>
parents:
26820
diff
changeset
|
1837 # except an ampersand followed by a character. |
44023
6d3b67a837a6
cleanup: drop redundant character escapes from `[]` character sets
Matt Harbison <matt_harbison@yahoo.com>
parents:
43996
diff
changeset
|
1838 m = re.match(br'(?s)(.+?)\$\$([^$]*&[^ $].*)', prompt) |
49888
8147abc05794
pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49314
diff
changeset
|
1839 |
8147abc05794
pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49314
diff
changeset
|
1840 assert m is not None # help pytype |
8147abc05794
pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49314
diff
changeset
|
1841 |
27392
00aa37c65e0a
ui: try to handle $$ more robustly in prompts (issue4970)
Matt Mackall <mpm@selenic.com>
parents:
26820
diff
changeset
|
1842 msg = m.group(1) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1843 choices = [p.strip(b' ') for p in m.group(2).split(b'$$')] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1844 |
33740
d880a6bcef2f
ui: refactor extractchoices so it doesn't break on Python 3
Augie Fackler <augie@google.com>
parents:
33713
diff
changeset
|
1845 def choicetuple(s): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1846 ampidx = s.index(b'&') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1847 return s[ampidx + 1 : ampidx + 2].lower(), s.replace(b'&', b'', 1) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1848 |
33740
d880a6bcef2f
ui: refactor extractchoices so it doesn't break on Python 3
Augie Fackler <augie@google.com>
parents:
33713
diff
changeset
|
1849 return (msg, [choicetuple(s) for s in choices]) |
20265
e5803150ea1d
ui: add "extractchoices()" to share the logic to extract choices from prompt
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19886
diff
changeset
|
1850 |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
1851 def promptchoice(self, prompt: bytes, default: int = 0) -> int: |
19226
c58b6ab4c26f
ui: merge prompt text components into a singe string
Matt Mackall <mpm@selenic.com>
parents:
19195
diff
changeset
|
1852 """Prompt user with a message, read response, and ensure it matches |
c58b6ab4c26f
ui: merge prompt text components into a singe string
Matt Mackall <mpm@selenic.com>
parents:
19195
diff
changeset
|
1853 one of the provided choices. The prompt is formatted as follows: |
c58b6ab4c26f
ui: merge prompt text components into a singe string
Matt Mackall <mpm@selenic.com>
parents:
19195
diff
changeset
|
1854 |
c58b6ab4c26f
ui: merge prompt text components into a singe string
Matt Mackall <mpm@selenic.com>
parents:
19195
diff
changeset
|
1855 "would you like fries with that (Yn)? $$ &Yes $$ &No" |
c58b6ab4c26f
ui: merge prompt text components into a singe string
Matt Mackall <mpm@selenic.com>
parents:
19195
diff
changeset
|
1856 |
c58b6ab4c26f
ui: merge prompt text components into a singe string
Matt Mackall <mpm@selenic.com>
parents:
19195
diff
changeset
|
1857 The index of the choice is returned. Responses are case |
c58b6ab4c26f
ui: merge prompt text components into a singe string
Matt Mackall <mpm@selenic.com>
parents:
19195
diff
changeset
|
1858 insensitive. If ui is not interactive, the default is |
c58b6ab4c26f
ui: merge prompt text components into a singe string
Matt Mackall <mpm@selenic.com>
parents:
19195
diff
changeset
|
1859 returned. |
9048
86b4a9b0ddda
ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents:
8940
diff
changeset
|
1860 """ |
19226
c58b6ab4c26f
ui: merge prompt text components into a singe string
Matt Mackall <mpm@selenic.com>
parents:
19195
diff
changeset
|
1861 |
20265
e5803150ea1d
ui: add "extractchoices()" to share the logic to extract choices from prompt
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19886
diff
changeset
|
1862 msg, choices = self.extractchoices(prompt) |
e5803150ea1d
ui: add "extractchoices()" to share the logic to extract choices from prompt
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19886
diff
changeset
|
1863 resps = [r for r, t in choices] |
5671
b5605d88dc27
Make ui.prompt repeat on "unrecognized response" again (issue897)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5337
diff
changeset
|
1864 while True: |
40639
83e571ea06a9
commandserver: attach prompt default and choices to message
Yuya Nishihara <yuya@tcha.org>
parents:
40637
diff
changeset
|
1865 r = self._prompt(msg, default=resps[default], choices=choices) |
9048
86b4a9b0ddda
ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents:
8940
diff
changeset
|
1866 if r.lower() in resps: |
86b4a9b0ddda
ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents:
8940
diff
changeset
|
1867 return resps.index(r.lower()) |
40594
840cd57cde32
ui: add config knob to redirect status messages to stderr (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40593
diff
changeset
|
1868 # TODO: shouldn't it be a warning? |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1869 self._writemsg(self._fmsgout, _(b"unrecognized response\n")) |
9048
86b4a9b0ddda
ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents:
8940
diff
changeset
|
1870 |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
1871 def getpass( |
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
1872 self, prompt: Optional[bytes] = None, default: Optional[bytes] = None |
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
1873 ) -> Optional[bytes]: |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1874 if not self.interactive(): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1875 return default |
7798
57fee79e5588
catch CTRL-D at password prompt
Steve Borho <steve@borho.org>
parents:
7600
diff
changeset
|
1876 try: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1877 self._writemsg( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1878 self._fmsgerr, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1879 prompt or _(b'password: '), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1880 type=b'prompt', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1881 password=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1882 ) |
21195
9336bc7dca8e
cmdserver: forcibly use L channel to read password input (issue3161)
Yuya Nishihara <yuya@tcha.org>
parents:
21132
diff
changeset
|
1883 # disable getpass() only if explicitly specified. it's still valid |
9336bc7dca8e
cmdserver: forcibly use L channel to read password input (issue3161)
Yuya Nishihara <yuya@tcha.org>
parents:
21132
diff
changeset
|
1884 # to interact with tty even if fin is not a tty. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1885 with self.timeblockedsection(b'stdio'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1886 if self.configbool(b'ui', b'nontty'): |
40593
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
1887 l = self._fin.readline() |
30998
fdecd24ca4dc
ui: log time spent blocked on stdio
Simon Farnsworth <simonfar@fb.com>
parents:
30996
diff
changeset
|
1888 if not l: |
fdecd24ca4dc
ui: log time spent blocked on stdio
Simon Farnsworth <simonfar@fb.com>
parents:
30996
diff
changeset
|
1889 raise EOFError |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1890 return l.rstrip(b'\n') |
30998
fdecd24ca4dc
ui: log time spent blocked on stdio
Simon Farnsworth <simonfar@fb.com>
parents:
30996
diff
changeset
|
1891 else: |
47038
5b3513177f2b
util: avoid echoing the password to the console on Windows py3 (issue6446)
Matt Harbison <matt_harbison@yahoo.com>
parents:
46965
diff
changeset
|
1892 return util.get_password() |
7798
57fee79e5588
catch CTRL-D at password prompt
Steve Borho <steve@borho.org>
parents:
7600
diff
changeset
|
1893 except EOFError: |
26896
5e46123e6c35
error: add structured exception for EOF at prompt
Siddharth Agarwal <sid0@fb.com>
parents:
26820
diff
changeset
|
1894 raise error.ResponseExpected() |
38809
afc4ad706f9c
dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
38808
diff
changeset
|
1895 |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
1896 def status(self, *msg: bytes, **opts: _MsgOpts) -> None: |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1897 """write status message to output (if ui.quiet is False) |
10815
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
1898 |
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
1899 This adds an output label of "ui.status". |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1900 """ |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1901 if not self.quiet: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1902 self._writemsg(self._fmsgout, type=b'status', *msg, **opts) |
38809
afc4ad706f9c
dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
38808
diff
changeset
|
1903 |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
1904 def warn(self, *msg: bytes, **opts: _MsgOpts) -> None: |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1905 """write warning message to output (stderr) |
10815
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
1906 |
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
1907 This adds an output label of "ui.warning". |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1908 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1909 self._writemsg(self._fmsgerr, type=b'warning', *msg, **opts) |
38809
afc4ad706f9c
dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
38808
diff
changeset
|
1910 |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
1911 def error(self, *msg: bytes, **opts: _MsgOpts) -> None: |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1912 """write error message to output (stderr) |
38809
afc4ad706f9c
dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
38808
diff
changeset
|
1913 |
afc4ad706f9c
dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
38808
diff
changeset
|
1914 This adds an output label of "ui.error". |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1915 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1916 self._writemsg(self._fmsgerr, type=b'error', *msg, **opts) |
38809
afc4ad706f9c
dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
38808
diff
changeset
|
1917 |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
1918 def note(self, *msg: bytes, **opts: _MsgOpts) -> None: |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1919 """write note to output (if ui.verbose is True) |
10815
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
1920 |
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
1921 This adds an output label of "ui.note". |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1922 """ |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1923 if self.verbose: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1924 self._writemsg(self._fmsgout, type=b'note', *msg, **opts) |
38809
afc4ad706f9c
dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
38808
diff
changeset
|
1925 |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
1926 def debug(self, *msg: bytes, **opts: _MsgOpts) -> None: |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1927 """write debug message to output (if ui.debugflag is True) |
10815
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
1928 |
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
1929 This adds an output label of "ui.debug". |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
1930 """ |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1931 if self.debugflag: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1932 self._writemsg(self._fmsgout, type=b'debug', *msg, **opts) |
40793
fdc6eb1d650d
blackbox: send debug message to logger by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40764
diff
changeset
|
1933 self.log(b'debug', b'%s', b''.join(msg)) |
26750
9f9ec4abe700
cmdutil: make in-memory changes visible to external editor (issue4378)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26587
diff
changeset
|
1934 |
43079
5209fc94b982
ui: define (write|status|warn|note)noi18n aliases
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
1935 # Aliases to defeat check-code. |
5209fc94b982
ui: define (write|status|warn|note)noi18n aliases
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
1936 statusnoi18n = status |
5209fc94b982
ui: define (write|status|warn|note)noi18n aliases
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
1937 notenoi18n = note |
5209fc94b982
ui: define (write|status|warn|note)noi18n aliases
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
1938 warnnoi18n = warn |
5209fc94b982
ui: define (write|status|warn|note)noi18n aliases
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
1939 writenoi18n = write |
5209fc94b982
ui: define (write|status|warn|note)noi18n aliases
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
1940 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1941 def edit( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1942 self, |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1943 text: bytes, |
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1944 user: bytes, |
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1945 extra: Optional[Dict[bytes, Any]] = None, # TODO: value type of bytes? |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1946 editform=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1947 pending=None, |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1948 repopath: Optional[bytes] = None, |
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1949 action: Optional[bytes] = None, |
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
1950 ) -> bytes: |
34046
6e6452bc441d
editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
34039
diff
changeset
|
1951 if action is None: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1952 self.develwarn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1953 b'action is None but will soon be a required ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1954 b'parameter to ui.edit()' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1955 ) |
28635
87f92d6f0bc3
edit: allow to configure the suffix of the temporary filename
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
28633
diff
changeset
|
1956 extra_defaults = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1957 b'prefix': b'editor', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1958 b'suffix': b'.txt', |
28635
87f92d6f0bc3
edit: allow to configure the suffix of the temporary filename
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
28633
diff
changeset
|
1959 } |
27153
3553e40d0770
ui: allow open editor with custom filename
Mykola Nikishov <mn@mn.com.ua>
parents:
27110
diff
changeset
|
1960 if extra is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1961 if extra.get(b'suffix') is not None: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1962 self.develwarn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1963 b'extra.suffix is not None but will soon be ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1964 b'ignored by ui.edit()' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1965 ) |
27153
3553e40d0770
ui: allow open editor with custom filename
Mykola Nikishov <mn@mn.com.ua>
parents:
27110
diff
changeset
|
1966 extra_defaults.update(extra) |
3553e40d0770
ui: allow open editor with custom filename
Mykola Nikishov <mn@mn.com.ua>
parents:
27110
diff
changeset
|
1967 extra = extra_defaults |
30835
bcad61a1f9a7
ui: add a parameter to set the temporary directory for edit
Sean Farley <sean@farley.io>
parents:
30832
diff
changeset
|
1968 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1969 if action == b'diff': |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1970 suffix = b'.diff' |
34071
3c82b14d2838
editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents:
34046
diff
changeset
|
1971 elif action: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1972 suffix = b'.%s.hg.txt' % action |
34046
6e6452bc441d
editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
34039
diff
changeset
|
1973 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1974 suffix = extra[b'suffix'] |
34046
6e6452bc441d
editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
34039
diff
changeset
|
1975 |
30848
7080652af6e6
ui: rename tmpdir parameter to more specific repopath
Sean Farley <sean@farley.io>
parents:
30835
diff
changeset
|
1976 rdir = None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1977 if self.configbool(b'experimental', b'editortmpinhg'): |
30848
7080652af6e6
ui: rename tmpdir parameter to more specific repopath
Sean Farley <sean@farley.io>
parents:
30835
diff
changeset
|
1978 rdir = repopath |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1979 (fd, name) = pycompat.mkstemp( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1980 prefix=b'hg-' + extra[b'prefix'] + b'-', suffix=suffix, dir=rdir |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
1981 ) |
1984
df7436f439a0
Improved ui.edit():
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1983
diff
changeset
|
1982 try: |
43882
e5f69e3bb3f6
ui: use a context manager to handle file streams in edit()
Matt Harbison <matt_harbison@yahoo.com>
parents:
43807
diff
changeset
|
1983 with os.fdopen(fd, 'wb') as f: |
e5f69e3bb3f6
ui: use a context manager to handle file streams in edit()
Matt Harbison <matt_harbison@yahoo.com>
parents:
43807
diff
changeset
|
1984 f.write(util.tonativeeol(text)) |
1984
df7436f439a0
Improved ui.edit():
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1983
diff
changeset
|
1985 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1986 environ = {b'HGUSER': user} |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1987 if b'transplant_source' in extra: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1988 environ.update( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1989 {b'HGREVISION': hex(extra[b'transplant_source'])} |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1990 ) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1991 for label in (b'intermediate-source', b'source', b'rebase_source'): |
20605
a8aa699a812a
ui: edit(): rebase, graft: set HGREVISION environment variable for an editor
Alexander Drozdov <al.drozdov@gmail.com>
parents:
20603
diff
changeset
|
1992 if label in extra: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1993 environ.update({b'HGREVISION': extra[label]}) |
20605
a8aa699a812a
ui: edit(): rebase, graft: set HGREVISION environment variable for an editor
Alexander Drozdov <al.drozdov@gmail.com>
parents:
20603
diff
changeset
|
1994 break |
22205
9fa429723f26
ui: invoke editor for committing with HGEDITFORM environment variable
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21955
diff
changeset
|
1995 if editform: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1996 environ.update({b'HGEDITFORM': editform}) |
26750
9f9ec4abe700
cmdutil: make in-memory changes visible to external editor (issue4378)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26587
diff
changeset
|
1997 if pending: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1998 environ.update({b'HG_PENDING': pending}) |
20605
a8aa699a812a
ui: edit(): rebase, graft: set HGREVISION environment variable for an editor
Alexander Drozdov <al.drozdov@gmail.com>
parents:
20603
diff
changeset
|
1999 |
5660
3c80ecdc1bcd
Use VISUAL in addition to EDITOR when choosing the editor to use.
Osku Salerma <osku@iki.fi>
parents:
5613
diff
changeset
|
2000 editor = self.geteditor() |
207 | 2001 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2002 self.system( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2003 b"%s \"%s\"" % (editor, name), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2004 environ=environ, |
45892
ac362d5a7893
errors: introduce CanceledError and use it in a few places
Martin von Zweigbergk <martinvonz@google.com>
parents:
45845
diff
changeset
|
2005 onerr=error.CanceledError, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2006 errprefix=_(b"edit failed"), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2007 blockedtag=b'editor', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2008 ) |
608
d2994b5298fb
Add username/merge/editor to .hgrc
Matt Mackall <mpm@selenic.com>
parents:
565
diff
changeset
|
2009 |
52607
cc918741a22a
ui: replace a trivial file read with the `util` function
Matt Harbison <matt_harbison@yahoo.com>
parents:
52568
diff
changeset
|
2010 t = util.fromnativeeol(util.readfile(name)) |
1984
df7436f439a0
Improved ui.edit():
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1983
diff
changeset
|
2011 finally: |
df7436f439a0
Improved ui.edit():
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1983
diff
changeset
|
2012 os.unlink(name) |
662
b55a78595ef6
Pass username to hgeditor, remove temporary file
Radoslaw "AstralStorm" Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
613
diff
changeset
|
2013 |
207 | 2014 return t |
2200
9f43b6e24232
move mail sending code into core, so extensions can share it.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2166
diff
changeset
|
2015 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2016 def system( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2017 self, |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
2018 cmd: bytes, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2019 environ=None, |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
2020 cwd: Optional[bytes] = None, |
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
2021 onerr: Optional[Callable[[bytes], Exception]] = None, |
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
2022 errprefix: Optional[bytes] = None, |
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
2023 blockedtag: Optional[bytes] = None, |
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
2024 ) -> int: |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
2025 """execute shell command with appropriate output stream. command |
23269
d9d8d2e0f701
ui: introduce util.system() wrapper to make sure ui.fout is used
Yuya Nishihara <yuya@tcha.org>
parents:
23139
diff
changeset
|
2026 output will be redirected if fout is not stdout. |
31125
3f8f53190d6a
chg: deduplicate error handling of ui.system()
Yuya Nishihara <yuya@tcha.org>
parents:
31124
diff
changeset
|
2027 |
3f8f53190d6a
chg: deduplicate error handling of ui.system()
Yuya Nishihara <yuya@tcha.org>
parents:
31124
diff
changeset
|
2028 if command fails and onerr is None, return status, else raise onerr |
3f8f53190d6a
chg: deduplicate error handling of ui.system()
Yuya Nishihara <yuya@tcha.org>
parents:
31124
diff
changeset
|
2029 object as exception. |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
2030 """ |
30999
fd598149112b
ui: time calls to ui.system
Simon Farnsworth <simonfar@fb.com>
parents:
30998
diff
changeset
|
2031 if blockedtag is None: |
31541
d0f95ecca2ad
ui: restrict length of autogenerated blocked tags
Simon Farnsworth <simonfar@fb.com>
parents:
31538
diff
changeset
|
2032 # Long cmds tend to be because of an absolute path on cmd. Keep |
d0f95ecca2ad
ui: restrict length of autogenerated blocked tags
Simon Farnsworth <simonfar@fb.com>
parents:
31538
diff
changeset
|
2033 # the tail end instead |
d0f95ecca2ad
ui: restrict length of autogenerated blocked tags
Simon Farnsworth <simonfar@fb.com>
parents:
31538
diff
changeset
|
2034 cmdsuffix = cmd.translate(None, _keepalnum)[-85:] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2035 blockedtag = b'unknown_system_' + cmdsuffix |
40593
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
2036 out = self._fout |
25149
3f0744eeaeaf
cleanup: use __builtins__.any instead of util.any
Augie Fackler <augie@google.com>
parents:
25125
diff
changeset
|
2037 if any(s[1] for s in self._bufferstates): |
24848
2f88821856eb
ui: allow capture of subprocess output
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24687
diff
changeset
|
2038 out = self |
30999
fd598149112b
ui: time calls to ui.system
Simon Farnsworth <simonfar@fb.com>
parents:
30998
diff
changeset
|
2039 with self.timeblockedsection(blockedtag): |
31125
3f8f53190d6a
chg: deduplicate error handling of ui.system()
Yuya Nishihara <yuya@tcha.org>
parents:
31124
diff
changeset
|
2040 rc = self._runsystem(cmd, environ=environ, cwd=cwd, out=out) |
3f8f53190d6a
chg: deduplicate error handling of ui.system()
Yuya Nishihara <yuya@tcha.org>
parents:
31124
diff
changeset
|
2041 if rc and onerr: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2042 errmsg = b'%s %s' % ( |
44589
b746a22349f9
ui: use "procutil.shellsplit" to parse command
Micha Wiedenmann <mw-u2@posteo.de>
parents:
44239
diff
changeset
|
2043 procutil.shellsplit(cmd)[0], |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2044 procutil.explainexit(rc), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2045 ) |
31125
3f8f53190d6a
chg: deduplicate error handling of ui.system()
Yuya Nishihara <yuya@tcha.org>
parents:
31124
diff
changeset
|
2046 if errprefix: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2047 errmsg = b'%s: %s' % (errprefix, errmsg) |
31125
3f8f53190d6a
chg: deduplicate error handling of ui.system()
Yuya Nishihara <yuya@tcha.org>
parents:
31124
diff
changeset
|
2048 raise onerr(errmsg) |
3f8f53190d6a
chg: deduplicate error handling of ui.system()
Yuya Nishihara <yuya@tcha.org>
parents:
31124
diff
changeset
|
2049 return rc |
31124
fbce78c58f1e
chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents:
31123
diff
changeset
|
2050 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
2051 def _runsystem(self, cmd: bytes, environ, cwd: Optional[bytes], out) -> int: |
31124
fbce78c58f1e
chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents:
31123
diff
changeset
|
2052 """actually execute the given shell command (can be overridden by |
fbce78c58f1e
chg: refactor ui.system() to be partly overridden
Yuya Nishihara <yuya@tcha.org>
parents:
31123
diff
changeset
|
2053 extensions like chg)""" |
37123
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37122
diff
changeset
|
2054 return procutil.system(cmd, environ=environ, cwd=cwd, out=out) |
23269
d9d8d2e0f701
ui: introduce util.system() wrapper to make sure ui.fout is used
Yuya Nishihara <yuya@tcha.org>
parents:
23139
diff
changeset
|
2055 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
2056 def traceback(self, exc=None, force: bool = False): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
2057 """print exception traceback if traceback printing enabled or forced. |
2335
f0680b2d1d64
add ui.print_exc(), make all traceback printing central.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2293
diff
changeset
|
2058 only to call in exception handler. returns true if traceback |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
2059 printed.""" |
18966
5572f688e0a9
ui: add 'force' parameter to traceback() to override the current print setting
Matt Harbison <matt_harbison@yahoo.com>
parents:
18965
diff
changeset
|
2060 if self.tracebackflag or force: |
18965
0062508b1900
ui: add support for fully printing chained exception stacks in ui.traceback()
Matt Harbison <matt_harbison@yahoo.com>
parents:
18669
diff
changeset
|
2061 if exc is None: |
0062508b1900
ui: add support for fully printing chained exception stacks in ui.traceback()
Matt Harbison <matt_harbison@yahoo.com>
parents:
18669
diff
changeset
|
2062 exc = sys.exc_info() |
0062508b1900
ui: add support for fully printing chained exception stacks in ui.traceback()
Matt Harbison <matt_harbison@yahoo.com>
parents:
18669
diff
changeset
|
2063 cause = getattr(exc[1], 'cause', None) |
0062508b1900
ui: add support for fully printing chained exception stacks in ui.traceback()
Matt Harbison <matt_harbison@yahoo.com>
parents:
18669
diff
changeset
|
2064 |
0062508b1900
ui: add support for fully printing chained exception stacks in ui.traceback()
Matt Harbison <matt_harbison@yahoo.com>
parents:
18669
diff
changeset
|
2065 if cause is not None: |
0062508b1900
ui: add support for fully printing chained exception stacks in ui.traceback()
Matt Harbison <matt_harbison@yahoo.com>
parents:
18669
diff
changeset
|
2066 causetb = traceback.format_tb(cause[2]) |
0062508b1900
ui: add support for fully printing chained exception stacks in ui.traceback()
Matt Harbison <matt_harbison@yahoo.com>
parents:
18669
diff
changeset
|
2067 exctb = traceback.format_tb(exc[2]) |
0062508b1900
ui: add support for fully printing chained exception stacks in ui.traceback()
Matt Harbison <matt_harbison@yahoo.com>
parents:
18669
diff
changeset
|
2068 exconly = traceback.format_exception_only(cause[0], cause[1]) |
0062508b1900
ui: add support for fully printing chained exception stacks in ui.traceback()
Matt Harbison <matt_harbison@yahoo.com>
parents:
18669
diff
changeset
|
2069 |
0062508b1900
ui: add support for fully printing chained exception stacks in ui.traceback()
Matt Harbison <matt_harbison@yahoo.com>
parents:
18669
diff
changeset
|
2070 # exclude frame where 'exc' was chained and rethrown from exctb |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2071 self.write_err( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2072 b'Traceback (most recent call last):\n', |
43883
e63b27fb0595
ui: convert exception data to bytes when printing chained exception info
Matt Harbison <matt_harbison@yahoo.com>
parents:
43882
diff
changeset
|
2073 encoding.strtolocal(''.join(exctb[:-1])), |
e63b27fb0595
ui: convert exception data to bytes when printing chained exception info
Matt Harbison <matt_harbison@yahoo.com>
parents:
43882
diff
changeset
|
2074 encoding.strtolocal(''.join(causetb)), |
e63b27fb0595
ui: convert exception data to bytes when printing chained exception info
Matt Harbison <matt_harbison@yahoo.com>
parents:
43882
diff
changeset
|
2075 encoding.strtolocal(''.join(exconly)), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2076 ) |
18965
0062508b1900
ui: add support for fully printing chained exception stacks in ui.traceback()
Matt Harbison <matt_harbison@yahoo.com>
parents:
18669
diff
changeset
|
2077 else: |
25568
c1ff82daed62
ui: flush stderr after printing a non-chained exception for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
25519
diff
changeset
|
2078 output = traceback.format_exception(exc[0], exc[1], exc[2]) |
43554
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43377
diff
changeset
|
2079 self.write_err(encoding.strtolocal(''.join(output))) |
18966
5572f688e0a9
ui: add 'force' parameter to traceback() to override the current print setting
Matt Harbison <matt_harbison@yahoo.com>
parents:
18965
diff
changeset
|
2080 return self.tracebackflag or force |
5660
3c80ecdc1bcd
Use VISUAL in addition to EDITOR when choosing the editor to use.
Osku Salerma <osku@iki.fi>
parents:
5613
diff
changeset
|
2081 |
3c80ecdc1bcd
Use VISUAL in addition to EDITOR when choosing the editor to use.
Osku Salerma <osku@iki.fi>
parents:
5613
diff
changeset
|
2082 def geteditor(self): |
3c80ecdc1bcd
Use VISUAL in addition to EDITOR when choosing the editor to use.
Osku Salerma <osku@iki.fi>
parents:
5613
diff
changeset
|
2083 '''return editor to use''' |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2084 if pycompat.sysplatform == b'plan9': |
16383
f5dd179bfa4a
plan9: initial support for plan 9 from bell labs
Steven Stallion <sstallion@gmail.com>
parents:
16373
diff
changeset
|
2085 # vi is the MIPS instruction simulator on Plan 9. We |
f5dd179bfa4a
plan9: initial support for plan 9 from bell labs
Steven Stallion <sstallion@gmail.com>
parents:
16373
diff
changeset
|
2086 # instead default to E to plumb commit messages to |
f5dd179bfa4a
plan9: initial support for plan 9 from bell labs
Steven Stallion <sstallion@gmail.com>
parents:
16373
diff
changeset
|
2087 # avoid confusion. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2088 editor = b'E' |
44213
c23877cb25a5
darwin: use vim, not vi, to avoid data-loss inducing posix behavior
Kyle Lippincott <spectral@google.com>
parents:
44126
diff
changeset
|
2089 elif pycompat.isdarwin: |
c23877cb25a5
darwin: use vim, not vi, to avoid data-loss inducing posix behavior
Kyle Lippincott <spectral@google.com>
parents:
44126
diff
changeset
|
2090 # vi on darwin is POSIX compatible to a fault, and that includes |
c23877cb25a5
darwin: use vim, not vi, to avoid data-loss inducing posix behavior
Kyle Lippincott <spectral@google.com>
parents:
44126
diff
changeset
|
2091 # exiting non-zero if you make any mistake when running an ex |
c23877cb25a5
darwin: use vim, not vi, to avoid data-loss inducing posix behavior
Kyle Lippincott <spectral@google.com>
parents:
44126
diff
changeset
|
2092 # command. Proof: `vi -c ':unknown' -c ':qa'; echo $?` produces 1, |
c23877cb25a5
darwin: use vim, not vi, to avoid data-loss inducing posix behavior
Kyle Lippincott <spectral@google.com>
parents:
44126
diff
changeset
|
2093 # while s/vi/vim/ doesn't. |
c23877cb25a5
darwin: use vim, not vi, to avoid data-loss inducing posix behavior
Kyle Lippincott <spectral@google.com>
parents:
44126
diff
changeset
|
2094 editor = b'vim' |
52568
8986a3a8147a
ui: set the default editor on Windows to notepad.exe
Matt Harbison <matt_harbison@yahoo.com>
parents:
52457
diff
changeset
|
2095 elif pycompat.iswindows: |
8986a3a8147a
ui: set the default editor on Windows to notepad.exe
Matt Harbison <matt_harbison@yahoo.com>
parents:
52457
diff
changeset
|
2096 # vi isn't installed by on Windows, while notepad.exe is. |
8986a3a8147a
ui: set the default editor on Windows to notepad.exe
Matt Harbison <matt_harbison@yahoo.com>
parents:
52457
diff
changeset
|
2097 editor = b'notepad.exe' |
16383
f5dd179bfa4a
plan9: initial support for plan 9 from bell labs
Steven Stallion <sstallion@gmail.com>
parents:
16373
diff
changeset
|
2098 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2099 editor = b'vi' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2100 return encoding.environ.get(b"HGEDITOR") or self.config( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2101 b"ui", b"editor", editor |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2102 ) |
9153 | 2103 |
25499
0fa964d6fd48
progress: move all logic altering the ui object logic in mercurial.ui
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25498
diff
changeset
|
2104 @util.propertycache |
49889
25fe689a4a64
typing: add type hints related to progress bars in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49888
diff
changeset
|
2105 def _progbar(self) -> Optional[progress.progbar]: |
25499
0fa964d6fd48
progress: move all logic altering the ui object logic in mercurial.ui
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25498
diff
changeset
|
2106 """setup the progbar singleton to the ui object""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2107 if ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2108 self.quiet |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2109 or self.debugflag |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2110 or self.configbool(b'progress', b'disable') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2111 or not progress.shouldprint(self) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2112 ): |
25499
0fa964d6fd48
progress: move all logic altering the ui object logic in mercurial.ui
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25498
diff
changeset
|
2113 return None |
0fa964d6fd48
progress: move all logic altering the ui object logic in mercurial.ui
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25498
diff
changeset
|
2114 return getprogbar(self) |
0fa964d6fd48
progress: move all logic altering the ui object logic in mercurial.ui
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25498
diff
changeset
|
2115 |
49889
25fe689a4a64
typing: add type hints related to progress bars in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49888
diff
changeset
|
2116 def _progclear(self) -> None: |
25499
0fa964d6fd48
progress: move all logic altering the ui object logic in mercurial.ui
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25498
diff
changeset
|
2117 """clear progress bar output if any. use it before any output""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2118 if not haveprogbar(): # nothing loaded yet |
25499
0fa964d6fd48
progress: move all logic altering the ui object logic in mercurial.ui
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25498
diff
changeset
|
2119 return |
0fa964d6fd48
progress: move all logic altering the ui object logic in mercurial.ui
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25498
diff
changeset
|
2120 if self._progbar is not None and self._progbar.printed: |
0fa964d6fd48
progress: move all logic altering the ui object logic in mercurial.ui
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25498
diff
changeset
|
2121 self._progbar.clear() |
0fa964d6fd48
progress: move all logic altering the ui object logic in mercurial.ui
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25498
diff
changeset
|
2122 |
49889
25fe689a4a64
typing: add type hints related to progress bars in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49888
diff
changeset
|
2123 def makeprogress( |
25fe689a4a64
typing: add type hints related to progress bars in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49888
diff
changeset
|
2124 self, topic: bytes, unit: bytes = b"", total: Optional[int] = None |
25fe689a4a64
typing: add type hints related to progress bars in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49888
diff
changeset
|
2125 ) -> scmutil.progress: |
41210
929999d963b8
progress: specify updatebar() function by constructor argument
Yuya Nishihara <yuya@tcha.org>
parents:
41143
diff
changeset
|
2126 """Create a progress helper for the specified topic""" |
929999d963b8
progress: specify updatebar() function by constructor argument
Yuya Nishihara <yuya@tcha.org>
parents:
41143
diff
changeset
|
2127 if getattr(self._fmsgerr, 'structured', False): |
929999d963b8
progress: specify updatebar() function by constructor argument
Yuya Nishihara <yuya@tcha.org>
parents:
41143
diff
changeset
|
2128 # channel for machine-readable output with metadata, just send |
929999d963b8
progress: specify updatebar() function by constructor argument
Yuya Nishihara <yuya@tcha.org>
parents:
41143
diff
changeset
|
2129 # raw information |
929999d963b8
progress: specify updatebar() function by constructor argument
Yuya Nishihara <yuya@tcha.org>
parents:
41143
diff
changeset
|
2130 # TODO: consider porting some useful information (e.g. estimated |
929999d963b8
progress: specify updatebar() function by constructor argument
Yuya Nishihara <yuya@tcha.org>
parents:
41143
diff
changeset
|
2131 # time) from progbar. we might want to support update delay to |
929999d963b8
progress: specify updatebar() function by constructor argument
Yuya Nishihara <yuya@tcha.org>
parents:
41143
diff
changeset
|
2132 # reduce the cost of transferring progress messages. |
929999d963b8
progress: specify updatebar() function by constructor argument
Yuya Nishihara <yuya@tcha.org>
parents:
41143
diff
changeset
|
2133 def updatebar(topic, pos, item, unit, total): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2134 self._fmsgerr.write( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2135 None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2136 type=b'progress', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2137 topic=topic, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2138 pos=pos, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2139 item=item, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2140 unit=unit, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2141 total=total, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2142 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2143 |
41210
929999d963b8
progress: specify updatebar() function by constructor argument
Yuya Nishihara <yuya@tcha.org>
parents:
41143
diff
changeset
|
2144 elif self._progbar is not None: |
929999d963b8
progress: specify updatebar() function by constructor argument
Yuya Nishihara <yuya@tcha.org>
parents:
41143
diff
changeset
|
2145 updatebar = self._progbar.progress |
929999d963b8
progress: specify updatebar() function by constructor argument
Yuya Nishihara <yuya@tcha.org>
parents:
41143
diff
changeset
|
2146 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2147 |
41210
929999d963b8
progress: specify updatebar() function by constructor argument
Yuya Nishihara <yuya@tcha.org>
parents:
41143
diff
changeset
|
2148 def updatebar(topic, pos, item, unit, total): |
929999d963b8
progress: specify updatebar() function by constructor argument
Yuya Nishihara <yuya@tcha.org>
parents:
41143
diff
changeset
|
2149 pass |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2150 |
41210
929999d963b8
progress: specify updatebar() function by constructor argument
Yuya Nishihara <yuya@tcha.org>
parents:
41143
diff
changeset
|
2151 return scmutil.progress(self, updatebar, topic, unit, total) |
38351
bec1212eceaa
progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents:
38197
diff
changeset
|
2152 |
40764
55b053af7196
ui: manage logger instances and event filtering by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40717
diff
changeset
|
2153 def getlogger(self, name): |
55b053af7196
ui: manage logger instances and event filtering by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40717
diff
changeset
|
2154 """Returns a logger of the given name; or None if not registered""" |
55b053af7196
ui: manage logger instances and event filtering by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40717
diff
changeset
|
2155 return self._loggers.get(name) |
55b053af7196
ui: manage logger instances and event filtering by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40717
diff
changeset
|
2156 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
2157 def setlogger(self, name, logger) -> None: |
40764
55b053af7196
ui: manage logger instances and event filtering by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40717
diff
changeset
|
2158 """Install logger which can be identified later by the given name |
55b053af7196
ui: manage logger instances and event filtering by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40717
diff
changeset
|
2159 |
55b053af7196
ui: manage logger instances and event filtering by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40717
diff
changeset
|
2160 More than one loggers can be registered. Use extension or module |
55b053af7196
ui: manage logger instances and event filtering by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40717
diff
changeset
|
2161 name to uniquely identify the logger instance. |
55b053af7196
ui: manage logger instances and event filtering by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40717
diff
changeset
|
2162 """ |
55b053af7196
ui: manage logger instances and event filtering by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40717
diff
changeset
|
2163 self._loggers[name] = logger |
55b053af7196
ui: manage logger instances and event filtering by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40717
diff
changeset
|
2164 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
2165 def log(self, event, msgfmt, *msgargs, **opts) -> None: |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
2166 """hook for logging facility extensions |
11984 | 2167 |
40717
c72a81bc2e82
ui: unify argument name of ui.log()
Yuya Nishihara <yuya@tcha.org>
parents:
40649
diff
changeset
|
2168 event should be a readily-identifiable subsystem, which will |
11984 | 2169 allow filtering. |
26235
6c962145f523
ui: improve docs on ui.log
Augie Fackler <augie@google.com>
parents:
26189
diff
changeset
|
2170 |
40794
ffd574c144d2
ui: pass in formatted message to logger.log()
Yuya Nishihara <yuya@tcha.org>
parents:
40793
diff
changeset
|
2171 msgfmt should be a newline-terminated format string to log, and |
ffd574c144d2
ui: pass in formatted message to logger.log()
Yuya Nishihara <yuya@tcha.org>
parents:
40793
diff
changeset
|
2172 *msgargs are %-formatted into it. |
26235
6c962145f523
ui: improve docs on ui.log
Augie Fackler <augie@google.com>
parents:
26189
diff
changeset
|
2173 |
6c962145f523
ui: improve docs on ui.log
Augie Fackler <augie@google.com>
parents:
26189
diff
changeset
|
2174 **opts currently has no defined meanings. |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
2175 """ |
40764
55b053af7196
ui: manage logger instances and event filtering by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40717
diff
changeset
|
2176 if not self._loggers: |
55b053af7196
ui: manage logger instances and event filtering by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40717
diff
changeset
|
2177 return |
49026
2cce2fa5bcf7
py3: replace pycompat.itervalues(x) with x.values()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49024
diff
changeset
|
2178 activeloggers = [l for l in self._loggers.values() if l.tracked(event)] |
40764
55b053af7196
ui: manage logger instances and event filtering by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40717
diff
changeset
|
2179 if not activeloggers: |
55b053af7196
ui: manage logger instances and event filtering by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40717
diff
changeset
|
2180 return |
40794
ffd574c144d2
ui: pass in formatted message to logger.log()
Yuya Nishihara <yuya@tcha.org>
parents:
40793
diff
changeset
|
2181 msg = msgfmt % msgargs |
40795
691c68bc1222
ui: pass in bytes opts dict to logger.log()
Yuya Nishihara <yuya@tcha.org>
parents:
40794
diff
changeset
|
2182 opts = pycompat.byteskwargs(opts) |
40793
fdc6eb1d650d
blackbox: send debug message to logger by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40764
diff
changeset
|
2183 # guard against recursion from e.g. ui.debug() |
fdc6eb1d650d
blackbox: send debug message to logger by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40764
diff
changeset
|
2184 registeredloggers = self._loggers |
fdc6eb1d650d
blackbox: send debug message to logger by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40764
diff
changeset
|
2185 self._loggers = {} |
fdc6eb1d650d
blackbox: send debug message to logger by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40764
diff
changeset
|
2186 try: |
fdc6eb1d650d
blackbox: send debug message to logger by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40764
diff
changeset
|
2187 for logger in activeloggers: |
fdc6eb1d650d
blackbox: send debug message to logger by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40764
diff
changeset
|
2188 logger.log(self, event, msg, opts) |
fdc6eb1d650d
blackbox: send debug message to logger by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40764
diff
changeset
|
2189 finally: |
fdc6eb1d650d
blackbox: send debug message to logger by core ui
Yuya Nishihara <yuya@tcha.org>
parents:
40764
diff
changeset
|
2190 self._loggers = registeredloggers |
11984 | 2191 |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
2192 def label(self, msg: bytes, label: bytes) -> bytes: |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
2193 """style msg based on supplied label |
10815
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
2194 |
31104
894bdcdc75df
color: move the 'colorlabel' call to the core 'ui' class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
2195 If some color mode is enabled, this will add the necessary control |
894bdcdc75df
color: move the 'colorlabel' call to the core 'ui' class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
2196 characters to apply such color. In addition, 'debug' color mode adds |
894bdcdc75df
color: move the 'colorlabel' call to the core 'ui' class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
2197 markup showing which label affects a piece of text. |
10815
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
2198 |
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
2199 ui.write(s, 'label') is equivalent to |
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
2200 ui.write(ui.label(s, 'label')). |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45944
diff
changeset
|
2201 """ |
31104
894bdcdc75df
color: move the 'colorlabel' call to the core 'ui' class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
2202 if self._colormode is not None: |
894bdcdc75df
color: move the 'colorlabel' call to the core 'ui' class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
2203 return color.colorlabel(self, msg, label) |
10815
32b213b9b22c
ui: add ui.write() output labeling API
Brodie Rao <brodie@bitheap.org>
parents:
10567
diff
changeset
|
2204 return msg |
24250
9c32eea2ca04
ui: represent paths as classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23269
diff
changeset
|
2205 |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
2206 def develwarn( |
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
2207 self, msg: bytes, stacklevel: int = 1, config: Optional[bytes] = None |
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
2208 ) -> None: |
27274
82910fdc216f
ui: add a 'stacklevel' argument to 'develwarn'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27266
diff
changeset
|
2209 """issue a developer warning message |
82910fdc216f
ui: add a 'stacklevel' argument to 'develwarn'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27266
diff
changeset
|
2210 |
82910fdc216f
ui: add a 'stacklevel' argument to 'develwarn'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27266
diff
changeset
|
2211 Use 'stacklevel' to report the offender some layers further up in the |
82910fdc216f
ui: add a 'stacklevel' argument to 'develwarn'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27266
diff
changeset
|
2212 stack. |
82910fdc216f
ui: add a 'stacklevel' argument to 'develwarn'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27266
diff
changeset
|
2213 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2214 if not self.configbool(b'devel', b'all-warnings'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2215 if config is None or not self.configbool(b'devel', config): |
29095
3f33831a9202
develwarn: move config gating inside the develwarn function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29082
diff
changeset
|
2216 return |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2217 msg = b'devel-warn: ' + msg |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2218 stacklevel += 1 # get in develwarn |
25629
52e5f68d8363
devel-warn: move the develwarn function as a method of the ui object
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25568
diff
changeset
|
2219 if self.tracebackflag: |
40593
7bffbbe03e90
ui: hide fin/fout/ferr attributes behind @property functions
Yuya Nishihara <yuya@tcha.org>
parents:
40592
diff
changeset
|
2220 util.debugstacktrace(msg, stacklevel, self._ferr, self._fout) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2221 self.log( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2222 b'develwarn', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2223 b'%s at:\n%s' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2224 % (msg, b''.join(util.getstackframes(stacklevel))), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2225 ) |
25629
52e5f68d8363
devel-warn: move the develwarn function as a method of the ui object
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25568
diff
changeset
|
2226 else: |
52e5f68d8363
devel-warn: move the develwarn function as a method of the ui object
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25568
diff
changeset
|
2227 curframe = inspect.currentframe() |
52e5f68d8363
devel-warn: move the develwarn function as a method of the ui object
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25568
diff
changeset
|
2228 calframe = inspect.getouterframes(curframe, 2) |
36165
df1760b58fda
ui: convert stack traces to sysbytes before logging
Augie Fackler <augie@google.com>
parents:
36164
diff
changeset
|
2229 fname, lineno, fmsg = calframe[stacklevel][1:4] |
df1760b58fda
ui: convert stack traces to sysbytes before logging
Augie Fackler <augie@google.com>
parents:
36164
diff
changeset
|
2230 fname, fmsg = pycompat.sysbytes(fname), pycompat.sysbytes(fmsg) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2231 self.write_err(b'%s at: %s:%d (%s)\n' % (msg, fname, lineno, fmsg)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2232 self.log( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2233 b'develwarn', b'%s at: %s:%d (%s)\n', msg, fname, lineno, fmsg |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2234 ) |
43996
e3ce3731d621
ui: delete local variables instead of setting to `None`
Matt Harbison <matt_harbison@yahoo.com>
parents:
43916
diff
changeset
|
2235 |
e3ce3731d621
ui: delete local variables instead of setting to `None`
Matt Harbison <matt_harbison@yahoo.com>
parents:
43916
diff
changeset
|
2236 # avoid cycles |
e3ce3731d621
ui: delete local variables instead of setting to `None`
Matt Harbison <matt_harbison@yahoo.com>
parents:
43916
diff
changeset
|
2237 del curframe |
e3ce3731d621
ui: delete local variables instead of setting to `None`
Matt Harbison <matt_harbison@yahoo.com>
parents:
43916
diff
changeset
|
2238 del calframe |
25629
52e5f68d8363
devel-warn: move the develwarn function as a method of the ui object
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25568
diff
changeset
|
2239 |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
2240 def deprecwarn( |
50253
444fa55f5dd2
style: rewrap `ui.deprecwarn` declaration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49925
diff
changeset
|
2241 self, |
444fa55f5dd2
style: rewrap `ui.deprecwarn` declaration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49925
diff
changeset
|
2242 msg: bytes, |
444fa55f5dd2
style: rewrap `ui.deprecwarn` declaration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49925
diff
changeset
|
2243 version: bytes, |
444fa55f5dd2
style: rewrap `ui.deprecwarn` declaration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49925
diff
changeset
|
2244 stacklevel: int = 2, |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
2245 ) -> None: |
27275
f2cd240f2f7c
ui: add a 'deprecwarn' helper to issue deprecation warnings
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27274
diff
changeset
|
2246 """issue a deprecation warning |
f2cd240f2f7c
ui: add a 'deprecwarn' helper to issue deprecation warnings
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27274
diff
changeset
|
2247 |
f2cd240f2f7c
ui: add a 'deprecwarn' helper to issue deprecation warnings
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27274
diff
changeset
|
2248 - msg: message explaining what is deprecated and how to upgrade, |
f2cd240f2f7c
ui: add a 'deprecwarn' helper to issue deprecation warnings
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27274
diff
changeset
|
2249 - version: last version where the API will be supported, |
f2cd240f2f7c
ui: add a 'deprecwarn' helper to issue deprecation warnings
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27274
diff
changeset
|
2250 """ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2251 if not ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2252 self.configbool(b'devel', b'all-warnings') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2253 or self.configbool(b'devel', b'deprec-warn') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2254 ): |
29082
77de985d7c91
deprecation: gate deprecation warning behind devel configuration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
28962
diff
changeset
|
2255 return |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2256 msg += ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2257 b"\n(compatibility will be dropped after Mercurial-%s," |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2258 b" update your code.)" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2259 ) % version |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2260 self.develwarn(msg, stacklevel=stacklevel, config=b'deprec-warn') |
25629
52e5f68d8363
devel-warn: move the develwarn function as a method of the ui object
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25568
diff
changeset
|
2261 |
30832
da5fa0f13a41
ui: introduce an experimental dict of exportable environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents:
30814
diff
changeset
|
2262 def exportableenviron(self): |
da5fa0f13a41
ui: introduce an experimental dict of exportable environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents:
30814
diff
changeset
|
2263 """The environment variables that are safe to export, e.g. through |
da5fa0f13a41
ui: introduce an experimental dict of exportable environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents:
30814
diff
changeset
|
2264 hgweb. |
da5fa0f13a41
ui: introduce an experimental dict of exportable environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents:
30814
diff
changeset
|
2265 """ |
da5fa0f13a41
ui: introduce an experimental dict of exportable environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents:
30814
diff
changeset
|
2266 return self._exportableenviron |
da5fa0f13a41
ui: introduce an experimental dict of exportable environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents:
30814
diff
changeset
|
2267 |
30489
b0a8337ba9af
ui: add configoverride context manager
Kostia Balytskyi <ikostia@fb.com>
parents:
30482
diff
changeset
|
2268 @contextlib.contextmanager |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
2269 def configoverride(self, overrides: _ConfigItems, source: bytes = b""): |
30489
b0a8337ba9af
ui: add configoverride context manager
Kostia Balytskyi <ikostia@fb.com>
parents:
30482
diff
changeset
|
2270 """Context manager for temporary config overrides |
b0a8337ba9af
ui: add configoverride context manager
Kostia Balytskyi <ikostia@fb.com>
parents:
30482
diff
changeset
|
2271 `overrides` must be a dict of the following structure: |
b0a8337ba9af
ui: add configoverride context manager
Kostia Balytskyi <ikostia@fb.com>
parents:
30482
diff
changeset
|
2272 {(section, name) : value}""" |
b0a8337ba9af
ui: add configoverride context manager
Kostia Balytskyi <ikostia@fb.com>
parents:
30482
diff
changeset
|
2273 backups = {} |
30546
4b0e6677eed1
ui: use try..finally in configoverride
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30528
diff
changeset
|
2274 try: |
4b0e6677eed1
ui: use try..finally in configoverride
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30528
diff
changeset
|
2275 for (section, name), value in overrides.items(): |
4b0e6677eed1
ui: use try..finally in configoverride
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30528
diff
changeset
|
2276 backups[(section, name)] = self.backupconfig(section, name) |
4b0e6677eed1
ui: use try..finally in configoverride
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30528
diff
changeset
|
2277 self.setconfig(section, name, value, source) |
4b0e6677eed1
ui: use try..finally in configoverride
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30528
diff
changeset
|
2278 yield |
4b0e6677eed1
ui: use try..finally in configoverride
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30528
diff
changeset
|
2279 finally: |
4b0e6677eed1
ui: use try..finally in configoverride
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30528
diff
changeset
|
2280 for __, backup in backups.items(): |
4b0e6677eed1
ui: use try..finally in configoverride
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30528
diff
changeset
|
2281 self.restoreconfig(backup) |
4b0e6677eed1
ui: use try..finally in configoverride
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30528
diff
changeset
|
2282 # just restoring ui.quiet config to the previous value is not enough |
4b0e6677eed1
ui: use try..finally in configoverride
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30528
diff
changeset
|
2283 # as it does not update ui.quiet class member |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2284 if (b'ui', b'quiet') in overrides: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2285 self.fixconfig(section=b'ui') |
30489
b0a8337ba9af
ui: add configoverride context manager
Kostia Balytskyi <ikostia@fb.com>
parents:
30482
diff
changeset
|
2286 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
2287 def estimatememory(self) -> Optional[int]: |
45062
02b17231f6c3
util: provide a helper function to estimate RAM size
Joerg Sonnenberger <joerg@bec.de>
parents:
45037
diff
changeset
|
2288 """Provide an estimate for the available system memory in Bytes. |
02b17231f6c3
util: provide a helper function to estimate RAM size
Joerg Sonnenberger <joerg@bec.de>
parents:
45037
diff
changeset
|
2289 |
02b17231f6c3
util: provide a helper function to estimate RAM size
Joerg Sonnenberger <joerg@bec.de>
parents:
45037
diff
changeset
|
2290 This can be overriden via ui.available-memory. It returns None, if |
02b17231f6c3
util: provide a helper function to estimate RAM size
Joerg Sonnenberger <joerg@bec.de>
parents:
45037
diff
changeset
|
2291 no estimate can be computed. |
02b17231f6c3
util: provide a helper function to estimate RAM size
Joerg Sonnenberger <joerg@bec.de>
parents:
45037
diff
changeset
|
2292 """ |
02b17231f6c3
util: provide a helper function to estimate RAM size
Joerg Sonnenberger <joerg@bec.de>
parents:
45037
diff
changeset
|
2293 value = self.config(b'ui', b'available-memory') |
02b17231f6c3
util: provide a helper function to estimate RAM size
Joerg Sonnenberger <joerg@bec.de>
parents:
45037
diff
changeset
|
2294 if value is not None: |
02b17231f6c3
util: provide a helper function to estimate RAM size
Joerg Sonnenberger <joerg@bec.de>
parents:
45037
diff
changeset
|
2295 try: |
02b17231f6c3
util: provide a helper function to estimate RAM size
Joerg Sonnenberger <joerg@bec.de>
parents:
45037
diff
changeset
|
2296 return util.sizetoint(value) |
02b17231f6c3
util: provide a helper function to estimate RAM size
Joerg Sonnenberger <joerg@bec.de>
parents:
45037
diff
changeset
|
2297 except error.ParseError: |
02b17231f6c3
util: provide a helper function to estimate RAM size
Joerg Sonnenberger <joerg@bec.de>
parents:
45037
diff
changeset
|
2298 raise error.ConfigError( |
02b17231f6c3
util: provide a helper function to estimate RAM size
Joerg Sonnenberger <joerg@bec.de>
parents:
45037
diff
changeset
|
2299 _(b"ui.available-memory value is invalid ('%s')") % value |
02b17231f6c3
util: provide a helper function to estimate RAM size
Joerg Sonnenberger <joerg@bec.de>
parents:
45037
diff
changeset
|
2300 ) |
02b17231f6c3
util: provide a helper function to estimate RAM size
Joerg Sonnenberger <joerg@bec.de>
parents:
45037
diff
changeset
|
2301 return util._estimatememory() |
02b17231f6c3
util: provide a helper function to estimate RAM size
Joerg Sonnenberger <joerg@bec.de>
parents:
45037
diff
changeset
|
2302 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2303 |
25498
7a5335ed7e1a
progress: move the singleton logic to the ui module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25363
diff
changeset
|
2304 # we instantiate one globally shared progress bar to avoid |
7a5335ed7e1a
progress: move the singleton logic to the ui module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25363
diff
changeset
|
2305 # competing progress bars when multiple UI objects get created |
49889
25fe689a4a64
typing: add type hints related to progress bars in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49888
diff
changeset
|
2306 _progresssingleton: Optional[progress.progbar] = None |
25498
7a5335ed7e1a
progress: move the singleton logic to the ui module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25363
diff
changeset
|
2307 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2308 |
49889
25fe689a4a64
typing: add type hints related to progress bars in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49888
diff
changeset
|
2309 def getprogbar(ui: ui) -> progress.progbar: |
25498
7a5335ed7e1a
progress: move the singleton logic to the ui module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25363
diff
changeset
|
2310 global _progresssingleton |
7a5335ed7e1a
progress: move the singleton logic to the ui module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25363
diff
changeset
|
2311 if _progresssingleton is None: |
7a5335ed7e1a
progress: move the singleton logic to the ui module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25363
diff
changeset
|
2312 # passing 'ui' object to the singleton is fishy, |
7a5335ed7e1a
progress: move the singleton logic to the ui module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25363
diff
changeset
|
2313 # this is how the extension used to work but feel free to rework it. |
7a5335ed7e1a
progress: move the singleton logic to the ui module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25363
diff
changeset
|
2314 _progresssingleton = progress.progbar(ui) |
7a5335ed7e1a
progress: move the singleton logic to the ui module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25363
diff
changeset
|
2315 return _progresssingleton |
33683
0e4bed5c5c38
ui: check for progress singleton when clearing progress bar (issue5684)
Mark Thomas <mbthomas@fb.com>
parents:
33668
diff
changeset
|
2316 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2317 |
49889
25fe689a4a64
typing: add type hints related to progress bars in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49888
diff
changeset
|
2318 def haveprogbar() -> bool: |
33683
0e4bed5c5c38
ui: check for progress singleton when clearing progress bar (issue5684)
Mark Thomas <mbthomas@fb.com>
parents:
33668
diff
changeset
|
2319 return _progresssingleton is not None |
40594
840cd57cde32
ui: add config knob to redirect status messages to stderr (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40593
diff
changeset
|
2320 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2321 |
49892
0449fb7729d7
typing: add trivial type hints to mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49890
diff
changeset
|
2322 def _selectmsgdests(ui: ui): |
40594
840cd57cde32
ui: add config knob to redirect status messages to stderr (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40593
diff
changeset
|
2323 name = ui.config(b'ui', b'message-output') |
40636
054d0fcba2c4
commandserver: add experimental option to use separate message channel
Yuya Nishihara <yuya@tcha.org>
parents:
40634
diff
changeset
|
2324 if name == b'channel': |
054d0fcba2c4
commandserver: add experimental option to use separate message channel
Yuya Nishihara <yuya@tcha.org>
parents:
40634
diff
changeset
|
2325 if ui.fmsg: |
054d0fcba2c4
commandserver: add experimental option to use separate message channel
Yuya Nishihara <yuya@tcha.org>
parents:
40634
diff
changeset
|
2326 return ui.fmsg, ui.fmsg |
054d0fcba2c4
commandserver: add experimental option to use separate message channel
Yuya Nishihara <yuya@tcha.org>
parents:
40634
diff
changeset
|
2327 else: |
054d0fcba2c4
commandserver: add experimental option to use separate message channel
Yuya Nishihara <yuya@tcha.org>
parents:
40634
diff
changeset
|
2328 # fall back to ferr if channel isn't ready so that status/error |
054d0fcba2c4
commandserver: add experimental option to use separate message channel
Yuya Nishihara <yuya@tcha.org>
parents:
40634
diff
changeset
|
2329 # messages can be printed |
054d0fcba2c4
commandserver: add experimental option to use separate message channel
Yuya Nishihara <yuya@tcha.org>
parents:
40634
diff
changeset
|
2330 return ui.ferr, ui.ferr |
40594
840cd57cde32
ui: add config knob to redirect status messages to stderr (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40593
diff
changeset
|
2331 if name == b'stdio': |
840cd57cde32
ui: add config knob to redirect status messages to stderr (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40593
diff
changeset
|
2332 return ui.fout, ui.ferr |
840cd57cde32
ui: add config knob to redirect status messages to stderr (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40593
diff
changeset
|
2333 if name == b'stderr': |
840cd57cde32
ui: add config knob to redirect status messages to stderr (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40593
diff
changeset
|
2334 return ui.ferr, ui.ferr |
840cd57cde32
ui: add config knob to redirect status messages to stderr (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40593
diff
changeset
|
2335 raise error.Abort(b'invalid ui.message-output destination: %s' % name) |
40637
83dd8c63a0c6
ui: extract helpers to write message with type or label
Yuya Nishihara <yuya@tcha.org>
parents:
40636
diff
changeset
|
2336 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42699
diff
changeset
|
2337 |
49890
f1e820cda2f5
typing: add type hints related to message output in mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49889
diff
changeset
|
2338 def _writemsgwith(write, dest, *args: bytes, **opts: _MsgOpts) -> None: |
40637
83dd8c63a0c6
ui: extract helpers to write message with type or label
Yuya Nishihara <yuya@tcha.org>
parents:
40636
diff
changeset
|
2339 """Write ui message with the given ui._write*() function |
83dd8c63a0c6
ui: extract helpers to write message with type or label
Yuya Nishihara <yuya@tcha.org>
parents:
40636
diff
changeset
|
2340 |
83dd8c63a0c6
ui: extract helpers to write message with type or label
Yuya Nishihara <yuya@tcha.org>
parents:
40636
diff
changeset
|
2341 The specified message type is translated to 'ui.<type>' label if the dest |
83dd8c63a0c6
ui: extract helpers to write message with type or label
Yuya Nishihara <yuya@tcha.org>
parents:
40636
diff
changeset
|
2342 isn't a structured channel, so that the message will be colorized. |
83dd8c63a0c6
ui: extract helpers to write message with type or label
Yuya Nishihara <yuya@tcha.org>
parents:
40636
diff
changeset
|
2343 """ |
83dd8c63a0c6
ui: extract helpers to write message with type or label
Yuya Nishihara <yuya@tcha.org>
parents:
40636
diff
changeset
|
2344 # TODO: maybe change 'type' to a mandatory option |
43554
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43377
diff
changeset
|
2345 if 'type' in opts and not getattr(dest, 'structured', False): |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43377
diff
changeset
|
2346 opts['label'] = opts.get('label', b'') + b' ui.%s' % opts.pop('type') |
40637
83dd8c63a0c6
ui: extract helpers to write message with type or label
Yuya Nishihara <yuya@tcha.org>
parents:
40636
diff
changeset
|
2347 write(dest, *args, **opts) |