Show More
@@ -7,7 +7,7 b'' | |||||
7 | # GNU General Public License version 2 or any later version. |
|
7 | # GNU General Public License version 2 or any later version. | |
8 |
|
8 | |||
9 | import os |
|
9 | import os | |
10 | from mercurial import ui, hg, hook, error, encoding, templater |
|
10 | from mercurial import ui, hg, hook, error, encoding, templater, wireproto | |
11 | from common import get_mtime, ErrorResponse, permhooks |
|
11 | from common import get_mtime, ErrorResponse, permhooks | |
12 | from common import HTTP_OK, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR |
|
12 | from common import HTTP_OK, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR | |
13 | from request import wsgirequest |
|
13 | from request import wsgirequest | |
@@ -22,6 +22,33 b' perms = {' | |||||
22 | 'pushkey': 'push', |
|
22 | 'pushkey': 'push', | |
23 | } |
|
23 | } | |
24 |
|
24 | |||
|
25 | class webproto(object): | |||
|
26 | def __init__(self, req): | |||
|
27 | self.req = req | |||
|
28 | self.response = '' | |||
|
29 | def getargs(self, args): | |||
|
30 | data = {} | |||
|
31 | keys = args.split() | |||
|
32 | for k in keys: | |||
|
33 | if k == '*': | |||
|
34 | star = {} | |||
|
35 | for key in self.req.form.keys(): | |||
|
36 | if key not in keys: | |||
|
37 | star[key] = self.req.form[key][0] | |||
|
38 | data['*'] = star | |||
|
39 | else: | |||
|
40 | data[k] = self.req.form[k][0] | |||
|
41 | return [data[k] for k in keys] | |||
|
42 | def respond(self, s): | |||
|
43 | HGTYPE = 'application/mercurial-0.1' | |||
|
44 | self.req.respond(HTTP_OK, HGTYPE, length=len(s)) | |||
|
45 | self.response = s | |||
|
46 | ||||
|
47 | def callproto(repo, req, cmd): | |||
|
48 | p = webproto(req) | |||
|
49 | r = wireproto.dispatch(repo, p, cmd) | |||
|
50 | yield p.response | |||
|
51 | ||||
25 | class hgweb(object): |
|
52 | class hgweb(object): | |
26 | def __init__(self, repo, name=None, baseui=None): |
|
53 | def __init__(self, repo, name=None, baseui=None): | |
27 | if isinstance(repo, str): |
|
54 | if isinstance(repo, str): | |
@@ -123,6 +150,8 b' class hgweb(object):' | |||||
123 | if cmd == 'unbundle': |
|
150 | if cmd == 'unbundle': | |
124 | req.drain() |
|
151 | req.drain() | |
125 | raise |
|
152 | raise | |
|
153 | if cmd in wireproto.commands: | |||
|
154 | return callproto(self.repo, req, cmd) | |||
126 | method = getattr(protocol, cmd) |
|
155 | method = getattr(protocol, cmd) | |
127 | return method(self.repo, req) |
|
156 | return method(self.repo, req) | |
128 | except ErrorResponse, inst: |
|
157 | except ErrorResponse, inst: |
@@ -23,51 +23,6 b' from common import ErrorResponse, HTTP_O' | |||||
23 | HGTYPE = 'application/mercurial-0.1' |
|
23 | HGTYPE = 'application/mercurial-0.1' | |
24 | basecaps = 'lookup changegroupsubset branchmap pushkey'.split() |
|
24 | basecaps = 'lookup changegroupsubset branchmap pushkey'.split() | |
25 |
|
25 | |||
26 | def lookup(repo, req): |
|
|||
27 | try: |
|
|||
28 | r = hex(repo.lookup(req.form['key'][0])) |
|
|||
29 | success = 1 |
|
|||
30 | except Exception, inst: |
|
|||
31 | r = str(inst) |
|
|||
32 | success = 0 |
|
|||
33 | resp = "%s %s\n" % (success, r) |
|
|||
34 | req.respond(HTTP_OK, HGTYPE, length=len(resp)) |
|
|||
35 | yield resp |
|
|||
36 |
|
||||
37 | def heads(repo, req): |
|
|||
38 | resp = " ".join(map(hex, repo.heads())) + "\n" |
|
|||
39 | req.respond(HTTP_OK, HGTYPE, length=len(resp)) |
|
|||
40 | yield resp |
|
|||
41 |
|
||||
42 | def branchmap(repo, req): |
|
|||
43 | branches = repo.branchmap() |
|
|||
44 | heads = [] |
|
|||
45 | for branch, nodes in branches.iteritems(): |
|
|||
46 | branchname = urllib.quote(branch) |
|
|||
47 | branchnodes = [hex(node) for node in nodes] |
|
|||
48 | heads.append('%s %s' % (branchname, ' '.join(branchnodes))) |
|
|||
49 | resp = '\n'.join(heads) |
|
|||
50 | req.respond(HTTP_OK, HGTYPE, length=len(resp)) |
|
|||
51 | yield resp |
|
|||
52 |
|
||||
53 | def branches(repo, req): |
|
|||
54 | nodes = [] |
|
|||
55 | if 'nodes' in req.form: |
|
|||
56 | nodes = map(bin, req.form['nodes'][0].split(" ")) |
|
|||
57 | resp = cStringIO.StringIO() |
|
|||
58 | for b in repo.branches(nodes): |
|
|||
59 | resp.write(" ".join(map(hex, b)) + "\n") |
|
|||
60 | resp = resp.getvalue() |
|
|||
61 | req.respond(HTTP_OK, HGTYPE, length=len(resp)) |
|
|||
62 | yield resp |
|
|||
63 |
|
||||
64 | def between(repo, req): |
|
|||
65 | pairs = [map(bin, p.split("-")) |
|
|||
66 | for p in req.form['pairs'][0].split(" ")] |
|
|||
67 | resp = ''.join(" ".join(map(hex, b)) + "\n" for b in repo.between(pairs)) |
|
|||
68 | req.respond(HTTP_OK, HGTYPE, length=len(resp)) |
|
|||
69 | yield resp |
|
|||
70 |
|
||||
71 | def changegroup(repo, req): |
|
26 | def changegroup(repo, req): | |
72 | req.respond(HTTP_OK, HGTYPE) |
|
27 | req.respond(HTTP_OK, HGTYPE) | |
73 | nodes = [] |
|
28 | nodes = [] | |
@@ -204,22 +159,3 b' def stream_out(repo, req):' | |||||
204 | yield chunk |
|
159 | yield chunk | |
205 | except streamclone.StreamException, inst: |
|
160 | except streamclone.StreamException, inst: | |
206 | yield str(inst) |
|
161 | yield str(inst) | |
207 |
|
||||
208 | def pushkey(repo, req): |
|
|||
209 | namespace = req.form['namespace'][0] |
|
|||
210 | key = req.form['key'][0] |
|
|||
211 | old = req.form['old'][0] |
|
|||
212 | new = req.form['new'][0] |
|
|||
213 |
|
||||
214 | r = repo.pushkey(namespace, key, old, new) |
|
|||
215 | r = '%d\n' % int(r) |
|
|||
216 | req.respond(HTTP_OK, HGTYPE, length=len(r)) |
|
|||
217 | yield r |
|
|||
218 |
|
||||
219 | def listkeys(repo, req): |
|
|||
220 | namespace = req.form['namespace'][0] |
|
|||
221 | d = repo.listkeys(namespace).items() |
|
|||
222 | t = '\n'.join(['%s\t%s' % (k.encode('string-escape'), |
|
|||
223 | v.encode('string-escape')) for k, v in d]) |
|
|||
224 | req.respond(HTTP_OK, HGTYPE, length=len(t)) |
|
|||
225 | yield t |
|
@@ -46,9 +46,9 b' echo % capabilities' | |||||
46 | echo % heads |
|
46 | echo % heads | |
47 | "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '?cmd=heads' |
|
47 | "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '?cmd=heads' | |
48 | echo % lookup |
|
48 | echo % lookup | |
49 |
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '?cmd=lookup& |
|
49 | "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '?cmd=lookup&key=1' | |
50 | echo % branches |
|
50 | echo % branches | |
51 | "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '?cmd=branches' |
|
51 | "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '?cmd=branches&nodes=0000000000000000000000000000000000000000' | |
52 | echo % changegroup |
|
52 | echo % changegroup | |
53 | "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '?cmd=changegroup' \ |
|
53 | "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '?cmd=changegroup' \ | |
54 | | $TESTDIR/printrepr.py |
|
54 | | $TESTDIR/printrepr.py |
@@ -852,11 +852,11 b' 1d22e65f027e5a0609357e7d8e7508cd2ba5d2fe' | |||||
852 | % lookup |
|
852 | % lookup | |
853 | 200 Script output follows |
|
853 | 200 Script output follows | |
854 |
|
854 | |||
855 | 0 'key' |
|
855 | 1 a4f92ed23982be056b9852de5dfe873eaac7f0de | |
856 | % branches |
|
856 | % branches | |
857 | 200 Script output follows |
|
857 | 200 Script output follows | |
858 |
|
858 | |||
859 | 1d22e65f027e5a0609357e7d8e7508cd2ba5d2fe 2ef0ac749a14e4f57a5a822464a0902c6f7f448f 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 |
|
859 | 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 | |
860 | % changegroup |
|
860 | % changegroup | |
861 | 200 Script output follows |
|
861 | 200 Script output follows | |
862 |
|
862 |
General Comments 0
You need to be logged in to leave comments.
Login now