mercurial/hgweb/hgweb_mod.py
changeset 5588 083b6e3142a2
parent 5572 9c7f543405c1
parent 5579 e15f7db0f0ee
child 5620 652f57de3ccf
equal deleted inserted replaced
5587:121f9dbcc236 5588:083b6e3142a2
   724                     del form[k]
   724                     del form[k]
   725 
   725 
   726         def rewrite_request(req):
   726         def rewrite_request(req):
   727             '''translate new web interface to traditional format'''
   727             '''translate new web interface to traditional format'''
   728 
   728 
   729             def spliturl(req):
   729             req.url = req.env['SCRIPT_NAME']
   730                 def firstitem(query):
   730             if not req.url.endswith('/'):
   731                     return query.split('&', 1)[0].split(';', 1)[0]
   731                 req.url += '/'
   732 
   732             if req.env.has_key('REPO_NAME'):
   733                 def normurl(url):
   733                 req.url += req.env['REPO_NAME'] + '/'
   734                     inner = '/'.join([x for x in url.split('/') if x])
   734             
   735                     tl = len(url) > 1 and url.endswith('/') and '/' or ''
   735             if req.env.get('PATH_INFO'):
   736 
   736                 parts = req.env.get('PATH_INFO').strip('/').split('/')
   737                     return '%s%s%s' % (url.startswith('/') and '/' or '',
   737                 repo_parts = req.env.get('REPO_NAME', '').split('/')
   738                                        inner, tl)
   738                 if parts[:len(repo_parts)] == repo_parts:
   739 
   739                     parts = parts[len(repo_parts):]
   740                 root = normurl(urllib.unquote(req.env.get('REQUEST_URI', '').split('?', 1)[0]))
   740                 query = '/'.join(parts)
   741                 pi = normurl(req.env.get('PATH_INFO', ''))
   741             else:
   742                 if pi:
   742                 query = req.env['QUERY_STRING'].split('&', 1)[0]
   743                     # strip leading /
   743                 query = query.split(';', 1)[0]
   744                     pi = pi[1:]
       
   745                     if pi:
       
   746                         root = root[:root.rfind(pi)]
       
   747                     if req.env.has_key('REPO_NAME'):
       
   748                         rn = req.env['REPO_NAME'] + '/'
       
   749                         root += rn
       
   750                         query = pi[len(rn):]
       
   751                     else:
       
   752                         query = pi
       
   753                 else:
       
   754                     root += '?'
       
   755                     query = firstitem(req.env['QUERY_STRING'])
       
   756 
       
   757                 return (root, query)
       
   758 
       
   759             req.url, query = spliturl(req)
       
   760 
   744 
   761             if req.form.has_key('cmd'):
   745             if req.form.has_key('cmd'):
   762                 # old style
   746                 # old style
   763                 return
   747                 return
   764 
   748