Changeset View
Changeset View
Standalone View
Standalone View
mercurial/subrepoutil.py
Show All 17 Lines | from . import ( | ||||
config, | config, | ||||
error, | error, | ||||
filemerge, | filemerge, | ||||
pathutil, | pathutil, | ||||
phases, | phases, | ||||
pycompat, | pycompat, | ||||
util, | util, | ||||
) | ) | ||||
from .utils import stringutil | from .utils import ( | ||||
stringutil, | |||||
urlutil, | |||||
) | |||||
nullstate = (b'', b'', b'empty') | nullstate = (b'', b'', b'empty') | ||||
if pycompat.TYPE_CHECKING: | if pycompat.TYPE_CHECKING: | ||||
from typing import ( | from typing import ( | ||||
Any, | Any, | ||||
Dict, | Dict, | ||||
List, | List, | ||||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Line(s) | for path, src in p.items(b''): # type: bytes | ||||
kind = b'hg' | kind = b'hg' | ||||
if src.startswith(b'['): | if src.startswith(b'['): | ||||
if b']' not in src: | if b']' not in src: | ||||
raise error.Abort(_(b'missing ] in subrepository source')) | raise error.Abort(_(b'missing ] in subrepository source')) | ||||
kind, src = src.split(b']', 1) | kind, src = src.split(b']', 1) | ||||
kind = kind[1:] | kind = kind[1:] | ||||
src = src.lstrip() # strip any extra whitespace after ']' | src = src.lstrip() # strip any extra whitespace after ']' | ||||
if not util.url(src).isabs(): | if not urlutil.url(src).isabs(): | ||||
parent = _abssource(repo, abort=False) | parent = _abssource(repo, abort=False) | ||||
if parent: | if parent: | ||||
parent = util.url(parent) | parent = urlutil.url(parent) | ||||
parent.path = posixpath.join(parent.path or b'', src) | parent.path = posixpath.join(parent.path or b'', src) | ||||
parent.path = posixpath.normpath(parent.path) | parent.path = posixpath.normpath(parent.path) | ||||
joined = bytes(parent) | joined = bytes(parent) | ||||
# Remap the full joined path and use it if it changes, | # Remap the full joined path and use it if it changes, | ||||
# else remap the original source. | # else remap the original source. | ||||
remapped = remap(joined) | remapped = remap(joined) | ||||
if remapped == joined: | if remapped == joined: | ||||
src = remap(src) | src = remap(src) | ||||
▲ Show 20 Lines • Show All 244 Lines • ▼ Show 20 Line(s) | def subrelpath(sub): | ||||
return sub._relpath | return sub._relpath | ||||
def _abssource(repo, push=False, abort=True): | def _abssource(repo, push=False, abort=True): | ||||
# type: (localrepo.localrepository, bool, bool) -> Optional[bytes] | # type: (localrepo.localrepository, bool, bool) -> Optional[bytes] | ||||
"""return pull/push path of repo - either based on parent repo .hgsub info | """return pull/push path of repo - either based on parent repo .hgsub info | ||||
or on the top repo config. Abort or return None if no source found.""" | or on the top repo config. Abort or return None if no source found.""" | ||||
if util.safehasattr(repo, b'_subparent'): | if util.safehasattr(repo, b'_subparent'): | ||||
source = util.url(repo._subsource) | source = urlutil.url(repo._subsource) | ||||
if source.isabs(): | if source.isabs(): | ||||
return bytes(source) | return bytes(source) | ||||
source.path = posixpath.normpath(source.path) | source.path = posixpath.normpath(source.path) | ||||
parent = _abssource(repo._subparent, push, abort=False) | parent = _abssource(repo._subparent, push, abort=False) | ||||
if parent: | if parent: | ||||
parent = util.url(util.pconvert(parent)) | parent = urlutil.url(util.pconvert(parent)) | ||||
parent.path = posixpath.join(parent.path or b'', source.path) | parent.path = posixpath.join(parent.path or b'', source.path) | ||||
parent.path = posixpath.normpath(parent.path) | parent.path = posixpath.normpath(parent.path) | ||||
return bytes(parent) | return bytes(parent) | ||||
else: # recursion reached top repo | else: # recursion reached top repo | ||||
path = None | path = None | ||||
if util.safehasattr(repo, b'_subtoppath'): | if util.safehasattr(repo, b'_subtoppath'): | ||||
path = repo._subtoppath | path = repo._subtoppath | ||||
elif push and repo.ui.config(b'paths', b'default-push'): | elif push and repo.ui.config(b'paths', b'default-push'): | ||||
Show All 12 Lines | else: # recursion reached top repo | ||||
# | # | ||||
# C:\>cd C:\some\path | # C:\>cd C:\some\path | ||||
# C:\>D: | # C:\>D: | ||||
# D:\>python -c "import os; print os.path.abspath('C:')" | # D:\>python -c "import os; print os.path.abspath('C:')" | ||||
# C:\some\path | # C:\some\path | ||||
# | # | ||||
# D:\>python -c "import os; print os.path.abspath('C:relative')" | # D:\>python -c "import os; print os.path.abspath('C:relative')" | ||||
# C:\some\path\relative | # C:\some\path\relative | ||||
if util.hasdriveletter(path): | if urlutil.hasdriveletter(path): | ||||
if len(path) == 2 or path[2:3] not in br'\/': | if len(path) == 2 or path[2:3] not in br'\/': | ||||
path = os.path.abspath(path) | path = os.path.abspath(path) | ||||
return path | return path | ||||
if abort: | if abort: | ||||
raise error.Abort(_(b"default path for subrepository not found")) | raise error.Abort(_(b"default path for subrepository not found")) | ||||
▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines |