comparison mercurial/hgweb/hgwebdir_mod.py @ 31482:da7d19324b1e

hgwebdir: add support for explicit index files This is useful for when repositories are nested in --web-conf, and in the future with hosted subrepositories. The previous behavior was only to render an index at each virtual directory. There is now an explicit 'index' child for each virtual directory. The name was suggested by Yuya, for consistency with the other method names. Additionally, there is now an explicit 'index' child for every repository directory with a nested repository somewhere below it. This seems more consistent with each virtual directory hosting an index, and more discoverable than to only have an index for a directory that directly hosts a nested repository. I couldn't figure out how to close the loop and provide one in each directory without a deeper nested repository, without blocking a committed 'index' file. Keeping that seems better than rendering an empty index.
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 05 Mar 2017 22:22:32 -0500
parents d7bf7d2bd5ab
children bd3cb917761a
comparison
equal deleted inserted replaced
31481:a7c687c35119 31482:da7d19324b1e
252 static = [os.path.join(p, 'static') for p in tp] 252 static = [os.path.join(p, 'static') for p in tp]
253 staticfile(static, fname, req) 253 staticfile(static, fname, req)
254 return [] 254 return []
255 255
256 # top-level index 256 # top-level index
257 elif not virtual: 257
258 repos = dict(self.repos)
259
260 if not virtual or (virtual == 'index' and virtual not in repos):
258 req.respond(HTTP_OK, ctype) 261 req.respond(HTTP_OK, ctype)
259 return self.makeindex(req, tmpl) 262 return self.makeindex(req, tmpl)
260 263
261 # nested indexes and hgwebs 264 # nested indexes and hgwebs
262 265
263 repos = dict(self.repos) 266 if virtual.endswith('/index') and virtual not in repos:
267 subdir = virtual[:-len('index')]
268 if any(r.startswith(subdir) for r in repos):
269 req.respond(HTTP_OK, ctype)
270 return self.makeindex(req, tmpl, subdir)
271
264 virtualrepo = virtual 272 virtualrepo = virtual
265 while virtualrepo: 273 while virtualrepo:
266 real = repos.get(virtualrepo) 274 real = repos.get(virtualrepo)
267 if real: 275 if real:
268 req.env['REPO_NAME'] = virtualrepo 276 req.env['REPO_NAME'] = virtualrepo
350 directory = False 358 directory = False
351 except (IOError, error.RepoError): 359 except (IOError, error.RepoError):
352 pass 360 pass
353 361
354 parts = [name] 362 parts = [name]
355 if 'PATH_INFO' in req.env: 363 parts.insert(0, '/' + subdir.rstrip('/'))
356 parts.insert(0, req.env['PATH_INFO'].rstrip('/'))
357 if req.env['SCRIPT_NAME']: 364 if req.env['SCRIPT_NAME']:
358 parts.insert(0, req.env['SCRIPT_NAME']) 365 parts.insert(0, req.env['SCRIPT_NAME'])
359 url = re.sub(r'/+', '/', '/'.join(parts) + '/') 366 url = re.sub(r'/+', '/', '/'.join(parts) + '/')
360 367
361 # show either a directory entry or a repository 368 # show either a directory entry or a repository