Changeset View
Changeset View
Standalone View
Standalone View
hgext/schemes.py
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | |||||
from mercurial.i18n import _ | from mercurial.i18n import _ | ||||
from mercurial import ( | from mercurial import ( | ||||
error, | error, | ||||
extensions, | extensions, | ||||
hg, | hg, | ||||
pycompat, | pycompat, | ||||
registrar, | registrar, | ||||
templater, | templater, | ||||
util, | ) | ||||
from mercurial.utils import ( | |||||
urlutil, | |||||
) | ) | ||||
cmdtable = {} | cmdtable = {} | ||||
command = registrar.command(cmdtable) | command = registrar.command(cmdtable) | ||||
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for | # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for | ||||
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should | # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should | ||||
# be specifying the version(s) of Mercurial they are tested with, or | # be specifying the version(s) of Mercurial they are tested with, or | ||||
# leave the attribute unspecified. | # leave the attribute unspecified. | ||||
Show All 17 Lines | class ShortRepository(object): | ||||
def instance(self, ui, url, create, intents=None, createopts=None): | def instance(self, ui, url, create, intents=None, createopts=None): | ||||
url = self.resolve(url) | url = self.resolve(url) | ||||
return hg._peerlookup(url).instance( | return hg._peerlookup(url).instance( | ||||
ui, url, create, intents=intents, createopts=createopts | ui, url, create, intents=intents, createopts=createopts | ||||
) | ) | ||||
def resolve(self, url): | def resolve(self, url): | ||||
# Should this use the util.url class, or is manual parsing better? | # Should this use the urlutil.url class, or is manual parsing better? | ||||
try: | try: | ||||
url = url.split(b'://', 1)[1] | url = url.split(b'://', 1)[1] | ||||
except IndexError: | except IndexError: | ||||
raise error.Abort(_(b"no '://' in scheme url '%s'") % url) | raise error.Abort(_(b"no '://' in scheme url '%s'") % url) | ||||
parts = url.split(b'/', self.parts) | parts = url.split(b'/', self.parts) | ||||
if len(parts) > self.parts: | if len(parts) > self.parts: | ||||
tail = parts[-1] | tail = parts[-1] | ||||
parts = parts[:-1] | parts = parts[:-1] | ||||
Show All 34 Lines | for scheme, url in schemes.items(): | ||||
_( | _( | ||||
b'custom scheme %s:// conflicts with drive ' | b'custom scheme %s:// conflicts with drive ' | ||||
b'letter %s:\\\n' | b'letter %s:\\\n' | ||||
) | ) | ||||
% (scheme, scheme.upper()) | % (scheme, scheme.upper()) | ||||
) | ) | ||||
hg.schemes[scheme] = ShortRepository(url, scheme, t) | hg.schemes[scheme] = ShortRepository(url, scheme, t) | ||||
extensions.wrapfunction(util, b'hasdriveletter', hasdriveletter) | extensions.wrapfunction(urlutil, b'hasdriveletter', hasdriveletter) | ||||
@command(b'debugexpandscheme', norepo=True) | @command(b'debugexpandscheme', norepo=True) | ||||
def expandscheme(ui, url, **opts): | def expandscheme(ui, url, **opts): | ||||
"""given a repo path, provide the scheme-expanded path""" | """given a repo path, provide the scheme-expanded path""" | ||||
repo = hg._peerlookup(url) | repo = hg._peerlookup(url) | ||||
if isinstance(repo, ShortRepository): | if isinstance(repo, ShortRepository): | ||||
url = repo.resolve(url) | url = repo.resolve(url) | ||||
ui.write(url + b'\n') | ui.write(url + b'\n') |