##// END OF EJS Templates
hgwebdir: refactor inner loop
Dirkjan Ochtman -
r5603:74f65f44 default
parent child Browse files
Show More
@@ -73,49 +73,58 b' class hgwebdir(object):'
73
73
74 try:
74 try:
75 try:
75 try:
76
76 virtual = req.env.get("PATH_INFO", "").strip('/')
77 virtual = req.env.get("PATH_INFO", "").strip('/')
77 if virtual.startswith('static/'):
78
79 # a static file
80 if virtual.startswith('static/') or 'static' in req.form:
78 static = os.path.join(templater.templatepath(), 'static')
81 static = os.path.join(templater.templatepath(), 'static')
79 fname = virtual[7:]
82 if virtual.startswith('static/'):
83 fname = virtual[7:]
84 else:
85 fname = req.form['static'][0]
80 req.write(staticfile(static, fname, req))
86 req.write(staticfile(static, fname, req))
81 elif virtual:
87 return
82 repos = dict(self.repos)
88
83 while virtual:
89 # top-level index
84 real = repos.get(virtual)
90 elif not virtual:
85 if real:
91 tmpl = self.templater(req)
86 req.env['REPO_NAME'] = virtual
92 self.makeindex(req, tmpl)
87 try:
93 return
88 repo = hg.repository(self.parentui, real)
89 hgweb(repo).run_wsgi(req)
90 return
91 except IOError, inst:
92 raise ErrorResponse(500, inst.strerror)
93 except hg.RepoError, inst:
94 raise ErrorResponse(500, str(inst))
95
94
96 # browse subdirectories
95 # nested indexes and hgwebs
97 subdir = virtual + '/'
96 repos = dict(self.repos)
98 if [r for r in repos if r.startswith(subdir)]:
97 while virtual:
99 tmpl = self.templater(req)
98 real = repos.get(virtual)
100 self.makeindex(req, tmpl, subdir)
99 if real:
100 req.env['REPO_NAME'] = virtual
101 try:
102 repo = hg.repository(self.parentui, real)
103 hgweb(repo).run_wsgi(req)
101 return
104 return
102
105 except IOError, inst:
103 up = virtual.rfind('/')
106 raise ErrorResponse(500, inst.strerror)
104 if up < 0:
107 except hg.RepoError, inst:
105 break
108 raise ErrorResponse(500, str(inst))
106 virtual = virtual[:up]
107
109
108 tmpl = self.templater(req)
110 # browse subdirectories
109 req.respond(404, tmpl("notfound", repo=virtual))
111 subdir = virtual + '/'
110 else:
112 if [r for r in repos if r.startswith(subdir)]:
111 if req.form.has_key('static'):
112 static = os.path.join(templater.templatepath(), "static")
113 fname = req.form['static'][0]
114 req.write(staticfile(static, fname, req))
115 else:
116 tmpl = self.templater(req)
113 tmpl = self.templater(req)
117 self.makeindex(req, tmpl)
114 self.makeindex(req, tmpl, subdir)
115 return
116
117 up = virtual.rfind('/')
118 if up < 0:
119 break
120 virtual = virtual[:up]
121
122 # prefixes not found
123 tmpl = self.templater(req)
124 req.respond(404, tmpl("notfound", repo=virtual))
125
118 except ErrorResponse, err:
126 except ErrorResponse, err:
127 tmpl = self.templater(req)
119 req.respond(err.code, tmpl('error', error=err.message or ''))
128 req.respond(err.code, tmpl('error', error=err.message or ''))
120 finally:
129 finally:
121 tmpl = None
130 tmpl = None
General Comments 0
You need to be logged in to leave comments. Login now