Mercurial > public > mercurial-scm > hg
annotate mercurial/configuration/command.py @ 53042:cdd7bf612c7b stable tip
bundle-spec: properly format boolean parameter (issue6960)
This was breaking automatic clone bundle generation. This changeset fixes it and
add a test to catch it in the future.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 11 Mar 2025 02:29:42 +0100 |
parents | 8c509a70b6fa |
children |
rev | line source |
---|---|
52417
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
1 # Gather code related to command dealing with configuration. |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
2 |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
3 from __future__ import annotations |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
4 |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
5 import os |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
6 |
52419
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
7 from typing import Any, Collection, Dict, Optional |
52417
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
8 |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
9 from ..i18n import _ |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
10 |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
11 from .. import ( |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
12 cmdutil, |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
13 error, |
52419
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
14 formatter, |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
15 pycompat, |
52417
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
16 requirements, |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
17 ui as uimod, |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
18 util, |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
19 ) |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
20 |
52425
3e79ca017157
config: gather constant and type into the `__init__.py`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52419
diff
changeset
|
21 from . import ( |
3e79ca017157
config: gather constant and type into the `__init__.py`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52419
diff
changeset
|
22 ConfigLevelT, |
3e79ca017157
config: gather constant and type into the `__init__.py`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52419
diff
changeset
|
23 EDIT_LEVELS, |
3e79ca017157
config: gather constant and type into the `__init__.py`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52419
diff
changeset
|
24 LEVEL_SHARED, |
52427
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
25 NO_REPO_EDIT_LEVELS, |
52425
3e79ca017157
config: gather constant and type into the `__init__.py`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52419
diff
changeset
|
26 rcutil, |
3e79ca017157
config: gather constant and type into the `__init__.py`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52419
diff
changeset
|
27 ) |
52417
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
28 |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
29 EDIT_FLAG = 'edit' |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
30 |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
31 |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
32 def find_edit_level( |
52425
3e79ca017157
config: gather constant and type into the `__init__.py`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52419
diff
changeset
|
33 ui: uimod.ui, |
3e79ca017157
config: gather constant and type into the `__init__.py`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52419
diff
changeset
|
34 repo, |
3e79ca017157
config: gather constant and type into the `__init__.py`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52419
diff
changeset
|
35 opts: Dict[str, Any], |
52417
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
36 ) -> Optional[ConfigLevelT]: |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
37 """return the level we should edit, if any. |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
38 |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
39 Parse the command option to detect when an edit is requested, and if so the |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
40 configuration level we should edit. |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
41 """ |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
42 if opts.get(EDIT_FLAG) or any(opts.get(o) for o in EDIT_LEVELS): |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
43 cmdutil.check_at_most_one_arg(opts, *EDIT_LEVELS) |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
44 for level in EDIT_LEVELS: |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
45 if opts.get(level): |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
46 return level |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
47 return EDIT_LEVELS[0] |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
48 return None |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
49 |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
50 |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
51 def edit_config(ui: uimod.ui, repo, level: ConfigLevelT) -> None: |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
52 """let the user edit configuration file for the given level""" |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
53 |
52427
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
54 # validate input |
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
55 if repo is None and level not in NO_REPO_EDIT_LEVELS: |
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
56 msg = b"can't use --%s outside a repository" % pycompat.bytestr(level) |
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
57 raise error.InputError(_(msg)) |
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
58 if level == LEVEL_SHARED: |
52417
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
59 if not repo.shared(): |
52427
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
60 msg = _(b"repository is not shared; can't use --shared") |
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
61 raise error.InputError(msg) |
52417
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
62 if requirements.SHARESAFE_REQUIREMENT not in repo.requirements: |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
63 raise error.InputError( |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
64 _( |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
65 b"share safe feature not enabled; " |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
66 b"unable to edit shared source repository config" |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
67 ) |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
68 ) |
52427
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
69 |
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
70 # find rc files paths |
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
71 repo_path = None |
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
72 if repo is not None: |
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
73 repo_path = repo.root |
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
74 all_rcs = rcutil.all_rc_components(repo_path) |
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
75 rc_by_level = {} |
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
76 for lvl, rc_type, values in all_rcs: |
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
77 if rc_type != b'path': |
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
78 continue |
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
79 rc_by_level.setdefault(lvl, []).append(values) |
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
80 |
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
81 if level not in rc_by_level: |
52417
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
82 msg = 'unknown config level: %s' % level |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
83 raise error.ProgrammingError(msg) |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
84 |
52427
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
85 paths = rc_by_level[level] |
52417
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
86 for f in paths: |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
87 if os.path.exists(f): |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
88 break |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
89 else: |
52427
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
90 samplehgrc = uimod.samplehgrcs.get(level) |
52417
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
91 |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
92 f = paths[0] |
52427
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
93 if samplehgrc is not None: |
8c509a70b6fa
config: gather the path to edit through rcutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52426
diff
changeset
|
94 util.writefile(f, util.tonativeeol(samplehgrc)) |
52417
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
95 |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
96 editor = ui.geteditor() |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
97 ui.system( |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
98 b"%s \"%s\"" % (editor, f), |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
99 onerr=error.InputError, |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
100 errprefix=_(b"edit failed"), |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
101 blockedtag=b'config_edit', |
c97e0fd26225
config: move edition code in its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
102 ) |
52418
e98cea8fc858
config: move "component display" in the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52417
diff
changeset
|
103 |
e98cea8fc858
config: move "component display" in the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52417
diff
changeset
|
104 |
e98cea8fc858
config: move "component display" in the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52417
diff
changeset
|
105 def show_component(ui: uimod.ui, repo) -> None: |
e98cea8fc858
config: move "component display" in the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52417
diff
changeset
|
106 """show the component used to build the config |
e98cea8fc858
config: move "component display" in the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52417
diff
changeset
|
107 |
e98cea8fc858
config: move "component display" in the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52417
diff
changeset
|
108 XXX this skip over various source and ignore the repository config, so it |
e98cea8fc858
config: move "component display" in the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52417
diff
changeset
|
109 XXX is probably useless old code. |
e98cea8fc858
config: move "component display" in the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52417
diff
changeset
|
110 """ |
52426
22129ce9f86d
config: include the component level when returning them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52425
diff
changeset
|
111 for _lvl, t, f in rcutil.rccomponents(): |
52418
e98cea8fc858
config: move "component display" in the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52417
diff
changeset
|
112 if t == b'path': |
e98cea8fc858
config: move "component display" in the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52417
diff
changeset
|
113 ui.debug(b'read config from: %s\n' % f) |
e98cea8fc858
config: move "component display" in the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52417
diff
changeset
|
114 elif t == b'resource': |
e98cea8fc858
config: move "component display" in the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52417
diff
changeset
|
115 ui.debug(b'read config from: resource:%s.%s\n' % (f[0], f[1])) |
e98cea8fc858
config: move "component display" in the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52417
diff
changeset
|
116 elif t == b'items': |
e98cea8fc858
config: move "component display" in the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52417
diff
changeset
|
117 # Don't print anything for 'items'. |
e98cea8fc858
config: move "component display" in the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52417
diff
changeset
|
118 pass |
e98cea8fc858
config: move "component display" in the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52417
diff
changeset
|
119 else: |
e98cea8fc858
config: move "component display" in the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52417
diff
changeset
|
120 raise error.ProgrammingError(b'unknown rctype: %s' % t) |
52419
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
121 |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
122 |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
123 def show_config( |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
124 ui: uimod.ui, |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
125 repo, |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
126 value_filters: Collection[bytes], |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
127 formatter_options: dict, |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
128 untrusted: bool = False, |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
129 all_known: bool = False, |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
130 show_source: bool = False, |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
131 ) -> bool: |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
132 """Display config value to the user |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
133 |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
134 The display is done using a dedicated `formatter` object. |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
135 |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
136 |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
137 :value_filters: |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
138 if non-empty filter the display value according to these filters. If |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
139 the filter does not match any value, the function return False. True |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
140 otherwise. |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
141 |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
142 :formatter_option: |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
143 options passed to the formatter |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
144 |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
145 :untrusted: |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
146 When set, use untrusted value instead of ignoring them |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
147 |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
148 :all_known: |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
149 Display all known config item, not just the one with an explicit value. |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
150 |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
151 :show_source: |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
152 Show where each value has been defined. |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
153 """ |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
154 fm = ui.formatter(b'config', formatter_options) |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
155 selsections = selentries = [] |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
156 filtered = False |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
157 if value_filters: |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
158 selsections = [v for v in value_filters if b'.' not in v] |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
159 selentries = [v for v in value_filters if b'.' in v] |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
160 filtered = True |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
161 uniquesel = len(selentries) == 1 and not selsections |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
162 selsections = set(selsections) |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
163 selentries = set(selentries) |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
164 |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
165 matched = False |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
166 entries = ui.walkconfig(untrusted=untrusted, all_known=all_known) |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
167 for section, name, value in entries: |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
168 source = ui.configsource(section, name, untrusted) |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
169 value = pycompat.bytestr(value) |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
170 defaultvalue = ui.configdefault(section, name) |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
171 if fm.isplain(): |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
172 source = source or b'none' |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
173 value = value.replace(b'\n', b'\\n') |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
174 entryname = section + b'.' + name |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
175 if filtered and not (section in selsections or entryname in selentries): |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
176 continue |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
177 fm.startitem() |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
178 fm.condwrite(show_source, b'source', b'%s: ', source) |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
179 if uniquesel: |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
180 fm.data(name=entryname) |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
181 fm.write(b'value', b'%s\n', value) |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
182 else: |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
183 fm.write(b'name value', b'%s=%s\n', entryname, value) |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
184 if formatter.isprintable(defaultvalue): |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
185 fm.data(defaultvalue=defaultvalue) |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
186 elif isinstance(defaultvalue, list) and all( |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
187 formatter.isprintable(e) for e in defaultvalue |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
188 ): |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
189 fm.data(defaultvalue=fm.formatlist(defaultvalue, name=b'value')) |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
190 # TODO: no idea how to process unsupported defaultvalue types |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
191 matched = True |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
192 fm.end() |
04c3fb885fb6
config: extra the code showing config in its own module too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52418
diff
changeset
|
193 return matched |