changeset 4244:a80502f47552

hgwebdir: break templater -> templater circular reference This is essentially another instance of the same problem fixed by the parent changeset. See its commit message for the details.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Mon, 19 Mar 2007 19:07:37 -0300
parents 3f2e334937ce
children bd46b83b9692
files mercurial/hgweb/hgwebdir_mod.py
diffstat 1 files changed, 50 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/hgwebdir_mod.py	Mon Mar 19 19:07:35 2007 -0300
+++ b/mercurial/hgweb/hgwebdir_mod.py	Mon Mar 19 19:07:37 2007 -0300
@@ -172,53 +172,56 @@
                     parity = 1 - parity
                     yield row
 
-        virtual = req.env.get("PATH_INFO", "").strip('/')
-        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)
+        try:
+            virtual = req.env.get("PATH_INFO", "").strip('/')
+            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:
-                    break
-                up = virtual.rfind('/')
-                if up < 0:
-                    break
-                virtual = virtual[:up]
-            if real:
-                req.env['REPO_NAME'] = virtual
-                try:
-                    repo = hg.repository(parentui, real)
-                    hgweb(repo).run_wsgi(req)
-                except IOError, inst:
-                    req.write(tmpl("error", error=inst.strerror))
-                except hg.RepoError, inst:
-                    req.write(tmpl("error", error=str(inst)))
+                    req.env['REPO_NAME'] = virtual
+                    try:
+                        repo = hg.repository(parentui, real)
+                        hgweb(repo).run_wsgi(req)
+                    except IOError, inst:
+                        req.write(tmpl("error", error=inst.strerror))
+                    except hg.RepoError, inst:
+                        req.write(tmpl("error", error=str(inst)))
+                else:
+                    req.write(tmpl("notfound", repo=virtual))
             else:
-                req.write(tmpl("notfound", repo=virtual))
-        else:
-            if req.form.has_key('static'):
-                static = os.path.join(templater.templatepath(), "static")
-                fname = req.form['static'][0]
-                req.write(staticfile(static, fname, req)
-                          or tmpl("error", error="%r not found" % fname))
-            else:
-                sortable = ["name", "description", "contact", "lastchange"]
-                sortcolumn, descending = self.repos_sorted
-                if req.form.has_key('sort'):
-                    sortcolumn = req.form['sort'][0]
-                    descending = sortcolumn.startswith('-')
-                    if descending:
-                        sortcolumn = sortcolumn[1:]
-                    if sortcolumn not in sortable:
-                        sortcolumn = ""
+                if req.form.has_key('static'):
+                    static = os.path.join(templater.templatepath(), "static")
+                    fname = req.form['static'][0]
+                    req.write(staticfile(static, fname, req)
+                              or tmpl("error", error="%r not found" % fname))
+                else:
+                    sortable = ["name", "description", "contact", "lastchange"]
+                    sortcolumn, descending = self.repos_sorted
+                    if req.form.has_key('sort'):
+                        sortcolumn = req.form['sort'][0]
+                        descending = sortcolumn.startswith('-')
+                        if descending:
+                            sortcolumn = sortcolumn[1:]
+                        if sortcolumn not in sortable:
+                            sortcolumn = ""
 
-                sort = [("sort_%s" % column,
-                         "%s%s" % ((not descending and column == sortcolumn)
-                                   and "-" or "", column))
-                        for column in sortable]
-                req.write(tmpl("index", entries=entries,
-                               sortcolumn=sortcolumn, descending=descending,
-                               **dict(sort)))
+                    sort = [("sort_%s" % column,
+                             "%s%s" % ((not descending and column == sortcolumn)
+                                       and "-" or "", column))
+                            for column in sortable]
+                    req.write(tmpl("index", entries=entries,
+                                   sortcolumn=sortcolumn, descending=descending,
+                                   **dict(sort)))
+        finally:
+            tmpl = None