Mercurial > public > mercurial-scm > hg
comparison mercurial/subrepoutil.py @ 46907:ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
The new module is well fitting for this new code. And this will be useful to
make the gathered code collaborate more later.
Differential Revision: https://phab.mercurial-scm.org/D10374
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 12 Apr 2021 03:01:04 +0200 |
parents | d4ba4d51f85f |
children | 5a59a0ed0a37 |
comparison
equal
deleted
inserted
replaced
46906:33524c46a092 | 46907:ffd3e823a7e5 |
---|---|
21 pathutil, | 21 pathutil, |
22 phases, | 22 phases, |
23 pycompat, | 23 pycompat, |
24 util, | 24 util, |
25 ) | 25 ) |
26 from .utils import stringutil | 26 from .utils import ( |
27 stringutil, | |
28 urlutil, | |
29 ) | |
27 | 30 |
28 nullstate = (b'', b'', b'empty') | 31 nullstate = (b'', b'', b'empty') |
29 | 32 |
30 if pycompat.TYPE_CHECKING: | 33 if pycompat.TYPE_CHECKING: |
31 from typing import ( | 34 from typing import ( |
134 raise error.Abort(_(b'missing ] in subrepository source')) | 137 raise error.Abort(_(b'missing ] in subrepository source')) |
135 kind, src = src.split(b']', 1) | 138 kind, src = src.split(b']', 1) |
136 kind = kind[1:] | 139 kind = kind[1:] |
137 src = src.lstrip() # strip any extra whitespace after ']' | 140 src = src.lstrip() # strip any extra whitespace after ']' |
138 | 141 |
139 if not util.url(src).isabs(): | 142 if not urlutil.url(src).isabs(): |
140 parent = _abssource(repo, abort=False) | 143 parent = _abssource(repo, abort=False) |
141 if parent: | 144 if parent: |
142 parent = util.url(parent) | 145 parent = urlutil.url(parent) |
143 parent.path = posixpath.join(parent.path or b'', src) | 146 parent.path = posixpath.join(parent.path or b'', src) |
144 parent.path = posixpath.normpath(parent.path) | 147 parent.path = posixpath.normpath(parent.path) |
145 joined = bytes(parent) | 148 joined = bytes(parent) |
146 # Remap the full joined path and use it if it changes, | 149 # Remap the full joined path and use it if it changes, |
147 # else remap the original source. | 150 # else remap the original source. |
398 def _abssource(repo, push=False, abort=True): | 401 def _abssource(repo, push=False, abort=True): |
399 # type: (localrepo.localrepository, bool, bool) -> Optional[bytes] | 402 # type: (localrepo.localrepository, bool, bool) -> Optional[bytes] |
400 """return pull/push path of repo - either based on parent repo .hgsub info | 403 """return pull/push path of repo - either based on parent repo .hgsub info |
401 or on the top repo config. Abort or return None if no source found.""" | 404 or on the top repo config. Abort or return None if no source found.""" |
402 if util.safehasattr(repo, b'_subparent'): | 405 if util.safehasattr(repo, b'_subparent'): |
403 source = util.url(repo._subsource) | 406 source = urlutil.url(repo._subsource) |
404 if source.isabs(): | 407 if source.isabs(): |
405 return bytes(source) | 408 return bytes(source) |
406 source.path = posixpath.normpath(source.path) | 409 source.path = posixpath.normpath(source.path) |
407 parent = _abssource(repo._subparent, push, abort=False) | 410 parent = _abssource(repo._subparent, push, abort=False) |
408 if parent: | 411 if parent: |
409 parent = util.url(util.pconvert(parent)) | 412 parent = urlutil.url(util.pconvert(parent)) |
410 parent.path = posixpath.join(parent.path or b'', source.path) | 413 parent.path = posixpath.join(parent.path or b'', source.path) |
411 parent.path = posixpath.normpath(parent.path) | 414 parent.path = posixpath.normpath(parent.path) |
412 return bytes(parent) | 415 return bytes(parent) |
413 else: # recursion reached top repo | 416 else: # recursion reached top repo |
414 path = None | 417 path = None |
433 # D:\>python -c "import os; print os.path.abspath('C:')" | 436 # D:\>python -c "import os; print os.path.abspath('C:')" |
434 # C:\some\path | 437 # C:\some\path |
435 # | 438 # |
436 # D:\>python -c "import os; print os.path.abspath('C:relative')" | 439 # D:\>python -c "import os; print os.path.abspath('C:relative')" |
437 # C:\some\path\relative | 440 # C:\some\path\relative |
438 if util.hasdriveletter(path): | 441 if urlutil.hasdriveletter(path): |
439 if len(path) == 2 or path[2:3] not in br'\/': | 442 if len(path) == 2 or path[2:3] not in br'\/': |
440 path = os.path.abspath(path) | 443 path = os.path.abspath(path) |
441 return path | 444 return path |
442 | 445 |
443 if abort: | 446 if abort: |