Mercurial > hg
annotate mercurial/rcutil.py @ 41055:55e8da487b8a
wireproto: in batch queries, support queries with immediate responses
listkeys and pushkey return without querying the remote when the
remote doesn't support such queries. Before this change, the batching
code didn't handle this convention, resulting in this kind of error:
$ hg pull ssh://user@dummy/repo1 -r tip -B a
pulling from ssh://user@dummy/repo1
remote: ** Unknown exception encountered with possibly-broken third-party extension disable-lookup
remote: ** which supports versions unknown of Mercurial.
remote: ** Please disable disable-lookup and try your action again.
remote: ** If that fixes the bug please report it to the extension author.
remote: ** Python 2.7.15+ (default, Oct 2 2018, 22:12:08) [GCC 8.2.0]
remote: ** Mercurial Distributed SCM (version 4.8.1+586-ef54bd33b476+20181224)
remote: ** Extensions loaded: disable-lookup
remote: Traceback (most recent call last):
remote: File "/tmp/hgtests.i66Npc/install/bin/hg", line 43, in <module>
remote: dispatch.run()
remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/dispatch.py", line 99, in run
remote: status = dispatch(req)
remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/dispatch.py", line 225, in dispatch
remote: ret = _runcatch(req) or 0
remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/dispatch.py", line 376, in _runcatch
remote: return _callcatch(ui, _runcatchfunc)
remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/dispatch.py", line 384, in _callcatch
remote: return scmutil.callcatch(ui, func)
remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/scmutil.py", line 166, in callcatch
remote: return func()
remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/dispatch.py", line 367, in _runcatchfunc
remote: return _dispatch(req)
remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/dispatch.py", line 1021, in _dispatch
remote: cmdpats, cmdoptions)
remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/dispatch.py", line 756, in runcommand
remote: ret = _runcommand(ui, options, cmd, d)
remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/dispatch.py", line 1030, in _runcommand
remote: return cmdfunc()
remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/dispatch.py", line 1018, in <lambda>
remote: d = lambda: util.checksignature(func)(ui, *args, **strcmdopt)
remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/util.py", line 1670, in check
remote: return func(*args, **kwargs)
remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/commands.py", line 5257, in serve
remote: s.serve_forever()
remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/wireprotoserver.py", line 797, in serve_forever
remote: self.serveuntil(threading.Event())
remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/wireprotoserver.py", line 804, in serveuntil
remote: _runsshserver(self._ui, self._repo, self._fin, self._fout, ev)
remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/wireprotoserver.py", line 656, in _runsshserver
remote: rsp = wireprotov1server.dispatch(repo, proto, request)
remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/wireprotov1server.py", line 74, in dispatch
remote: return func(repo, proto, *args)
remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/wireprotov1server.py", line 195, in batch
remote: data[k] = vals[k]
remote: KeyError: 'namespace'
abort: unexpected response: empty string
[255]
Differential Revision: https://phab.mercurial-scm.org/D5482
author | Valentin Gatien-Baron <valentin.gatienbaron@gmail.com> |
---|---|
date | Mon, 24 Dec 2018 14:04:16 -0500 |
parents | 75979c8d4572 |
children | edbcf5b239f9 |
rev | line source |
---|---|
31679
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
1 # rcutil.py - utilities about config paths, special config sections etc. |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
2 # |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
3 # Copyright Mercurial Contributors |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
4 # |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
7 |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
8 from __future__ import absolute_import |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
9 |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
10 import os |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
11 |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
12 from . import ( |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
13 encoding, |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
14 pycompat, |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
15 util, |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
16 ) |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
17 |
34645 | 18 if pycompat.iswindows: |
31679
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
19 from . import scmwindows as scmplatform |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
20 else: |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
21 from . import scmposix as scmplatform |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
22 |
32078
bf5e13e38390
pager: use less as a fallback on Unix
Yuya Nishihara <yuya@tcha.org>
parents:
31954
diff
changeset
|
23 fallbackpager = scmplatform.fallbackpager |
31679
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
24 systemrcpath = scmplatform.systemrcpath |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
25 userrcpath = scmplatform.userrcpath |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
26 |
31681
294728f2a908
rcutil: extract rc directory listing logic
Jun Wu <quark@fb.com>
parents:
31680
diff
changeset
|
27 def _expandrcpath(path): |
294728f2a908
rcutil: extract rc directory listing logic
Jun Wu <quark@fb.com>
parents:
31680
diff
changeset
|
28 '''path could be a file or a directory. return a list of file paths''' |
294728f2a908
rcutil: extract rc directory listing logic
Jun Wu <quark@fb.com>
parents:
31680
diff
changeset
|
29 p = util.expandpath(path) |
294728f2a908
rcutil: extract rc directory listing logic
Jun Wu <quark@fb.com>
parents:
31680
diff
changeset
|
30 if os.path.isdir(p): |
294728f2a908
rcutil: extract rc directory listing logic
Jun Wu <quark@fb.com>
parents:
31680
diff
changeset
|
31 join = os.path.join |
32208
d74b0cff94a9
osutil: proxy through util (and platform) modules (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32078
diff
changeset
|
32 return [join(p, f) for f, k in util.listdir(p) if f.endswith('.rc')] |
31681
294728f2a908
rcutil: extract rc directory listing logic
Jun Wu <quark@fb.com>
parents:
31680
diff
changeset
|
33 return [p] |
294728f2a908
rcutil: extract rc directory listing logic
Jun Wu <quark@fb.com>
parents:
31680
diff
changeset
|
34 |
31684
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
35 def envrcitems(env=None): |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
36 '''Return [(section, name, value, source)] config items. |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
37 |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
38 The config items are extracted from environment variables specified by env, |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
39 used to override systemrc, but not userrc. |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
40 |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
41 If env is not provided, encoding.environ will be used. |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
42 ''' |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
43 if env is None: |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
44 env = encoding.environ |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
45 checklist = [ |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
46 ('EDITOR', 'ui', 'editor'), |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
47 ('VISUAL', 'ui', 'editor'), |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
48 ('PAGER', 'pager', 'pager'), |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
49 ] |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
50 result = [] |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
51 for envname, section, configname in checklist: |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
52 if envname not in env: |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
53 continue |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
54 result.append((section, configname, env[envname], '$%s' % envname)) |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
55 return result |
0be96ac9199a
rcutil: add a method to convert environment variables to config items
Jun Wu <quark@fb.com>
parents:
31683
diff
changeset
|
56 |
31680
448889f9a36c
rcutil: split osrcpath to return default.d paths (API)
Jun Wu <quark@fb.com>
parents:
31679
diff
changeset
|
57 def defaultrcpath(): |
448889f9a36c
rcutil: split osrcpath to return default.d paths (API)
Jun Wu <quark@fb.com>
parents:
31679
diff
changeset
|
58 '''return rc paths in default.d''' |
31679
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
59 path = [] |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
60 defaultpath = os.path.join(util.datapath, 'default.d') |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
61 if os.path.isdir(defaultpath): |
31681
294728f2a908
rcutil: extract rc directory listing logic
Jun Wu <quark@fb.com>
parents:
31680
diff
changeset
|
62 path = _expandrcpath(defaultpath) |
31679
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
63 return path |
0f8ba0bc1154
rcutil: move scmutil.*rcpath to rcutil (API)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
64 |
31682
07d62fa518a4
rcutil: rename rcpath to rccomponents (API)
Jun Wu <quark@fb.com>
parents:
31681
diff
changeset
|
65 def rccomponents(): |
31683
00e569a2da97
rcutil: let rccomponents return different types of configs (API)
Jun Wu <quark@fb.com>
parents:
31682
diff
changeset
|
66 '''return an ordered [(type, obj)] about where to load configs. |
00e569a2da97
rcutil: let rccomponents return different types of configs (API)
Jun Wu <quark@fb.com>
parents:
31682
diff
changeset
|
67 |
00e569a2da97
rcutil: let rccomponents return different types of configs (API)
Jun Wu <quark@fb.com>
parents:
31682
diff
changeset
|
68 respect $HGRCPATH. if $HGRCPATH is empty, only .hg/hgrc of current repo is |
00e569a2da97
rcutil: let rccomponents return different types of configs (API)
Jun Wu <quark@fb.com>
parents:
31682
diff
changeset
|
69 used. if $HGRCPATH is not set, the platform default will be used. |
00e569a2da97
rcutil: let rccomponents return different types of configs (API)
Jun Wu <quark@fb.com>
parents:
31682
diff
changeset
|
70 |
00e569a2da97
rcutil: let rccomponents return different types of configs (API)
Jun Wu <quark@fb.com>
parents:
31682
diff
changeset
|
71 if a directory is provided, *.rc files under it will be used. |
00e569a2da97
rcutil: let rccomponents return different types of configs (API)
Jun Wu <quark@fb.com>
parents:
31682
diff
changeset
|
72 |
00e569a2da97
rcutil: let rccomponents return different types of configs (API)
Jun Wu <quark@fb.com>
parents:
31682
diff
changeset
|
73 type could be either 'path' or 'items', if type is 'path', obj is a string, |
00e569a2da97
rcutil: let rccomponents return different types of configs (API)
Jun Wu <quark@fb.com>
parents:
31682
diff
changeset
|
74 and is the config file path. if type is 'items', obj is a list of (section, |
00e569a2da97
rcutil: let rccomponents return different types of configs (API)
Jun Wu <quark@fb.com>
parents:
31682
diff
changeset
|
75 name, value, source) that should fill the config directly. |
00e569a2da97
rcutil: let rccomponents return different types of configs (API)
Jun Wu <quark@fb.com>
parents:
31682
diff
changeset
|
76 ''' |
31685
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
31684
diff
changeset
|
77 envrc = ('items', envrcitems()) |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
31684
diff
changeset
|
78 |
31693 | 79 if 'HGRCPATH' in encoding.environ: |
80 # assume HGRCPATH is all about user configs so environments can be | |
81 # overridden. | |
82 _rccomponents = [envrc] | |
83 for p in encoding.environ['HGRCPATH'].split(pycompat.ospathsep): | |
84 if not p: | |
85 continue | |
86 _rccomponents.extend(('path', p) for p in _expandrcpath(p)) | |
87 else: | |
31694
10d88dc7c010
rcutil: extract duplicated logic to a lambda
Jun Wu <quark@fb.com>
parents:
31693
diff
changeset
|
88 normpaths = lambda paths: [('path', os.path.normpath(p)) for p in paths] |
10d88dc7c010
rcutil: extract duplicated logic to a lambda
Jun Wu <quark@fb.com>
parents:
31693
diff
changeset
|
89 _rccomponents = normpaths(defaultrcpath() + systemrcpath()) |
31693 | 90 _rccomponents.append(envrc) |
31694
10d88dc7c010
rcutil: extract duplicated logic to a lambda
Jun Wu <quark@fb.com>
parents:
31693
diff
changeset
|
91 _rccomponents.extend(normpaths(userrcpath())) |
31682
07d62fa518a4
rcutil: rename rcpath to rccomponents (API)
Jun Wu <quark@fb.com>
parents:
31681
diff
changeset
|
92 return _rccomponents |
31954
e518192d6bac
pager: set some environment variables if they're not set
Jun Wu <quark@fb.com>
parents:
31694
diff
changeset
|
93 |
e518192d6bac
pager: set some environment variables if they're not set
Jun Wu <quark@fb.com>
parents:
31694
diff
changeset
|
94 def defaultpagerenv(): |
e518192d6bac
pager: set some environment variables if they're not set
Jun Wu <quark@fb.com>
parents:
31694
diff
changeset
|
95 '''return a dict of default environment variables and their values, |
e518192d6bac
pager: set some environment variables if they're not set
Jun Wu <quark@fb.com>
parents:
31694
diff
changeset
|
96 intended to be set before starting a pager. |
e518192d6bac
pager: set some environment variables if they're not set
Jun Wu <quark@fb.com>
parents:
31694
diff
changeset
|
97 ''' |
e518192d6bac
pager: set some environment variables if they're not set
Jun Wu <quark@fb.com>
parents:
31694
diff
changeset
|
98 return {'LESS': 'FRX', 'LV': '-c'} |