Show More
@@ -0,0 +1,40 b'' | |||||
|
1 | import os | |||
|
2 | from mercurial import hg, ui | |||
|
3 | from mercurial.hgweb.hgwebdir_mod import hgwebdir | |||
|
4 | ||||
|
5 | os.mkdir('webdir') | |||
|
6 | os.chdir('webdir') | |||
|
7 | ||||
|
8 | webdir = os.path.realpath('.') | |||
|
9 | ||||
|
10 | u = ui.ui() | |||
|
11 | hg.repository(u, 'a', create=1) | |||
|
12 | hg.repository(u, 'b', create=1) | |||
|
13 | os.chdir('b') | |||
|
14 | hg.repository(u, 'd', create=1) | |||
|
15 | os.chdir('..') | |||
|
16 | hg.repository(u, 'c', create=1) | |||
|
17 | os.chdir('..') | |||
|
18 | ||||
|
19 | paths = {'t/a/': '%s/a' % webdir, | |||
|
20 | 'b': '%s/b' % webdir, | |||
|
21 | 'coll': '%s/*' % webdir, | |||
|
22 | 'rcoll': '%s/**' % webdir} | |||
|
23 | ||||
|
24 | config = os.path.join(webdir, 'hgwebdir.conf') | |||
|
25 | configfile = open(config, 'w') | |||
|
26 | configfile.write('[paths]\n') | |||
|
27 | for k, v in paths.items(): | |||
|
28 | configfile.write('%s = %s\n' % (k, v)) | |||
|
29 | configfile.close() | |||
|
30 | ||||
|
31 | confwd = hgwebdir(config) | |||
|
32 | dictwd = hgwebdir(paths) | |||
|
33 | ||||
|
34 | assert len(confwd.repos) == len(dictwd.repos), 'different numbers' | |||
|
35 | assert len(confwd.repos) == 9, 'expected 9 repos, found %d' % len(confwd.repos) | |||
|
36 | ||||
|
37 | found = dict(confwd.repos) | |||
|
38 | for key, path in dictwd.repos: | |||
|
39 | assert key in found, 'repository %s was not found' % key | |||
|
40 | assert found[key] == path, 'different paths for repo %s' % key |
@@ -19,6 +19,28 b' import webutil' | |||||
19 | def cleannames(items): |
|
19 | def cleannames(items): | |
20 | return [(util.pconvert(name).strip('/'), path) for name, path in items] |
|
20 | return [(util.pconvert(name).strip('/'), path) for name, path in items] | |
21 |
|
21 | |||
|
22 | def findrepos(paths): | |||
|
23 | repos = {} | |||
|
24 | for prefix, root in cleannames(paths): | |||
|
25 | roothead, roottail = os.path.split(root) | |||
|
26 | # "foo = /bar/*" makes every subrepo of /bar/ to be | |||
|
27 | # mounted as foo/subrepo | |||
|
28 | # and "foo = /bar/**" also recurses into the subdirectories, | |||
|
29 | # remember to use it without working dir. | |||
|
30 | try: | |||
|
31 | recurse = {'*': False, '**': True}[roottail] | |||
|
32 | except KeyError: | |||
|
33 | repos[prefix] = root | |||
|
34 | continue | |||
|
35 | roothead = os.path.normpath(roothead) | |||
|
36 | for path in util.walkrepos(roothead, followsym=True, recurse=recurse): | |||
|
37 | path = os.path.normpath(path) | |||
|
38 | name = util.pconvert(path[len(roothead):]).strip('/') | |||
|
39 | if prefix: | |||
|
40 | name = prefix + '/' + name | |||
|
41 | repos[name] = path | |||
|
42 | return repos.items() | |||
|
43 | ||||
22 | class hgwebdir(object): |
|
44 | class hgwebdir(object): | |
23 | refreshinterval = 20 |
|
45 | refreshinterval = 20 | |
24 |
|
46 | |||
@@ -39,14 +61,6 b' class hgwebdir(object):' | |||||
39 | self.ui.setconfig('ui', 'report_untrusted', 'off') |
|
61 | self.ui.setconfig('ui', 'report_untrusted', 'off') | |
40 | self.ui.setconfig('ui', 'interactive', 'off') |
|
62 | self.ui.setconfig('ui', 'interactive', 'off') | |
41 |
|
63 | |||
42 | if isinstance(self.conf, (list, tuple)): |
|
|||
43 | self.repos = cleannames(conf) |
|
|||
44 | elif isinstance(self.conf, dict): |
|
|||
45 | self.repos = sorted(cleannames(self.conf.items())) |
|
|||
46 | else: |
|
|||
47 | self.ui.readconfig(self.conf, remap={'paths': 'hgweb-paths'}, trust=True) |
|
|||
48 | self.repos = [] |
|
|||
49 |
|
||||
50 | self.motd = self.ui.config('web', 'motd') |
|
64 | self.motd = self.ui.config('web', 'motd') | |
51 | self.style = self.ui.config('web', 'style', 'paper') |
|
65 | self.style = self.ui.config('web', 'style', 'paper') | |
52 | self.stripecount = self.ui.config('web', 'stripes', 1) |
|
66 | self.stripecount = self.ui.config('web', 'stripes', 1) | |
@@ -54,29 +68,16 b' class hgwebdir(object):' | |||||
54 | self.stripecount = int(self.stripecount) |
|
68 | self.stripecount = int(self.stripecount) | |
55 | self._baseurl = self.ui.config('web', 'baseurl') |
|
69 | self._baseurl = self.ui.config('web', 'baseurl') | |
56 |
|
70 | |||
57 | if self.repos: |
|
71 | if not isinstance(self.conf, (dict, list, tuple)): | |
58 | return |
|
72 | map = {'paths': 'hgweb-paths'} | |
|
73 | self.ui.readconfig(self.conf, remap=map, trust=True) | |||
|
74 | paths = self.ui.configitems('hgweb-paths') | |||
|
75 | elif isinstance(self.conf, (list, tuple)): | |||
|
76 | paths = self.conf | |||
|
77 | elif isinstance(self.conf, dict): | |||
|
78 | paths = self.conf.items() | |||
59 |
|
79 | |||
60 | for prefix, root in cleannames(self.ui.configitems('hgweb-paths')): |
|
80 | self.repos = findrepos(paths) | |
61 | roothead, roottail = os.path.split(root) |
|
|||
62 | # "foo = /bar/*" makes every subrepo of /bar/ to be |
|
|||
63 | # mounted as foo/subrepo |
|
|||
64 | # and "foo = /bar/**" also recurses into the subdirectories, |
|
|||
65 | # remember to use it without working dir. |
|
|||
66 | try: |
|
|||
67 | recurse = {'*': False, '**': True}[roottail] |
|
|||
68 | except KeyError: |
|
|||
69 | self.repos.append((prefix, root)) |
|
|||
70 | continue |
|
|||
71 | roothead = os.path.normpath(roothead) |
|
|||
72 | for path in util.walkrepos(roothead, followsym=True, |
|
|||
73 | recurse=recurse): |
|
|||
74 | path = os.path.normpath(path) |
|
|||
75 | name = util.pconvert(path[len(roothead):]).strip('/') |
|
|||
76 | if prefix: |
|
|||
77 | name = prefix + '/' + name |
|
|||
78 | self.repos.append((name, path)) |
|
|||
79 |
|
||||
80 | for prefix, root in self.ui.configitems('collections'): |
|
81 | for prefix, root in self.ui.configitems('collections'): | |
81 | for path in util.walkrepos(root, followsym=True): |
|
82 | for path in util.walkrepos(root, followsym=True): | |
82 | repo = os.path.normpath(path) |
|
83 | repo = os.path.normpath(path) |
General Comments 0
You need to be logged in to leave comments.
Login now