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