Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/protocol.py @ 6788:88a1bcc5c6a7
hgweb: use a single-element tuple to return from protocol.unbundle()
Python 2.3/2.4 don't support yielding from inside try/finally blocks.
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Mon, 30 Jun 2008 10:36:45 +0200 |
parents | 18c429ea3a0e |
children | c228ae4bc89c |
comparison
equal
deleted
inserted
replaced
6787:dbb00e91c327 | 6788:88a1bcc5c6a7 |
---|---|
122 for s in util.filechunkiter(req, limit=length): | 122 for s in util.filechunkiter(req, limit=length): |
123 # drain incoming bundle, else client will not see | 123 # drain incoming bundle, else client will not see |
124 # response when run outside cgi script | 124 # response when run outside cgi script |
125 pass | 125 pass |
126 req.respond(HTTP_OK, HGTYPE) | 126 req.respond(HTTP_OK, HGTYPE) |
127 yield errorfmt % 'unsynced changes' | 127 return errorfmt % 'unsynced changes', |
128 return | |
129 | 128 |
130 req.respond(HTTP_OK, HGTYPE) | 129 req.respond(HTTP_OK, HGTYPE) |
131 | 130 |
132 # do not lock repo until all changegroup data is | 131 # do not lock repo until all changegroup data is |
133 # streamed. save to temporary file. | 132 # streamed. save to temporary file. |
141 | 140 |
142 try: | 141 try: |
143 lock = repo.lock() | 142 lock = repo.lock() |
144 try: | 143 try: |
145 if not check_heads(): | 144 if not check_heads(): |
146 yield errorfmt % 'unsynced changes' | 145 return errorfmt % 'unsynced changes', |
147 return | |
148 | 146 |
149 fp.seek(0) | 147 fp.seek(0) |
150 header = fp.read(6) | 148 header = fp.read(6) |
151 if header.startswith('HG') and not header.startswith('HG10'): | 149 if header.startswith('HG') and not header.startswith('HG10'): |
152 raise ValueError('unknown bundle version') | 150 raise ValueError('unknown bundle version') |
168 sys.stdout.write("abort: %s\n" % inst) | 166 sys.stdout.write("abort: %s\n" % inst) |
169 ret = 0 | 167 ret = 0 |
170 finally: | 168 finally: |
171 val = sys.stdout.getvalue() | 169 val = sys.stdout.getvalue() |
172 sys.stdout, sys.stderr = oldio | 170 sys.stdout, sys.stderr = oldio |
173 yield '%d\n%s' % (ret, val) | 171 return '%d\n%s' % (ret, val), |
174 finally: | 172 finally: |
175 del lock | 173 del lock |
176 except ValueError, inst: | 174 except ValueError, inst: |
177 yield errorfmt % inst | 175 return errorfmt % inst, |
178 except (OSError, IOError), inst: | 176 except (OSError, IOError), inst: |
179 filename = getattr(inst, 'filename', '') | 177 filename = getattr(inst, 'filename', '') |
180 # Don't send our filesystem layout to the client | 178 # Don't send our filesystem layout to the client |
181 if filename.startswith(repo.root): | 179 if filename.startswith(repo.root): |
182 filename = filename[len(repo.root)+1:] | 180 filename = filename[len(repo.root)+1:] |
186 if inst.errno == errno.ENOENT: | 184 if inst.errno == errno.ENOENT: |
187 code = HTTP_NOT_FOUND | 185 code = HTTP_NOT_FOUND |
188 else: | 186 else: |
189 code = HTTP_SERVER_ERROR | 187 code = HTTP_SERVER_ERROR |
190 req.respond(code) | 188 req.respond(code) |
191 yield '0\n%s: %s\n' % (error, filename) | 189 return '0\n%s: %s\n' % (error, filename), |
192 finally: | 190 finally: |
193 fp.close() | 191 fp.close() |
194 os.unlink(tempname) | 192 os.unlink(tempname) |
195 | 193 |
196 def stream_out(repo, req): | 194 def stream_out(repo, req): |