63 # leave the attribute unspecified. |
63 # leave the attribute unspecified. |
64 testedwith = 'ships-with-hg-core' |
64 testedwith = 'ships-with-hg-core' |
65 |
65 |
66 _partre = re.compile(br'\{(\d+)\}') |
66 _partre = re.compile(br'\{(\d+)\}') |
67 |
67 |
|
68 |
68 class ShortRepository(object): |
69 class ShortRepository(object): |
69 def __init__(self, url, scheme, templater): |
70 def __init__(self, url, scheme, templater): |
70 self.scheme = scheme |
71 self.scheme = scheme |
71 self.templater = templater |
72 self.templater = templater |
72 self.url = url |
73 self.url = url |
78 def __repr__(self): |
79 def __repr__(self): |
79 return '<ShortRepository: %s>' % self.scheme |
80 return '<ShortRepository: %s>' % self.scheme |
80 |
81 |
81 def instance(self, ui, url, create, intents=None, createopts=None): |
82 def instance(self, ui, url, create, intents=None, createopts=None): |
82 url = self.resolve(url) |
83 url = self.resolve(url) |
83 return hg._peerlookup(url).instance(ui, url, create, intents=intents, |
84 return hg._peerlookup(url).instance( |
84 createopts=createopts) |
85 ui, url, create, intents=intents, createopts=createopts |
|
86 ) |
85 |
87 |
86 def resolve(self, url): |
88 def resolve(self, url): |
87 # Should this use the util.url class, or is manual parsing better? |
89 # Should this use the util.url class, or is manual parsing better? |
88 try: |
90 try: |
89 url = url.split('://', 1)[1] |
91 url = url.split('://', 1)[1] |
96 else: |
98 else: |
97 tail = '' |
99 tail = '' |
98 context = dict(('%d' % (i + 1), v) for i, v in enumerate(parts)) |
100 context = dict(('%d' % (i + 1), v) for i, v in enumerate(parts)) |
99 return ''.join(self.templater.process(self.url, context)) + tail |
101 return ''.join(self.templater.process(self.url, context)) + tail |
100 |
102 |
|
103 |
101 def hasdriveletter(orig, path): |
104 def hasdriveletter(orig, path): |
102 if path: |
105 if path: |
103 for scheme in schemes: |
106 for scheme in schemes: |
104 if path.startswith(scheme + ':'): |
107 if path.startswith(scheme + ':'): |
105 return False |
108 return False |
106 return orig(path) |
109 return orig(path) |
107 |
110 |
|
111 |
108 schemes = { |
112 schemes = { |
109 'py': 'http://hg.python.org/', |
113 'py': 'http://hg.python.org/', |
110 'bb': 'https://bitbucket.org/', |
114 'bb': 'https://bitbucket.org/', |
111 'bb+ssh': 'ssh://hg@bitbucket.org/', |
115 'bb+ssh': 'ssh://hg@bitbucket.org/', |
112 'gcode': 'https://{1}.googlecode.com/hg/', |
116 'gcode': 'https://{1}.googlecode.com/hg/', |
113 'kiln': 'https://{1}.kilnhg.com/Repo/' |
117 'kiln': 'https://{1}.kilnhg.com/Repo/', |
114 } |
118 } |
|
119 |
115 |
120 |
116 def extsetup(ui): |
121 def extsetup(ui): |
117 schemes.update(dict(ui.configitems('schemes'))) |
122 schemes.update(dict(ui.configitems('schemes'))) |
118 t = templater.engine(templater.parse) |
123 t = templater.engine(templater.parse) |
119 for scheme, url in schemes.items(): |
124 for scheme, url in schemes.items(): |
120 if (pycompat.iswindows and len(scheme) == 1 and scheme.isalpha() |
125 if ( |
121 and os.path.exists('%s:\\' % scheme)): |
126 pycompat.iswindows |
122 raise error.Abort(_('custom scheme %s:// conflicts with drive ' |
127 and len(scheme) == 1 |
123 'letter %s:\\\n') % (scheme, scheme.upper())) |
128 and scheme.isalpha() |
|
129 and os.path.exists('%s:\\' % scheme) |
|
130 ): |
|
131 raise error.Abort( |
|
132 _('custom scheme %s:// conflicts with drive ' 'letter %s:\\\n') |
|
133 % (scheme, scheme.upper()) |
|
134 ) |
124 hg.schemes[scheme] = ShortRepository(url, scheme, t) |
135 hg.schemes[scheme] = ShortRepository(url, scheme, t) |
125 |
136 |
126 extensions.wrapfunction(util, 'hasdriveletter', hasdriveletter) |
137 extensions.wrapfunction(util, 'hasdriveletter', hasdriveletter) |
|
138 |
127 |
139 |
128 @command('debugexpandscheme', norepo=True) |
140 @command('debugexpandscheme', norepo=True) |
129 def expandscheme(ui, url, **opts): |
141 def expandscheme(ui, url, **opts): |
130 """given a repo path, provide the scheme-expanded path |
142 """given a repo path, provide the scheme-expanded path |
131 """ |
143 """ |