diff options
Diffstat (limited to 'mercurial/hgweb/hgwebdir_mod.py')
-rw-r--r-- | mercurial/hgweb/hgwebdir_mod.py | 115 |
1 files changed, 20 insertions, 95 deletions
diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py index 7cb083e..c5db7ff 100644 --- a/mercurial/hgweb/hgwebdir_mod.py +++ b/mercurial/hgweb/hgwebdir_mod.py @@ -23,10 +23,10 @@ def findrepos(paths): repos = [] for prefix, root in cleannames(paths): roothead, roottail = os.path.split(root) - # "foo = /bar/*" or "foo = /bar/**" lets every repo /bar/N in or below - # /bar/ be served as as foo/N . - # '*' will not search inside dirs with .hg (except .hg/patches), - # '**' will search inside dirs with .hg (and thus also find subrepos). + # "foo = /bar/*" makes every subrepo of /bar/ to be + # mounted as foo/subrepo + # and "foo = /bar/**" also recurses into the subdirectories, + # remember to use it without working dir. try: recurse = {'*': False, '**': True}[roottail] except KeyError: @@ -51,33 +51,6 @@ def urlrepos(prefix, roothead, paths): yield (prefix + '/' + util.pconvert(path[len(roothead):]).lstrip('/')).strip('/'), path -def geturlcgivars(baseurl, port): - """ - Extract CGI variables from baseurl - - >>> geturlcgivars("http://host.org/base", "80") - ('host.org', '80', '/base') - >>> geturlcgivars("http://host.org:8000/base", "80") - ('host.org', '8000', '/base') - >>> geturlcgivars('/base', 8000) - ('', '8000', '/base') - >>> geturlcgivars("base", '8000') - ('', '8000', '/base') - >>> geturlcgivars("http://host", '8000') - ('host', '8000', '/') - >>> geturlcgivars("http://host/", '8000') - ('host', '8000', '/') - """ - u = util.url(baseurl) - name = u.host or '' - if u.port: - port = u.port - path = u.path or "" - if not path.startswith('/'): - path = '/' + path - - return name, str(port), path - class hgwebdir(object): refreshinterval = 20 @@ -97,7 +70,7 @@ class hgwebdir(object): else: u = ui.ui() u.setconfig('ui', 'report_untrusted', 'off') - u.setconfig('ui', 'nontty', 'true') + u.setconfig('ui', 'interactive', 'off') if not isinstance(self.conf, (dict, list, tuple)): map = {'paths': 'hgweb-paths'} @@ -245,67 +218,12 @@ class hgwebdir(object): def rawentries(subdir="", **map): descend = self.ui.configbool('web', 'descend', True) - collapse = self.ui.configbool('web', 'collapse', False) - seenrepos = set() - seendirs = set() for name, path in self.repos: if not name.startswith(subdir): continue name = name[len(subdir):] - directory = False - - if '/' in name: - if not descend: - continue - - nameparts = name.split('/') - rootname = nameparts[0] - - if not collapse: - pass - elif rootname in seendirs: - continue - elif rootname in seenrepos: - pass - else: - directory = True - name = rootname - - # redefine the path to refer to the directory - discarded = '/'.join(nameparts[1:]) - - # remove name parts plus accompanying slash - path = path[:-len(discarded) - 1] - - parts = [name] - if 'PATH_INFO' in req.env: - parts.insert(0, req.env['PATH_INFO'].rstrip('/')) - if req.env['SCRIPT_NAME']: - parts.insert(0, req.env['SCRIPT_NAME']) - url = re.sub(r'/+', '/', '/'.join(parts) + '/') - - # show either a directory entry or a repository - if directory: - # get the directory's time information - try: - d = (get_mtime(path), util.makedate()[1]) - except OSError: - continue - - row = dict(contact="", - contact_sort="", - name=name, - name_sort=name, - url=url, - description="", - description_sort="", - lastchange=d, - lastchange_sort=d[1]-d[0], - archives=[]) - - seendirs.add(name) - yield row + if not descend and '/' in name: continue u = self.ui.copy() @@ -323,6 +241,13 @@ class hgwebdir(object): if not self.read_allowed(u, req): continue + parts = [name] + if 'PATH_INFO' in req.env: + parts.insert(0, req.env['PATH_INFO'].rstrip('/')) + if req.env['SCRIPT_NAME']: + parts.insert(0, req.env['SCRIPT_NAME']) + url = re.sub(r'/+', '/', '/'.join(parts) + '/') + # update time with local timezone try: r = hg.repository(self.ui, path) @@ -350,8 +275,6 @@ class hgwebdir(object): lastchange=d, lastchange_sort=d[1]-d[0], archives=archivelist(u, "tip", url)) - - seenrepos.add(name) yield row sortdefault = None, False @@ -425,7 +348,6 @@ class hgwebdir(object): start = url[-1] == '?' and '&' or '?' sessionvars = webutil.sessionvars(vars, start) logourl = config('web', 'logourl', 'http://mercurial.selenic.com/') - logoimg = config('web', 'logoimg', 'hglogo.png') staticurl = config('web', 'staticurl') or url + 'static/' if not staticurl.endswith('/'): staticurl += '/' @@ -436,14 +358,17 @@ class hgwebdir(object): "motd": motd, "url": url, "logourl": logourl, - "logoimg": logoimg, "staticurl": staticurl, "sessionvars": sessionvars}) return tmpl def updatereqenv(self, env): if self._baseurl is not None: - name, port, path = geturlcgivars(self._baseurl, env['SERVER_PORT']) - env['SERVER_NAME'] = name - env['SERVER_PORT'] = port + u = util.url(self._baseurl) + env['SERVER_NAME'] = u.host + if u.port: + env['SERVER_PORT'] = u.port + path = u.path or "" + if not path.startswith('/'): + path = '/' + path env['SCRIPT_NAME'] = path |