Mercurial > hg > mercurial-crew-with-dirclash
annotate mercurial/hgweb/wsgicgi.py @ 5192:33015dac5df5
convert: fix mercurial_sink.putcommit
Changeset 4ebc8693ce72 added some code to putcommit to avoid creating a
revision that touches no files, but this can break regular conversions
from some repositories:
- conceptually, since we're converting a repo, we should try to make
the new hg repo as similar as possible to the original repo - we
should create a new changeset, even if the original revision didn't
touch any files (maybe the commit message had some important bit);
- even if a "regular" revision that doesn't touch any file may seem
weird (and maybe even broken), it's completely legitimate for a merge
revision to not touch any file, and, if we just skip it, the
converted repo will end up with wrong history and possibly an extra
head.
As an example, say the crew and main hg repos are sync'ed. Somebody
sends an important patch to the mailing list. Matt quickly applies
and pushes it. But at the same time somebody also applies it to crew
and pushes it. Suppose the commit message ended up being a bit
different (say, there was a typo and somebody didn't fix it) or that
the date ended up being different (because of different patch-applying
scripts): the changeset hashes will be different, but the manifests
will be the same.
Since both changesets were pushed to public repos, it's hard to recall
them. If both are merged, the manifest from the resulting merge
revision will have the exact same contents as its parents - i.e. the
merge revision really doesn't touch any file at all.
To keep the file filtering stuff "working", the generic code was changed
to skip empty revisions if we're filtering the repo, fixing a bug in the
process (we want parents[0] instead of tip).
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Fri, 17 Aug 2007 20:18:05 -0300 |
parents | be591b740e0f |
children |
rev | line source |
---|---|
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
1 # hgweb/wsgicgi.py - CGI->WSGI translator |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
2 # |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
3 # Copyright 2006 Eric Hopper <hopper@omnifarious.org> |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
4 # |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
6 # of the GNU General Public License, incorporated herein by reference. |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
7 # |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
8 # This was originally copied from the public domain code at |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
9 # http://www.python.org/dev/peps/pep-0333/#the-server-gateway-side |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
10 |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
11 import os, sys |
4076
5a89c61c189c
Switch CGI stdout to binary on windows
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3673
diff
changeset
|
12 from mercurial import util |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
13 |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
14 def launch(application): |
4496
7605da1c3b5c
wsgicgi: change stdin to binary mode
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4076
diff
changeset
|
15 util.set_binary(sys.stdin) |
4076
5a89c61c189c
Switch CGI stdout to binary on windows
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3673
diff
changeset
|
16 util.set_binary(sys.stdout) |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
17 |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
18 environ = dict(os.environ.items()) |
3673
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2558
diff
changeset
|
19 environ['wsgi.input'] = sys.stdin |
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2558
diff
changeset
|
20 environ['wsgi.errors'] = sys.stderr |
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2558
diff
changeset
|
21 environ['wsgi.version'] = (1, 0) |
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2558
diff
changeset
|
22 environ['wsgi.multithread'] = False |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
23 environ['wsgi.multiprocess'] = True |
3673
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2558
diff
changeset
|
24 environ['wsgi.run_once'] = True |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
25 |
4869
be591b740e0f
Handle CGI SSL detection via HTTPS environment better.
Wesley J. Landaker <wjl@icecavern.net>
parents:
4496
diff
changeset
|
26 if environ.get('HTTPS','off').lower() in ('on','1','yes'): |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
27 environ['wsgi.url_scheme'] = 'https' |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
28 else: |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
29 environ['wsgi.url_scheme'] = 'http' |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
30 |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
31 headers_set = [] |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
32 headers_sent = [] |
2558
1120302009d7
hgweb: fix unbundle.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2506
diff
changeset
|
33 out = sys.stdout |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
34 |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
35 def write(data): |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
36 if not headers_set: |
3673
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2558
diff
changeset
|
37 raise AssertionError("write() before start_response()") |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
38 |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
39 elif not headers_sent: |
3673
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2558
diff
changeset
|
40 # Before the first output, send the stored headers |
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2558
diff
changeset
|
41 status, response_headers = headers_sent[:] = headers_set |
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2558
diff
changeset
|
42 out.write('Status: %s\r\n' % status) |
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2558
diff
changeset
|
43 for header in response_headers: |
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2558
diff
changeset
|
44 out.write('%s: %s\r\n' % header) |
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2558
diff
changeset
|
45 out.write('\r\n') |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
46 |
2558
1120302009d7
hgweb: fix unbundle.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2506
diff
changeset
|
47 out.write(data) |
1120302009d7
hgweb: fix unbundle.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2506
diff
changeset
|
48 out.flush() |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
49 |
3673
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2558
diff
changeset
|
50 def start_response(status, response_headers, exc_info=None): |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
51 if exc_info: |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
52 try: |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
53 if headers_sent: |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
54 # Re-raise original exception if headers sent |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
55 raise exc_info[0], exc_info[1], exc_info[2] |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
56 finally: |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
57 exc_info = None # avoid dangling circular ref |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
58 elif headers_set: |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
59 raise AssertionError("Headers already set!") |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
60 |
3673
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2558
diff
changeset
|
61 headers_set[:] = [status, response_headers] |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
62 return write |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
63 |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
64 result = application(environ, start_response) |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
65 try: |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
66 for data in result: |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
67 if data: # don't send headers until body appears |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
68 write(data) |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
69 if not headers_sent: |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
70 write('') # send headers now if body was empty |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
71 finally: |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
72 if hasattr(result,'close'): |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
73 result.close() |