hg.py
70 lines
| 2.2 KiB
| text/x-python
|
PythonLexer
/ mercurial / hg.py
|
r0 | # hg.py - repository classes for mercurial | ||
# | ||||
# Copyright 2005 Matt Mackall <mpm@selenic.com> | ||||
# | ||||
# This software may be used and distributed according to the terms | ||||
# of the GNU General Public License, incorporated herein by reference. | ||||
|
r1089 | from node import * | ||
from repo import * | ||||
|
r262 | from demandload import * | ||
|
r2431 | from i18n import gettext as _ | ||
|
r1945 | demandload(globals(), "localrepo bundlerepo httprepo sshrepo statichttprepo") | ||
|
r2472 | demandload(globals(), "os util") | ||
|
r0 | |||
|
r2469 | def bundle(ui, path): | ||
if path.startswith('bundle://'): | ||||
path = path[9:] | ||||
else: | ||||
path = path[7:] | ||||
s = path.split("+", 1) | ||||
if len(s) == 1: | ||||
repopath, bundlename = "", s[0] | ||||
else: | ||||
repopath, bundlename = s | ||||
return bundlerepo.bundlerepository(ui, repopath, bundlename) | ||||
def hg(ui, path): | ||||
ui.warn(_("hg:// syntax is deprecated, please use http:// instead\n")) | ||||
return httprepo.httprepository(ui, path.replace("hg://", "http://")) | ||||
def local_(ui, path, create=0): | ||||
|
r2472 | if path.startswith('file:'): | ||
path = path[5:] | ||||
|
r2469 | return localrepo.localrepository(ui, path, create) | ||
def old_http(ui, path): | ||||
ui.warn(_("old-http:// syntax is deprecated, " | ||||
"please use static-http:// instead\n")) | ||||
return statichttprepo.statichttprepository( | ||||
ui, path.replace("old-http://", "http://")) | ||||
def static_http(ui, path): | ||||
return statichttprepo.statichttprepository( | ||||
ui, path.replace("static-http://", "http://")) | ||||
|
r2472 | schemes = { | ||
|
r2469 | 'bundle': bundle, | ||
'file': local_, | ||||
'hg': hg, | ||||
'http': lambda ui, path: httprepo.httprepository(ui, path), | ||||
'https': lambda ui, path: httprepo.httpsrepository(ui, path), | ||||
'old-http': old_http, | ||||
'ssh': lambda ui, path: sshrepo.sshrepository(ui, path), | ||||
'static-http': static_http, | ||||
} | ||||
|
r60 | def repository(ui, path=None, create=0): | ||
|
r2479 | if not path: path = '' | ||
|
r2469 | scheme = path | ||
if scheme: | ||||
c = scheme.find(':') | ||||
scheme = c >= 0 and scheme[:c] | ||||
try: | ||||
|
r2472 | ctor = schemes.get(scheme) or schemes['file'] | ||
|
r2469 | if create: | ||
return ctor(ui, path, create) | ||||
return ctor(ui, path) | ||||
except TypeError: | ||||
raise util.Abort(_('cannot create new repository over "%s" protocol') % | ||||
|
r2472 | scheme) | ||