mercurial/hgweb/hgwebdir_mod.py
changeset 36904 092ab4ba7ee5
parent 36903 803e0fc0cc9a
child 36905 93717f082af9
equal deleted inserted replaced
36903:803e0fc0cc9a 36904:092ab4ba7ee5
   117                 'url': url,
   117                 'url': url,
   118             })
   118             })
   119 
   119 
   120     return archives
   120     return archives
   121 
   121 
   122 def rawindexentries(ui, repos, wsgireq, req, subdir=''):
   122 def rawindexentries(ui, repos, req, subdir=''):
   123     descend = ui.configbool('web', 'descend')
   123     descend = ui.configbool('web', 'descend')
   124     collapse = ui.configbool('web', 'collapse')
   124     collapse = ui.configbool('web', 'collapse')
   125     seenrepos = set()
   125     seenrepos = set()
   126     seendirs = set()
   126     seendirs = set()
   127     for name, path in repos:
   127     for name, path in repos:
   159                     directory = False
   159                     directory = False
   160                 except (IOError, error.RepoError):
   160                 except (IOError, error.RepoError):
   161                     pass
   161                     pass
   162 
   162 
   163         parts = [
   163         parts = [
   164             wsgireq.req.apppath.strip('/'),
   164             req.apppath.strip('/'),
   165             subdir.strip('/'),
   165             subdir.strip('/'),
   166             name.strip('/'),
   166             name.strip('/'),
   167         ]
   167         ]
   168         url = '/' + '/'.join(p for p in parts if p) + '/'
   168         url = '/' + '/'.join(p for p in parts if p) + '/'
   169 
   169 
   243                'labels': u.configlist('web', 'labels', untrusted=True),
   243                'labels': u.configlist('web', 'labels', untrusted=True),
   244                }
   244                }
   245 
   245 
   246         yield row
   246         yield row
   247 
   247 
   248 def indexentries(ui, repos, wsgireq, req, stripecount, sortcolumn='',
   248 def indexentries(ui, repos, req, stripecount, sortcolumn='',
   249                  descending=False, subdir=''):
   249                  descending=False, subdir=''):
   250 
   250 
   251     rows = rawindexentries(ui, repos, wsgireq, req, subdir=subdir)
   251     rows = rawindexentries(ui, repos, req, subdir=subdir)
   252 
   252 
   253     sortdefault = None, False
   253     sortdefault = None, False
   254 
   254 
   255     if sortcolumn and sortdefault != (sortcolumn, descending):
   255     if sortcolumn and sortdefault != (sortcolumn, descending):
   256         sortkey = '%s_sort' % sortcolumn
   256         sortkey = '%s_sort' % sortcolumn
   399 
   399 
   400             repos = dict(self.repos)
   400             repos = dict(self.repos)
   401 
   401 
   402             if (not virtual or virtual == 'index') and virtual not in repos:
   402             if (not virtual or virtual == 'index') and virtual not in repos:
   403                 wsgireq.respond(HTTP_OK, ctype)
   403                 wsgireq.respond(HTTP_OK, ctype)
   404                 return self.makeindex(wsgireq, tmpl)
   404                 return self.makeindex(req, tmpl)
   405 
   405 
   406             # nested indexes and hgwebs
   406             # nested indexes and hgwebs
   407 
   407 
   408             if virtual.endswith('/index') and virtual not in repos:
   408             if virtual.endswith('/index') and virtual not in repos:
   409                 subdir = virtual[:-len('index')]
   409                 subdir = virtual[:-len('index')]
   410                 if any(r.startswith(subdir) for r in repos):
   410                 if any(r.startswith(subdir) for r in repos):
   411                     wsgireq.respond(HTTP_OK, ctype)
   411                     wsgireq.respond(HTTP_OK, ctype)
   412                     return self.makeindex(wsgireq, tmpl, subdir)
   412                     return self.makeindex(req, tmpl, subdir)
   413 
   413 
   414             def _virtualdirs():
   414             def _virtualdirs():
   415                 # Check the full virtual path, each parent, and the root ('')
   415                 # Check the full virtual path, each parent, and the root ('')
   416                 if virtual != '':
   416                 if virtual != '':
   417                     yield virtual
   417                     yield virtual
   441 
   441 
   442             # browse subdirectories
   442             # browse subdirectories
   443             subdir = virtual + '/'
   443             subdir = virtual + '/'
   444             if [r for r in repos if r.startswith(subdir)]:
   444             if [r for r in repos if r.startswith(subdir)]:
   445                 wsgireq.respond(HTTP_OK, ctype)
   445                 wsgireq.respond(HTTP_OK, ctype)
   446                 return self.makeindex(wsgireq, tmpl, subdir)
   446                 return self.makeindex(req, tmpl, subdir)
   447 
   447 
   448             # prefixes not found
   448             # prefixes not found
   449             wsgireq.respond(HTTP_NOT_FOUND, ctype)
   449             wsgireq.respond(HTTP_NOT_FOUND, ctype)
   450             return tmpl("notfound", repo=virtual)
   450             return tmpl("notfound", repo=virtual)
   451 
   451 
   453             wsgireq.respond(err, ctype)
   453             wsgireq.respond(err, ctype)
   454             return tmpl('error', error=err.message or '')
   454             return tmpl('error', error=err.message or '')
   455         finally:
   455         finally:
   456             tmpl = None
   456             tmpl = None
   457 
   457 
   458     def makeindex(self, wsgireq, tmpl, subdir=""):
   458     def makeindex(self, req, tmpl, subdir=""):
   459         req = wsgireq.req
       
   460 
       
   461         self.refresh()
   459         self.refresh()
   462         sortable = ["name", "description", "contact", "lastchange"]
   460         sortable = ["name", "description", "contact", "lastchange"]
   463         sortcolumn, descending = None, False
   461         sortcolumn, descending = None, False
   464         if 'sort' in req.qsparams:
   462         if 'sort' in req.qsparams:
   465             sortcolumn = req.qsparams['sort']
   463             sortcolumn = req.qsparams['sort']
   474                             and "-" or "", column))
   472                             and "-" or "", column))
   475                 for column in sortable]
   473                 for column in sortable]
   476 
   474 
   477         self.refresh()
   475         self.refresh()
   478 
   476 
   479         entries = indexentries(self.ui, self.repos, wsgireq, req,
   477         entries = indexentries(self.ui, self.repos, req,
   480                                self.stripecount, sortcolumn=sortcolumn,
   478                                self.stripecount, sortcolumn=sortcolumn,
   481                                descending=descending, subdir=subdir)
   479                                descending=descending, subdir=subdir)
   482 
   480 
   483         return tmpl("index", entries=entries, subdir=subdir,
   481         return tmpl("index", entries=entries, subdir=subdir,
   484                     pathdef=hgweb_mod.makebreadcrumb('/' + subdir, self.prefix),
   482                     pathdef=hgweb_mod.makebreadcrumb('/' + subdir, self.prefix),