comparison mercurial/hgweb/webcommands.py @ 16448:e6b45e9a75dc

hgweb: add hook for remapping repository path into virtual paths Extensions such as largefiles can use this to remap files so they appear in the same location as they do in the user's working copy.
author Martin Geisler <mg@lazybytes.net>
date Sun, 15 Apr 2012 16:05:53 +0200
parents 2695aaf4eb72
children dd68c972d089
comparison
equal deleted inserted replaced
16447:60c379da12aa 16448:e6b45e9a75dc
301 inbranch=webutil.nodeinbranch(web.repo, ctx), 301 inbranch=webutil.nodeinbranch(web.repo, ctx),
302 branches=webutil.nodebranchdict(web.repo, ctx)) 302 branches=webutil.nodebranchdict(web.repo, ctx))
303 303
304 rev = changeset 304 rev = changeset
305 305
306 def decodepath(path):
307 """Hook for mapping a path in the repository to a path in the
308 working copy.
309
310 Extensions (e.g., largefiles) can override this to remap files in
311 the virtual file system presented by the manifest command below."""
312 return path
313
306 def manifest(web, req, tmpl): 314 def manifest(web, req, tmpl):
307 ctx = webutil.changectx(web.repo, req) 315 ctx = webutil.changectx(web.repo, req)
308 path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) 316 path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0])
309 mf = ctx.manifest() 317 mf = ctx.manifest()
310 node = ctx.node() 318 node = ctx.node()
316 if path and path[-1] != "/": 324 if path and path[-1] != "/":
317 path += "/" 325 path += "/"
318 l = len(path) 326 l = len(path)
319 abspath = "/" + path 327 abspath = "/" + path
320 328
321 for f, n in mf.iteritems(): 329 for full, n in mf.iteritems():
330 # the virtual path (working copy path) used for the full
331 # (repository) path
332 f = decodepath(full)
333
322 if f[:l] != path: 334 if f[:l] != path:
323 continue 335 continue
324 remain = f[l:] 336 remain = f[l:]
325 elements = remain.split('/') 337 elements = remain.split('/')
326 if len(elements) == 1: 338 if len(elements) == 1:
327 files[remain] = f 339 files[remain] = full
328 else: 340 else:
329 h = dirs # need to retain ref to dirs (root) 341 h = dirs # need to retain ref to dirs (root)
330 for elem in elements[0:-1]: 342 for elem in elements[0:-1]:
331 if elem not in h: 343 if elem not in h:
332 h[elem] = {} 344 h[elem] = {}