##// END OF EJS Templates
schemas: use absolute_import
timeless -
r28379:27a90323 default
parent child Browse files
Show More
@@ -1,122 +1,131 b''
1 # Copyright 2009, Alexander Solovyov <piranha@piranha.org.ua>
1 # Copyright 2009, Alexander Solovyov <piranha@piranha.org.ua>
2 #
2 #
3 # This software may be used and distributed according to the terms of the
3 # This software may be used and distributed according to the terms of the
4 # GNU General Public License version 2 or any later version.
4 # GNU General Public License version 2 or any later version.
5
5
6 """extend schemes with shortcuts to repository swarms
6 """extend schemes with shortcuts to repository swarms
7
7
8 This extension allows you to specify shortcuts for parent URLs with a
8 This extension allows you to specify shortcuts for parent URLs with a
9 lot of repositories to act like a scheme, for example::
9 lot of repositories to act like a scheme, for example::
10
10
11 [schemes]
11 [schemes]
12 py = http://code.python.org/hg/
12 py = http://code.python.org/hg/
13
13
14 After that you can use it like::
14 After that you can use it like::
15
15
16 hg clone py://trunk/
16 hg clone py://trunk/
17
17
18 Additionally there is support for some more complex schemas, for
18 Additionally there is support for some more complex schemas, for
19 example used by Google Code::
19 example used by Google Code::
20
20
21 [schemes]
21 [schemes]
22 gcode = http://{1}.googlecode.com/hg/
22 gcode = http://{1}.googlecode.com/hg/
23
23
24 The syntax is taken from Mercurial templates, and you have unlimited
24 The syntax is taken from Mercurial templates, and you have unlimited
25 number of variables, starting with ``{1}`` and continuing with
25 number of variables, starting with ``{1}`` and continuing with
26 ``{2}``, ``{3}`` and so on. This variables will receive parts of URL
26 ``{2}``, ``{3}`` and so on. This variables will receive parts of URL
27 supplied, split by ``/``. Anything not specified as ``{part}`` will be
27 supplied, split by ``/``. Anything not specified as ``{part}`` will be
28 just appended to an URL.
28 just appended to an URL.
29
29
30 For convenience, the extension adds these schemes by default::
30 For convenience, the extension adds these schemes by default::
31
31
32 [schemes]
32 [schemes]
33 py = http://hg.python.org/
33 py = http://hg.python.org/
34 bb = https://bitbucket.org/
34 bb = https://bitbucket.org/
35 bb+ssh = ssh://hg@bitbucket.org/
35 bb+ssh = ssh://hg@bitbucket.org/
36 gcode = https://{1}.googlecode.com/hg/
36 gcode = https://{1}.googlecode.com/hg/
37 kiln = https://{1}.kilnhg.com/Repo/
37 kiln = https://{1}.kilnhg.com/Repo/
38
38
39 You can override a predefined scheme by defining a new scheme with the
39 You can override a predefined scheme by defining a new scheme with the
40 same name.
40 same name.
41 """
41 """
42 from __future__ import absolute_import
42
43
43 import os, re
44 import os
44 from mercurial import extensions, hg, templater, util, error, cmdutil
45 import re
46 from mercurial import (
47 cmdutil,
48 error,
49 extensions,
50 hg,
51 templater,
52 util,
53 )
45 from mercurial.i18n import _
54 from mercurial.i18n import _
46
55
47 cmdtable = {}
56 cmdtable = {}
48 command = cmdutil.command(cmdtable)
57 command = cmdutil.command(cmdtable)
49 # Note for extension authors: ONLY specify testedwith = 'internal' for
58 # Note for extension authors: ONLY specify testedwith = 'internal' for
50 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
59 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
51 # be specifying the version(s) of Mercurial they are tested with, or
60 # be specifying the version(s) of Mercurial they are tested with, or
52 # leave the attribute unspecified.
61 # leave the attribute unspecified.
53 testedwith = 'internal'
62 testedwith = 'internal'
54
63
55
64
56 class ShortRepository(object):
65 class ShortRepository(object):
57 def __init__(self, url, scheme, templater):
66 def __init__(self, url, scheme, templater):
58 self.scheme = scheme
67 self.scheme = scheme
59 self.templater = templater
68 self.templater = templater
60 self.url = url
69 self.url = url
61 try:
70 try:
62 self.parts = max(map(int, re.findall(r'\{(\d+)\}', self.url)))
71 self.parts = max(map(int, re.findall(r'\{(\d+)\}', self.url)))
63 except ValueError:
72 except ValueError:
64 self.parts = 0
73 self.parts = 0
65
74
66 def __repr__(self):
75 def __repr__(self):
67 return '<ShortRepository: %s>' % self.scheme
76 return '<ShortRepository: %s>' % self.scheme
68
77
69 def instance(self, ui, url, create):
78 def instance(self, ui, url, create):
70 url = self.resolve(url)
79 url = self.resolve(url)
71 return hg._peerlookup(url).instance(ui, url, create)
80 return hg._peerlookup(url).instance(ui, url, create)
72
81
73 def resolve(self, url):
82 def resolve(self, url):
74 # Should this use the util.url class, or is manual parsing better?
83 # Should this use the util.url class, or is manual parsing better?
75 try:
84 try:
76 url = url.split('://', 1)[1]
85 url = url.split('://', 1)[1]
77 except IndexError:
86 except IndexError:
78 raise error.Abort(_("no '://' in scheme url '%s'") % url)
87 raise error.Abort(_("no '://' in scheme url '%s'") % url)
79 parts = url.split('/', self.parts)
88 parts = url.split('/', self.parts)
80 if len(parts) > self.parts:
89 if len(parts) > self.parts:
81 tail = parts[-1]
90 tail = parts[-1]
82 parts = parts[:-1]
91 parts = parts[:-1]
83 else:
92 else:
84 tail = ''
93 tail = ''
85 context = dict((str(i + 1), v) for i, v in enumerate(parts))
94 context = dict((str(i + 1), v) for i, v in enumerate(parts))
86 return ''.join(self.templater.process(self.url, context)) + tail
95 return ''.join(self.templater.process(self.url, context)) + tail
87
96
88 def hasdriveletter(orig, path):
97 def hasdriveletter(orig, path):
89 if path:
98 if path:
90 for scheme in schemes:
99 for scheme in schemes:
91 if path.startswith(scheme + ':'):
100 if path.startswith(scheme + ':'):
92 return False
101 return False
93 return orig(path)
102 return orig(path)
94
103
95 schemes = {
104 schemes = {
96 'py': 'http://hg.python.org/',
105 'py': 'http://hg.python.org/',
97 'bb': 'https://bitbucket.org/',
106 'bb': 'https://bitbucket.org/',
98 'bb+ssh': 'ssh://hg@bitbucket.org/',
107 'bb+ssh': 'ssh://hg@bitbucket.org/',
99 'gcode': 'https://{1}.googlecode.com/hg/',
108 'gcode': 'https://{1}.googlecode.com/hg/',
100 'kiln': 'https://{1}.kilnhg.com/Repo/'
109 'kiln': 'https://{1}.kilnhg.com/Repo/'
101 }
110 }
102
111
103 def extsetup(ui):
112 def extsetup(ui):
104 schemes.update(dict(ui.configitems('schemes')))
113 schemes.update(dict(ui.configitems('schemes')))
105 t = templater.engine(lambda x: x)
114 t = templater.engine(lambda x: x)
106 for scheme, url in schemes.items():
115 for scheme, url in schemes.items():
107 if (os.name == 'nt' and len(scheme) == 1 and scheme.isalpha()
116 if (os.name == 'nt' and len(scheme) == 1 and scheme.isalpha()
108 and os.path.exists('%s:\\' % scheme)):
117 and os.path.exists('%s:\\' % scheme)):
109 raise error.Abort(_('custom scheme %s:// conflicts with drive '
118 raise error.Abort(_('custom scheme %s:// conflicts with drive '
110 'letter %s:\\\n') % (scheme, scheme.upper()))
119 'letter %s:\\\n') % (scheme, scheme.upper()))
111 hg.schemes[scheme] = ShortRepository(url, scheme, t)
120 hg.schemes[scheme] = ShortRepository(url, scheme, t)
112
121
113 extensions.wrapfunction(util, 'hasdriveletter', hasdriveletter)
122 extensions.wrapfunction(util, 'hasdriveletter', hasdriveletter)
114
123
115 @command('debugexpandscheme', norepo=True)
124 @command('debugexpandscheme', norepo=True)
116 def expandscheme(ui, url, **opts):
125 def expandscheme(ui, url, **opts):
117 """given a repo path, provide the scheme-expanded path
126 """given a repo path, provide the scheme-expanded path
118 """
127 """
119 repo = hg._peerlookup(url)
128 repo = hg._peerlookup(url)
120 if isinstance(repo, ShortRepository):
129 if isinstance(repo, ShortRepository):
121 url = repo.resolve(url)
130 url = repo.resolve(url)
122 ui.write(url + '\n')
131 ui.write(url + '\n')
@@ -1,148 +1,147 b''
1 #require test-repo
1 #require test-repo
2
2
3 $ cd "$TESTDIR"/..
3 $ cd "$TESTDIR"/..
4
4
5 $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs python contrib/check-py3-compat.py
5 $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs python contrib/check-py3-compat.py
6 contrib/check-code.py not using absolute_import
6 contrib/check-code.py not using absolute_import
7 contrib/check-code.py requires print_function
7 contrib/check-code.py requires print_function
8 contrib/debugshell.py not using absolute_import
8 contrib/debugshell.py not using absolute_import
9 contrib/hgfixes/fix_bytes.py not using absolute_import
9 contrib/hgfixes/fix_bytes.py not using absolute_import
10 contrib/hgfixes/fix_bytesmod.py not using absolute_import
10 contrib/hgfixes/fix_bytesmod.py not using absolute_import
11 contrib/hgfixes/fix_leftover_imports.py not using absolute_import
11 contrib/hgfixes/fix_leftover_imports.py not using absolute_import
12 contrib/import-checker.py not using absolute_import
12 contrib/import-checker.py not using absolute_import
13 contrib/import-checker.py requires print_function
13 contrib/import-checker.py requires print_function
14 contrib/memory.py not using absolute_import
14 contrib/memory.py not using absolute_import
15 contrib/perf.py not using absolute_import
15 contrib/perf.py not using absolute_import
16 contrib/python-hook-examples.py not using absolute_import
16 contrib/python-hook-examples.py not using absolute_import
17 contrib/revsetbenchmarks.py not using absolute_import
17 contrib/revsetbenchmarks.py not using absolute_import
18 contrib/revsetbenchmarks.py requires print_function
18 contrib/revsetbenchmarks.py requires print_function
19 contrib/showstack.py not using absolute_import
19 contrib/showstack.py not using absolute_import
20 contrib/synthrepo.py not using absolute_import
20 contrib/synthrepo.py not using absolute_import
21 contrib/win32/hgwebdir_wsgi.py not using absolute_import
21 contrib/win32/hgwebdir_wsgi.py not using absolute_import
22 doc/check-seclevel.py not using absolute_import
22 doc/check-seclevel.py not using absolute_import
23 doc/gendoc.py not using absolute_import
23 doc/gendoc.py not using absolute_import
24 doc/hgmanpage.py not using absolute_import
24 doc/hgmanpage.py not using absolute_import
25 hgext/__init__.py not using absolute_import
25 hgext/__init__.py not using absolute_import
26 hgext/color.py not using absolute_import
26 hgext/color.py not using absolute_import
27 hgext/convert/__init__.py not using absolute_import
27 hgext/convert/__init__.py not using absolute_import
28 hgext/convert/bzr.py not using absolute_import
28 hgext/convert/bzr.py not using absolute_import
29 hgext/convert/common.py not using absolute_import
29 hgext/convert/common.py not using absolute_import
30 hgext/convert/convcmd.py not using absolute_import
30 hgext/convert/convcmd.py not using absolute_import
31 hgext/convert/cvs.py not using absolute_import
31 hgext/convert/cvs.py not using absolute_import
32 hgext/convert/subversion.py not using absolute_import
32 hgext/convert/subversion.py not using absolute_import
33 hgext/convert/transport.py not using absolute_import
33 hgext/convert/transport.py not using absolute_import
34 hgext/eol.py not using absolute_import
34 hgext/eol.py not using absolute_import
35 hgext/extdiff.py not using absolute_import
35 hgext/extdiff.py not using absolute_import
36 hgext/factotum.py not using absolute_import
36 hgext/factotum.py not using absolute_import
37 hgext/fetch.py not using absolute_import
37 hgext/fetch.py not using absolute_import
38 hgext/gpg.py not using absolute_import
38 hgext/gpg.py not using absolute_import
39 hgext/graphlog.py not using absolute_import
39 hgext/graphlog.py not using absolute_import
40 hgext/hgcia.py not using absolute_import
40 hgext/hgcia.py not using absolute_import
41 hgext/hgk.py not using absolute_import
41 hgext/hgk.py not using absolute_import
42 hgext/highlight/__init__.py not using absolute_import
42 hgext/highlight/__init__.py not using absolute_import
43 hgext/highlight/highlight.py not using absolute_import
43 hgext/highlight/highlight.py not using absolute_import
44 hgext/histedit.py not using absolute_import
44 hgext/histedit.py not using absolute_import
45 hgext/largefiles/__init__.py not using absolute_import
45 hgext/largefiles/__init__.py not using absolute_import
46 hgext/largefiles/basestore.py not using absolute_import
46 hgext/largefiles/basestore.py not using absolute_import
47 hgext/largefiles/lfcommands.py not using absolute_import
47 hgext/largefiles/lfcommands.py not using absolute_import
48 hgext/largefiles/lfutil.py not using absolute_import
48 hgext/largefiles/lfutil.py not using absolute_import
49 hgext/largefiles/localstore.py not using absolute_import
49 hgext/largefiles/localstore.py not using absolute_import
50 hgext/largefiles/overrides.py not using absolute_import
50 hgext/largefiles/overrides.py not using absolute_import
51 hgext/largefiles/proto.py not using absolute_import
51 hgext/largefiles/proto.py not using absolute_import
52 hgext/largefiles/remotestore.py not using absolute_import
52 hgext/largefiles/remotestore.py not using absolute_import
53 hgext/largefiles/reposetup.py not using absolute_import
53 hgext/largefiles/reposetup.py not using absolute_import
54 hgext/largefiles/uisetup.py not using absolute_import
54 hgext/largefiles/uisetup.py not using absolute_import
55 hgext/largefiles/wirestore.py not using absolute_import
55 hgext/largefiles/wirestore.py not using absolute_import
56 hgext/mq.py not using absolute_import
56 hgext/mq.py not using absolute_import
57 hgext/notify.py not using absolute_import
57 hgext/notify.py not using absolute_import
58 hgext/patchbomb.py not using absolute_import
58 hgext/patchbomb.py not using absolute_import
59 hgext/purge.py not using absolute_import
59 hgext/purge.py not using absolute_import
60 hgext/rebase.py not using absolute_import
60 hgext/rebase.py not using absolute_import
61 hgext/record.py not using absolute_import
61 hgext/record.py not using absolute_import
62 hgext/relink.py not using absolute_import
62 hgext/relink.py not using absolute_import
63 hgext/schemes.py not using absolute_import
64 hgext/share.py not using absolute_import
63 hgext/share.py not using absolute_import
65 hgext/transplant.py not using absolute_import
64 hgext/transplant.py not using absolute_import
66 hgext/win32mbcs.py not using absolute_import
65 hgext/win32mbcs.py not using absolute_import
67 hgext/win32text.py not using absolute_import
66 hgext/win32text.py not using absolute_import
68 i18n/check-translation.py not using absolute_import
67 i18n/check-translation.py not using absolute_import
69 i18n/polib.py not using absolute_import
68 i18n/polib.py not using absolute_import
70 setup.py not using absolute_import
69 setup.py not using absolute_import
71 tests/filterpyflakes.py requires print_function
70 tests/filterpyflakes.py requires print_function
72 tests/generate-working-copy-states.py requires print_function
71 tests/generate-working-copy-states.py requires print_function
73 tests/get-with-headers.py requires print_function
72 tests/get-with-headers.py requires print_function
74 tests/heredoctest.py requires print_function
73 tests/heredoctest.py requires print_function
75 tests/hypothesishelpers.py not using absolute_import
74 tests/hypothesishelpers.py not using absolute_import
76 tests/hypothesishelpers.py requires print_function
75 tests/hypothesishelpers.py requires print_function
77 tests/killdaemons.py not using absolute_import
76 tests/killdaemons.py not using absolute_import
78 tests/md5sum.py not using absolute_import
77 tests/md5sum.py not using absolute_import
79 tests/mockblackbox.py not using absolute_import
78 tests/mockblackbox.py not using absolute_import
80 tests/printenv.py not using absolute_import
79 tests/printenv.py not using absolute_import
81 tests/readlink.py not using absolute_import
80 tests/readlink.py not using absolute_import
82 tests/readlink.py requires print_function
81 tests/readlink.py requires print_function
83 tests/revlog-formatv0.py not using absolute_import
82 tests/revlog-formatv0.py not using absolute_import
84 tests/run-tests.py not using absolute_import
83 tests/run-tests.py not using absolute_import
85 tests/seq.py not using absolute_import
84 tests/seq.py not using absolute_import
86 tests/seq.py requires print_function
85 tests/seq.py requires print_function
87 tests/silenttestrunner.py not using absolute_import
86 tests/silenttestrunner.py not using absolute_import
88 tests/silenttestrunner.py requires print_function
87 tests/silenttestrunner.py requires print_function
89 tests/sitecustomize.py not using absolute_import
88 tests/sitecustomize.py not using absolute_import
90 tests/svn-safe-append.py not using absolute_import
89 tests/svn-safe-append.py not using absolute_import
91 tests/svnxml.py not using absolute_import
90 tests/svnxml.py not using absolute_import
92 tests/test-ancestor.py requires print_function
91 tests/test-ancestor.py requires print_function
93 tests/test-atomictempfile.py not using absolute_import
92 tests/test-atomictempfile.py not using absolute_import
94 tests/test-batching.py not using absolute_import
93 tests/test-batching.py not using absolute_import
95 tests/test-batching.py requires print_function
94 tests/test-batching.py requires print_function
96 tests/test-bdiff.py not using absolute_import
95 tests/test-bdiff.py not using absolute_import
97 tests/test-bdiff.py requires print_function
96 tests/test-bdiff.py requires print_function
98 tests/test-context.py not using absolute_import
97 tests/test-context.py not using absolute_import
99 tests/test-context.py requires print_function
98 tests/test-context.py requires print_function
100 tests/test-demandimport.py not using absolute_import
99 tests/test-demandimport.py not using absolute_import
101 tests/test-demandimport.py requires print_function
100 tests/test-demandimport.py requires print_function
102 tests/test-dispatch.py not using absolute_import
101 tests/test-dispatch.py not using absolute_import
103 tests/test-dispatch.py requires print_function
102 tests/test-dispatch.py requires print_function
104 tests/test-doctest.py not using absolute_import
103 tests/test-doctest.py not using absolute_import
105 tests/test-duplicateoptions.py not using absolute_import
104 tests/test-duplicateoptions.py not using absolute_import
106 tests/test-duplicateoptions.py requires print_function
105 tests/test-duplicateoptions.py requires print_function
107 tests/test-filecache.py not using absolute_import
106 tests/test-filecache.py not using absolute_import
108 tests/test-filecache.py requires print_function
107 tests/test-filecache.py requires print_function
109 tests/test-filelog.py not using absolute_import
108 tests/test-filelog.py not using absolute_import
110 tests/test-filelog.py requires print_function
109 tests/test-filelog.py requires print_function
111 tests/test-hg-parseurl.py not using absolute_import
110 tests/test-hg-parseurl.py not using absolute_import
112 tests/test-hg-parseurl.py requires print_function
111 tests/test-hg-parseurl.py requires print_function
113 tests/test-hgweb-auth.py not using absolute_import
112 tests/test-hgweb-auth.py not using absolute_import
114 tests/test-hgweb-auth.py requires print_function
113 tests/test-hgweb-auth.py requires print_function
115 tests/test-hgwebdir-paths.py not using absolute_import
114 tests/test-hgwebdir-paths.py not using absolute_import
116 tests/test-hybridencode.py not using absolute_import
115 tests/test-hybridencode.py not using absolute_import
117 tests/test-hybridencode.py requires print_function
116 tests/test-hybridencode.py requires print_function
118 tests/test-lrucachedict.py not using absolute_import
117 tests/test-lrucachedict.py not using absolute_import
119 tests/test-lrucachedict.py requires print_function
118 tests/test-lrucachedict.py requires print_function
120 tests/test-manifest.py not using absolute_import
119 tests/test-manifest.py not using absolute_import
121 tests/test-minirst.py not using absolute_import
120 tests/test-minirst.py not using absolute_import
122 tests/test-minirst.py requires print_function
121 tests/test-minirst.py requires print_function
123 tests/test-parseindex2.py not using absolute_import
122 tests/test-parseindex2.py not using absolute_import
124 tests/test-parseindex2.py requires print_function
123 tests/test-parseindex2.py requires print_function
125 tests/test-pathencode.py not using absolute_import
124 tests/test-pathencode.py not using absolute_import
126 tests/test-pathencode.py requires print_function
125 tests/test-pathencode.py requires print_function
127 tests/test-propertycache.py not using absolute_import
126 tests/test-propertycache.py not using absolute_import
128 tests/test-propertycache.py requires print_function
127 tests/test-propertycache.py requires print_function
129 tests/test-revlog-ancestry.py not using absolute_import
128 tests/test-revlog-ancestry.py not using absolute_import
130 tests/test-revlog-ancestry.py requires print_function
129 tests/test-revlog-ancestry.py requires print_function
131 tests/test-run-tests.py not using absolute_import
130 tests/test-run-tests.py not using absolute_import
132 tests/test-simplemerge.py not using absolute_import
131 tests/test-simplemerge.py not using absolute_import
133 tests/test-status-inprocess.py not using absolute_import
132 tests/test-status-inprocess.py not using absolute_import
134 tests/test-status-inprocess.py requires print_function
133 tests/test-status-inprocess.py requires print_function
135 tests/test-symlink-os-yes-fs-no.py not using absolute_import
134 tests/test-symlink-os-yes-fs-no.py not using absolute_import
136 tests/test-trusted.py not using absolute_import
135 tests/test-trusted.py not using absolute_import
137 tests/test-trusted.py requires print_function
136 tests/test-trusted.py requires print_function
138 tests/test-ui-color.py not using absolute_import
137 tests/test-ui-color.py not using absolute_import
139 tests/test-ui-color.py requires print_function
138 tests/test-ui-color.py requires print_function
140 tests/test-ui-config.py not using absolute_import
139 tests/test-ui-config.py not using absolute_import
141 tests/test-ui-config.py requires print_function
140 tests/test-ui-config.py requires print_function
142 tests/test-ui-verbosity.py not using absolute_import
141 tests/test-ui-verbosity.py not using absolute_import
143 tests/test-ui-verbosity.py requires print_function
142 tests/test-ui-verbosity.py requires print_function
144 tests/test-url.py not using absolute_import
143 tests/test-url.py not using absolute_import
145 tests/test-url.py requires print_function
144 tests/test-url.py requires print_function
146 tests/test-walkrepo.py requires print_function
145 tests/test-walkrepo.py requires print_function
147 tests/test-wireproto.py requires print_function
146 tests/test-wireproto.py requires print_function
148 tests/tinyproxy.py requires print_function
147 tests/tinyproxy.py requires print_function
General Comments 0
You need to be logged in to leave comments. Login now