Changeset View
Changeset View
Standalone View
Standalone View
hgext/lfs/blobstore.py
Show All 25 Lines | from mercurial import ( | ||||
pathutil, | pathutil, | ||||
pycompat, | pycompat, | ||||
url as urlmod, | url as urlmod, | ||||
util, | util, | ||||
vfs as vfsmod, | vfs as vfsmod, | ||||
worker, | worker, | ||||
) | ) | ||||
from mercurial.utils import stringutil | from mercurial.utils import ( | ||||
stringutil, | |||||
urlutil, | |||||
) | |||||
from ..largefiles import lfutil | from ..largefiles import lfutil | ||||
# 64 bytes for SHA256 | # 64 bytes for SHA256 | ||||
_lfsre = re.compile(br'\A[a-f0-9]{64}\Z') | _lfsre = re.compile(br'\A[a-f0-9]{64}\Z') | ||||
class lfsvfs(vfsmod.vfs): | class lfsvfs(vfsmod.vfs): | ||||
▲ Show 20 Lines • Show All 677 Lines • ▼ Show 20 Line(s) | def remote(repo, remote=None): | ||||
If ``lfs.url`` is specified, use that remote endpoint. Otherwise, try to | If ``lfs.url`` is specified, use that remote endpoint. Otherwise, try to | ||||
infer the endpoint, based on the remote repository using the same path | infer the endpoint, based on the remote repository using the same path | ||||
adjustments as git. As an extension, 'http' is supported as well so that | adjustments as git. As an extension, 'http' is supported as well so that | ||||
``hg serve`` works out of the box. | ``hg serve`` works out of the box. | ||||
https://github.com/git-lfs/git-lfs/blob/master/docs/api/server-discovery.md | https://github.com/git-lfs/git-lfs/blob/master/docs/api/server-discovery.md | ||||
""" | """ | ||||
lfsurl = repo.ui.config(b'lfs', b'url') | lfsurl = repo.ui.config(b'lfs', b'url') | ||||
url = util.url(lfsurl or b'') | url = urlutil.url(lfsurl or b'') | ||||
if lfsurl is None: | if lfsurl is None: | ||||
if remote: | if remote: | ||||
path = remote | path = remote | ||||
elif util.safehasattr(repo, b'_subtoppath'): | elif util.safehasattr(repo, b'_subtoppath'): | ||||
# The pull command sets this during the optional update phase, which | # The pull command sets this during the optional update phase, which | ||||
# tells exactly where the pull originated, whether 'paths.default' | # tells exactly where the pull originated, whether 'paths.default' | ||||
# or explicit. | # or explicit. | ||||
path = repo._subtoppath | path = repo._subtoppath | ||||
else: | else: | ||||
# TODO: investigate 'paths.remote:lfsurl' style path customization, | # TODO: investigate 'paths.remote:lfsurl' style path customization, | ||||
# and fall back to inferring from 'paths.remote' if unspecified. | # and fall back to inferring from 'paths.remote' if unspecified. | ||||
path = repo.ui.config(b'paths', b'default') or b'' | path = repo.ui.config(b'paths', b'default') or b'' | ||||
defaulturl = util.url(path) | defaulturl = urlutil.url(path) | ||||
# TODO: support local paths as well. | # TODO: support local paths as well. | ||||
# TODO: consider the ssh -> https transformation that git applies | # TODO: consider the ssh -> https transformation that git applies | ||||
if defaulturl.scheme in (b'http', b'https'): | if defaulturl.scheme in (b'http', b'https'): | ||||
if defaulturl.path and defaulturl.path[:-1] != b'/': | if defaulturl.path and defaulturl.path[:-1] != b'/': | ||||
defaulturl.path += b'/' | defaulturl.path += b'/' | ||||
defaulturl.path = (defaulturl.path or b'') + b'.git/info/lfs' | defaulturl.path = (defaulturl.path or b'') + b'.git/info/lfs' | ||||
url = util.url(bytes(defaulturl)) | url = urlutil.url(bytes(defaulturl)) | ||||
repo.ui.note(_(b'lfs: assuming remote store: %s\n') % url) | repo.ui.note(_(b'lfs: assuming remote store: %s\n') % url) | ||||
scheme = url.scheme | scheme = url.scheme | ||||
if scheme not in _storemap: | if scheme not in _storemap: | ||||
raise error.Abort(_(b'lfs: unknown url scheme: %s') % scheme) | raise error.Abort(_(b'lfs: unknown url scheme: %s') % scheme) | ||||
return _storemap[scheme](repo, url) | return _storemap[scheme](repo, url) | ||||
class LfsRemoteError(error.StorageError): | class LfsRemoteError(error.StorageError): | ||||
pass | pass | ||||
class LfsCorruptionError(error.Abort): | class LfsCorruptionError(error.Abort): | ||||
"""Raised when a corrupt blob is detected, aborting an operation | """Raised when a corrupt blob is detected, aborting an operation | ||||
It exists to allow specialized handling on the server side.""" | It exists to allow specialized handling on the server side.""" |