comparison mercurial/hgweb/hgwebdir_mod.py @ 8529:a767998f0a78

hgweb: make hgwebdir handle dict/list paths the same as config paths Before this patch, the only way to get hgwebdir to honor the recursive paths was to create a config object or a config file with the recursive paths in it. This patch makes hgwebdir treat paths the same whether passed in as a list, tuple, config or however hgwebdir supports passing paths.
author Jeremy Whitlock <jcscoobyrs@gmail.com>
date Wed, 20 May 2009 16:04:37 +0200
parents 4b798b100c32
children b48a1e081f23
comparison
equal deleted inserted replaced
8528:4ddffb793d18 8529:a767998f0a78
17 import webutil 17 import webutil
18 18
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
25 def __init__(self, conf, baseui=None): 47 def __init__(self, conf, baseui=None):
26 self.conf = conf 48 self.conf = conf
37 else: 59 else:
38 self.ui = ui.ui() 60 self.ui = ui.ui()
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)
53 if self.stripecount: 67 if self.stripecount:
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'}
59 73 self.ui.readconfig(self.conf, remap=map, trust=True)
60 for prefix, root in cleannames(self.ui.configitems('hgweb-paths')): 74 paths = self.ui.configitems('hgweb-paths')
61 roothead, roottail = os.path.split(root) 75 elif isinstance(self.conf, (list, tuple)):
62 # "foo = /bar/*" makes every subrepo of /bar/ to be 76 paths = self.conf
63 # mounted as foo/subrepo 77 elif isinstance(self.conf, dict):
64 # and "foo = /bar/**" also recurses into the subdirectories, 78 paths = self.conf.items()
65 # remember to use it without working dir. 79
66 try: 80 self.repos = findrepos(paths)
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)
83 name = repo 84 name = repo
84 if name.startswith(prefix): 85 if name.startswith(prefix):