diff mercurial/hgweb/hgwebdir_mod.py @ 3281:45b639607e52

Merge with crew
author Matt Mackall <mpm@selenic.com>
date Fri, 06 Oct 2006 17:14:18 -0500
parents db9d2a624521
children 415905fad4fe
line wrap: on
line diff
--- a/mercurial/hgweb/hgwebdir_mod.py
+++ b/mercurial/hgweb/hgwebdir_mod.py
@@ -11,7 +11,7 @@ from mercurial.demandload import demandl
 demandload(globals(), "ConfigParser mimetools cStringIO")
 demandload(globals(), "mercurial:ui,hg,util,templater")
 demandload(globals(), "mercurial.hgweb.hgweb_mod:hgweb")
-demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile")
+demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile,style_map")
 from mercurial.i18n import gettext as _
 
 # This is a stopgap
@@ -69,25 +69,20 @@ class hgwebdir(object):
         def footer(**map):
             yield tmpl("footer", motd=self.motd, **map)
 
-        m = os.path.join(templater.templatepath(), "map")
         style = self.style
         if req.form.has_key('style'):
             style = req.form['style'][0]
-        if style != "":
-            b = os.path.basename("map-" + style)
-            p = os.path.join(templater.templatepath(), b)
-            if os.path.isfile(p):
-                m = p
-
-        tmpl = templater.templater(m, templater.common_filters,
+        mapfile = style_map(templater.templatepath(), style)
+        tmpl = templater.templater(mapfile, templater.common_filters,
                                    defaults={"header": header,
                                              "footer": footer})
 
         def archivelist(ui, nodeid, url):
             allowed = ui.configlist("web", "allow_archive")
-            for i in ['zip', 'gz', 'bz2']:
-                if i in allowed or ui.configbool("web", "allow" + i):
-                    yield {"type" : i, "node": nodeid, "url": url}
+            for i in [('zip', '.zip'), ('gz', '.tar.gz'), ('bz2', '.tar.bz2')]:
+                if i[0] in allowed or ui.configbool("web", "allow" + i[0]):
+                    yield {"type" : i[0], "extension": i[1],
+                           "node": nodeid, "url": url}
 
         def entries(sortcolumn="", descending=False, **map):
             rows = []
@@ -101,7 +96,7 @@ class hgwebdir(object):
                 get = u.config
 
                 url = ('/'.join([req.env["REQUEST_URI"].split('?')[0], name])
-                       .replace("//", "/"))
+                       .replace("//", "/")) + '/'
 
                 # update time with local timezone
                 try:
@@ -142,9 +137,22 @@ class hgwebdir(object):
                     yield row
 
         virtual = req.env.get("PATH_INFO", "").strip('/')
-        if virtual:
-            real = dict(self.repos).get(virtual)
+        if virtual.startswith('static/'):
+            static = os.path.join(templater.templatepath(), 'static')
+            fname = virtual[7:]
+            req.write(staticfile(static, fname, req) or
+                      tmpl('error', error='%r not found' % fname))
+        elif virtual:
+            while virtual:
+                real = dict(self.repos).get(virtual)
+                if real:
+                    break
+                up = virtual.rfind('/')
+                if up < 0:
+                    break
+                virtual = virtual[:up]
             if real:
+                req.env['REPO_NAME'] = virtual
                 try:
                     hgweb(real).run_wsgi(req)
                 except IOError, inst: