##// END OF EJS Templates
hgweb: all protocol functions have become generators...
Dirkjan Ochtman -
r6784:18c429ea default
parent child Browse files
Show More
@@ -76,8 +76,7 b' class hgweb(object):'
76
76
77 def __call__(self, env, respond):
77 def __call__(self, env, respond):
78 req = wsgirequest(env, respond)
78 req = wsgirequest(env, respond)
79 self.run_wsgi(req)
79 return self.run_wsgi(req)
80 return req
81
80
82 def run_wsgi(self, req):
81 def run_wsgi(self, req):
83
82
@@ -90,10 +89,9 b' class hgweb(object):'
90 cmd = req.form.get('cmd', [''])[0]
89 cmd = req.form.get('cmd', [''])[0]
91 if cmd and cmd in protocol.__all__:
90 if cmd and cmd in protocol.__all__:
92 if cmd in perms and not self.check_perm(req, perms[cmd]):
91 if cmd in perms and not self.check_perm(req, perms[cmd]):
93 return
92 return []
94 method = getattr(protocol, cmd)
93 method = getattr(protocol, cmd)
95 method(self.repo, req)
94 return method(self.repo, req)
96 return
97
95
98 # work with CGI variables to create coherent structure
96 # work with CGI variables to create coherent structure
99 # use SCRIPT_NAME, PATH_INFO and QUERY_STRING as well as our REPO_NAME
97 # use SCRIPT_NAME, PATH_INFO and QUERY_STRING as well as our REPO_NAME
@@ -171,6 +169,7 b' class hgweb(object):'
171
169
172 req.write(content)
170 req.write(content)
173 del tmpl
171 del tmpl
172 return req
174
173
175 except revlog.LookupError, err:
174 except revlog.LookupError, err:
176 req.respond(HTTP_NOT_FOUND, ctype)
175 req.respond(HTTP_NOT_FOUND, ctype)
@@ -30,12 +30,12 b' def lookup(repo, req):'
30 success = 0
30 success = 0
31 resp = "%s %s\n" % (success, r)
31 resp = "%s %s\n" % (success, r)
32 req.respond(HTTP_OK, HGTYPE, length=len(resp))
32 req.respond(HTTP_OK, HGTYPE, length=len(resp))
33 req.write(resp)
33 yield resp
34
34
35 def heads(repo, req):
35 def heads(repo, req):
36 resp = " ".join(map(hex, repo.heads())) + "\n"
36 resp = " ".join(map(hex, repo.heads())) + "\n"
37 req.respond(HTTP_OK, HGTYPE, length=len(resp))
37 req.respond(HTTP_OK, HGTYPE, length=len(resp))
38 req.write(resp)
38 yield resp
39
39
40 def branches(repo, req):
40 def branches(repo, req):
41 nodes = []
41 nodes = []
@@ -46,7 +46,7 b' def branches(repo, req):'
46 resp.write(" ".join(map(hex, b)) + "\n")
46 resp.write(" ".join(map(hex, b)) + "\n")
47 resp = resp.getvalue()
47 resp = resp.getvalue()
48 req.respond(HTTP_OK, HGTYPE, length=len(resp))
48 req.respond(HTTP_OK, HGTYPE, length=len(resp))
49 req.write(resp)
49 yield resp
50
50
51 def between(repo, req):
51 def between(repo, req):
52 if 'pairs' in req.form:
52 if 'pairs' in req.form:
@@ -57,7 +57,7 b' def between(repo, req):'
57 resp.write(" ".join(map(hex, b)) + "\n")
57 resp.write(" ".join(map(hex, b)) + "\n")
58 resp = resp.getvalue()
58 resp = resp.getvalue()
59 req.respond(HTTP_OK, HGTYPE, length=len(resp))
59 req.respond(HTTP_OK, HGTYPE, length=len(resp))
60 req.write(resp)
60 yield resp
61
61
62 def changegroup(repo, req):
62 def changegroup(repo, req):
63 req.respond(HTTP_OK, HGTYPE)
63 req.respond(HTTP_OK, HGTYPE)
@@ -72,9 +72,9 b' def changegroup(repo, req):'
72 chunk = f.read(4096)
72 chunk = f.read(4096)
73 if not chunk:
73 if not chunk:
74 break
74 break
75 req.write(z.compress(chunk))
75 yield z.compress(chunk)
76
76
77 req.write(z.flush())
77 yield z.flush()
78
78
79 def changegroupsubset(repo, req):
79 def changegroupsubset(repo, req):
80 req.respond(HTTP_OK, HGTYPE)
80 req.respond(HTTP_OK, HGTYPE)
@@ -92,9 +92,9 b' def changegroupsubset(repo, req):'
92 chunk = f.read(4096)
92 chunk = f.read(4096)
93 if not chunk:
93 if not chunk:
94 break
94 break
95 req.write(z.compress(chunk))
95 yield z.compress(chunk)
96
96
97 req.write(z.flush())
97 yield z.flush()
98
98
99 def capabilities(repo, req):
99 def capabilities(repo, req):
100 caps = ['lookup', 'changegroupsubset']
100 caps = ['lookup', 'changegroupsubset']
@@ -104,23 +104,11 b' def capabilities(repo, req):'
104 caps.append('unbundle=%s' % ','.join(changegroupmod.bundlepriority))
104 caps.append('unbundle=%s' % ','.join(changegroupmod.bundlepriority))
105 rsp = ' '.join(caps)
105 rsp = ' '.join(caps)
106 req.respond(HTTP_OK, HGTYPE, length=len(rsp))
106 req.respond(HTTP_OK, HGTYPE, length=len(rsp))
107 req.write(rsp)
107 yield rsp
108
108
109 def unbundle(repo, req):
109 def unbundle(repo, req):
110
110
111 def bail(response, headers={}):
111 errorfmt = '0\n%s\n'
112 length = int(req.env.get('CONTENT_LENGTH', 0))
113 for s in util.filechunkiter(req, limit=length):
114 # drain incoming bundle, else client will not see
115 # response when run outside cgi script
116 pass
117
118 status = headers.pop('status', HTTP_OK)
119 req.header(headers.items())
120 req.respond(status, HGTYPE)
121 req.write('0\n')
122 req.write(response)
123
124 proto = req.env.get('wsgi.url_scheme') or 'http'
112 proto = req.env.get('wsgi.url_scheme') or 'http'
125 their_heads = req.form['heads'][0].split(' ')
113 their_heads = req.form['heads'][0].split(' ')
126
114
@@ -130,7 +118,13 b' def unbundle(repo, req):'
130
118
131 # fail early if possible
119 # fail early if possible
132 if not check_heads():
120 if not check_heads():
133 bail('unsynced changes\n')
121 length = int(req.env.get('CONTENT_LENGTH', 0))
122 for s in util.filechunkiter(req, limit=length):
123 # drain incoming bundle, else client will not see
124 # response when run outside cgi script
125 pass
126 req.respond(HTTP_OK, HGTYPE)
127 yield errorfmt % 'unsynced changes'
134 return
128 return
135
129
136 req.respond(HTTP_OK, HGTYPE)
130 req.respond(HTTP_OK, HGTYPE)
@@ -149,8 +143,7 b' def unbundle(repo, req):'
149 lock = repo.lock()
143 lock = repo.lock()
150 try:
144 try:
151 if not check_heads():
145 if not check_heads():
152 req.write('0\n')
146 yield errorfmt % 'unsynced changes'
153 req.write('unsynced changes\n')
154 return
147 return
155
148
156 fp.seek(0)
149 fp.seek(0)
@@ -177,15 +170,12 b' def unbundle(repo, req):'
177 finally:
170 finally:
178 val = sys.stdout.getvalue()
171 val = sys.stdout.getvalue()
179 sys.stdout, sys.stderr = oldio
172 sys.stdout, sys.stderr = oldio
180 req.write('%d\n' % ret)
173 yield '%d\n%s' % (ret, val)
181 req.write(val)
182 finally:
174 finally:
183 del lock
175 del lock
184 except ValueError, inst:
176 except ValueError, inst:
185 req.write('0\n')
177 yield errorfmt % inst
186 req.write(str(inst) + '\n')
187 except (OSError, IOError), inst:
178 except (OSError, IOError), inst:
188 req.write('0\n')
189 filename = getattr(inst, 'filename', '')
179 filename = getattr(inst, 'filename', '')
190 # Don't send our filesystem layout to the client
180 # Don't send our filesystem layout to the client
191 if filename.startswith(repo.root):
181 if filename.startswith(repo.root):
@@ -198,12 +188,11 b' def unbundle(repo, req):'
198 else:
188 else:
199 code = HTTP_SERVER_ERROR
189 code = HTTP_SERVER_ERROR
200 req.respond(code)
190 req.respond(code)
201 req.write('%s: %s\n' % (error, filename))
191 yield '0\n%s: %s\n' % (error, filename)
202 finally:
192 finally:
203 fp.close()
193 fp.close()
204 os.unlink(tempname)
194 os.unlink(tempname)
205
195
206 def stream_out(repo, req):
196 def stream_out(repo, req):
207 req.respond(HTTP_OK, HGTYPE)
197 req.respond(HTTP_OK, HGTYPE)
208 for chunk in streamclone.stream_out(repo, untrusted=True):
198 return streamclone.stream_out(repo, untrusted=True)
209 req.write(chunk)
@@ -122,7 +122,8 b' class _hgwebhandler(object, BaseHTTPServ'
122 self.saved_headers = []
122 self.saved_headers = []
123 self.sent_headers = False
123 self.sent_headers = False
124 self.length = None
124 self.length = None
125 self.server.application(env, self._start_response)
125 for chunk in self.server.application(env, self._start_response):
126 self._write(chunk)
126
127
127 def send_headers(self):
128 def send_headers(self):
128 if not self.saved_status:
129 if not self.saved_status:
General Comments 0
You need to be logged in to leave comments. Login now