##// END OF EJS Templates
schemes: url parts are counted from 1
Alexander Solovyov -
r10070:9d1195b2 stable
parent child Browse files
Show More
@@ -1,82 +1,82 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, incorporated herein by reference.
4 # GNU General Public License version 2, incorporated herein by reference.
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
37
38 You can override a predefined scheme by defining a new scheme with the
38 You can override a predefined scheme by defining a new scheme with the
39 same name.
39 same name.
40 """
40 """
41
41
42 import re
42 import re
43 from mercurial import hg, templater
43 from mercurial import hg, templater
44
44
45
45
46 class ShortRepository(object):
46 class ShortRepository(object):
47 def __init__(self, url, scheme, templater):
47 def __init__(self, url, scheme, templater):
48 self.scheme = scheme
48 self.scheme = scheme
49 self.templater = templater
49 self.templater = templater
50 self.url = url
50 self.url = url
51 try:
51 try:
52 self.parts = max(map(int, re.findall(r'\{(\d+)\}', self.url)))
52 self.parts = max(map(int, re.findall(r'\{(\d+)\}', self.url)))
53 except ValueError:
53 except ValueError:
54 self.parts = 0
54 self.parts = 0
55
55
56 def __repr__(self):
56 def __repr__(self):
57 return '<ShortRepository: %s>' % self.scheme
57 return '<ShortRepository: %s>' % self.scheme
58
58
59 def instance(self, ui, url, create):
59 def instance(self, ui, url, create):
60 url = url.split('://', 1)[1]
60 url = url.split('://', 1)[1]
61 parts = url.split('/', self.parts)
61 parts = url.split('/', self.parts)
62 if len(parts) > self.parts:
62 if len(parts) > self.parts:
63 tail = parts[-1]
63 tail = parts[-1]
64 parts = parts[:-1]
64 parts = parts[:-1]
65 else:
65 else:
66 tail = ''
66 tail = ''
67 context = dict((str(i), v) for i, v in enumerate(parts))
67 context = dict((str(i+1), v) for i, v in enumerate(parts))
68 url = ''.join(self.templater.process(self.url, context)) + tail
68 url = ''.join(self.templater.process(self.url, context)) + tail
69 return hg._lookup(url).instance(ui, url, create)
69 return hg._lookup(url).instance(ui, url, create)
70
70
71 schemes = {
71 schemes = {
72 'py': 'http://hg.python.org/',
72 'py': 'http://hg.python.org/',
73 'bb': 'https://bitbucket.org/',
73 'bb': 'https://bitbucket.org/',
74 'bb+ssh': 'ssh://hg@bitbucket.org/',
74 'bb+ssh': 'ssh://hg@bitbucket.org/',
75 'gcode': 'https://{1}.googlecode.com/hg/'
75 'gcode': 'https://{1}.googlecode.com/hg/'
76 }
76 }
77
77
78 def extsetup(ui):
78 def extsetup(ui):
79 schemes.update(dict(ui.configitems('schemes')))
79 schemes.update(dict(ui.configitems('schemes')))
80 t = templater.engine(lambda x: x)
80 t = templater.engine(lambda x: x)
81 for scheme, url in schemes.items():
81 for scheme, url in schemes.items():
82 hg.schemes[scheme] = ShortRepository(url, scheme, t)
82 hg.schemes[scheme] = ShortRepository(url, scheme, t)
@@ -1,22 +1,26 b''
1 #!/bin/sh
1 #!/bin/sh
2
2
3 cat <<EOF >> $HGRCPATH
3 cat <<EOF >> $HGRCPATH
4 [extensions]
4 [extensions]
5 schemes=
5 schemes=
6
6
7 [schemes]
7 [schemes]
8 l = http://localhost:$HGPORT/
8 l = http://localhost:$HGPORT/
9 parts = http://{1}:$HGPORT/
9 EOF
10 EOF
10
11
11 hg init test
12 hg init test
12 cd test
13 cd test
13 echo a > a
14 echo a > a
14 hg ci -Am initial
15 hg ci -Am initial
15
16
16 hg serve -n test -p $HGPORT -d --pid-file=hg.pid -A access.log -E errors.log
17 hg serve -n test -p $HGPORT -d --pid-file=hg.pid -A access.log -E errors.log
17 cat hg.pid >> $DAEMON_PIDS
18 cat hg.pid >> $DAEMON_PIDS
18
19
19 hg incoming l://
20 hg incoming l://
20
21
22 echo % check that {1} syntax works
23 hg incoming --debug parts://localhost | sed 's/[0-9]//g'
24
21 echo % errors
25 echo % errors
22 cat errors.log
26 cat errors.log
@@ -1,5 +1,12 b''
1 adding a
1 adding a
2 comparing with l://
2 comparing with l://
3 searching for changes
3 searching for changes
4 no changes found
4 no changes found
5 % check that {1} syntax works
6 using http://localhost:/
7 sending between command
8 comparing with parts://localhost
9 sending heads command
10 searching for changes
11 no changes found
5 % errors
12 % errors
General Comments 0
You need to be logged in to leave comments. Login now