Show More
@@ -6,7 +6,7 b'' | |||||
6 | # This software may be used and distributed according to the terms of the |
|
6 | # This software may be used and distributed according to the terms of the | |
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, zlib | |
10 | from mercurial import ui, hg, hook, error, encoding, templater, wireproto |
|
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 | |
@@ -22,6 +22,7 b' perms = {' | |||||
22 | 'pushkey': 'push', |
|
22 | 'pushkey': 'push', | |
23 | } |
|
23 | } | |
24 |
|
24 | |||
|
25 | HGTYPE = 'application/mercurial-0.1' | |||
25 | class webproto(object): |
|
26 | class webproto(object): | |
26 | def __init__(self, req): |
|
27 | def __init__(self, req): | |
27 | self.req = req |
|
28 | self.req = req | |
@@ -39,8 +40,17 b' class webproto(object):' | |||||
39 | else: |
|
40 | else: | |
40 | data[k] = self.req.form[k][0] |
|
41 | data[k] = self.req.form[k][0] | |
41 | return [data[k] for k in keys] |
|
42 | return [data[k] for k in keys] | |
|
43 | def sendchangegroup(self, cg): | |||
|
44 | self.req.respond(HTTP_OK, HGTYPE) | |||
|
45 | z = zlib.compressobj() | |||
|
46 | while 1: | |||
|
47 | chunk = cg.read(4096) | |||
|
48 | if not chunk: | |||
|
49 | break | |||
|
50 | self.req.write(z.compress(chunk)) | |||
|
51 | self.req.write(z.flush()) | |||
|
52 | ||||
42 | def respond(self, s): |
|
53 | def respond(self, s): | |
43 | HGTYPE = 'application/mercurial-0.1' |
|
|||
44 | self.req.respond(HTTP_OK, HGTYPE, length=len(s)) |
|
54 | self.req.respond(HTTP_OK, HGTYPE, length=len(s)) | |
45 | self.response = s |
|
55 | self.response = s | |
46 |
|
56 |
@@ -23,43 +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 changegroup(repo, req): |
|
|||
27 | req.respond(HTTP_OK, HGTYPE) |
|
|||
28 | nodes = [] |
|
|||
29 |
|
||||
30 | if 'roots' in req.form: |
|
|||
31 | nodes = map(bin, req.form['roots'][0].split(" ")) |
|
|||
32 |
|
||||
33 | z = zlib.compressobj() |
|
|||
34 | f = repo.changegroup(nodes, 'serve') |
|
|||
35 | while 1: |
|
|||
36 | chunk = f.read(4096) |
|
|||
37 | if not chunk: |
|
|||
38 | break |
|
|||
39 | yield z.compress(chunk) |
|
|||
40 |
|
||||
41 | yield z.flush() |
|
|||
42 |
|
||||
43 | def changegroupsubset(repo, req): |
|
|||
44 | req.respond(HTTP_OK, HGTYPE) |
|
|||
45 | bases = [] |
|
|||
46 | heads = [] |
|
|||
47 |
|
||||
48 | if 'bases' in req.form: |
|
|||
49 | bases = [bin(x) for x in req.form['bases'][0].split(' ')] |
|
|||
50 | if 'heads' in req.form: |
|
|||
51 | heads = [bin(x) for x in req.form['heads'][0].split(' ')] |
|
|||
52 |
|
||||
53 | z = zlib.compressobj() |
|
|||
54 | f = repo.changegroupsubset(bases, heads, 'serve') |
|
|||
55 | while 1: |
|
|||
56 | chunk = f.read(4096) |
|
|||
57 | if not chunk: |
|
|||
58 | break |
|
|||
59 | yield z.compress(chunk) |
|
|||
60 |
|
||||
61 | yield z.flush() |
|
|||
62 |
|
||||
63 | def capabilities(repo, req): |
|
26 | def capabilities(repo, req): | |
64 | caps = copy.copy(basecaps) |
|
27 | caps = copy.copy(basecaps) | |
65 | if streamclone.allowed(repo.ui): |
|
28 | if streamclone.allowed(repo.ui): |
@@ -58,6 +58,15 b' class sshserver(object):' | |||||
58 | self.fout.write(v) |
|
58 | self.fout.write(v) | |
59 | self.fout.flush() |
|
59 | self.fout.flush() | |
60 |
|
60 | |||
|
61 | def sendchangegroup(self, changegroup): | |||
|
62 | while True: | |||
|
63 | d = changegroup.read(4096) | |||
|
64 | if not d: | |||
|
65 | break | |||
|
66 | self.fout.write(d) | |||
|
67 | ||||
|
68 | self.fout.flush() | |||
|
69 | ||||
61 | def serve_forever(self): |
|
70 | def serve_forever(self): | |
62 | try: |
|
71 | try: | |
63 | while self.serve_one(): |
|
72 | while self.serve_one(): | |
@@ -105,34 +114,6 b' class sshserver(object):' | |||||
105 | self.lock = None |
|
114 | self.lock = None | |
106 | return "" |
|
115 | return "" | |
107 |
|
116 | |||
108 | def do_changegroup(self): |
|
|||
109 | nodes = [] |
|
|||
110 | roots = self.getarg('roots') |
|
|||
111 | nodes = map(bin, roots.split(" ")) |
|
|||
112 |
|
||||
113 | cg = self.repo.changegroup(nodes, 'serve') |
|
|||
114 | while True: |
|
|||
115 | d = cg.read(4096) |
|
|||
116 | if not d: |
|
|||
117 | break |
|
|||
118 | self.fout.write(d) |
|
|||
119 |
|
||||
120 | self.fout.flush() |
|
|||
121 |
|
||||
122 | def do_changegroupsubset(self): |
|
|||
123 | bases, heads = self.getargs('bases heads') |
|
|||
124 | bases = [bin(n) for n in bases.split(' ')] |
|
|||
125 | heads = [bin(n) for n in heads.split(' ')] |
|
|||
126 |
|
||||
127 | cg = self.repo.changegroupsubset(bases, heads, 'serve') |
|
|||
128 | while True: |
|
|||
129 | d = cg.read(4096) |
|
|||
130 | if not d: |
|
|||
131 | break |
|
|||
132 | self.fout.write(d) |
|
|||
133 |
|
||||
134 | self.fout.flush() |
|
|||
135 |
|
||||
136 | def do_addchangegroup(self): |
|
117 | def do_addchangegroup(self): | |
137 | '''DEPRECATED''' |
|
118 | '''DEPRECATED''' | |
138 |
|
119 |
@@ -15,7 +15,9 b' def dispatch(repo, proto, command):' | |||||
15 | return False |
|
15 | return False | |
16 | func, spec = commands[command] |
|
16 | func, spec = commands[command] | |
17 | args = proto.getargs(spec) |
|
17 | args = proto.getargs(spec) | |
18 |
|
|
18 | r = func(repo, proto, *args) | |
|
19 | if r != None: | |||
|
20 | proto.respond(r) | |||
19 | return True |
|
21 | return True | |
20 |
|
22 | |||
21 | def between(repo, proto, pairs): |
|
23 | def between(repo, proto, pairs): | |
@@ -41,6 +43,17 b' def branches(repo, proto, nodes):' | |||||
41 | r.append(" ".join(map(hex, b)) + "\n") |
|
43 | r.append(" ".join(map(hex, b)) + "\n") | |
42 | return "".join(r) |
|
44 | return "".join(r) | |
43 |
|
45 | |||
|
46 | def changegroup(repo, proto, roots): | |||
|
47 | nodes = map(bin, roots.split(" ")) | |||
|
48 | cg = repo.changegroup(nodes, 'serve') | |||
|
49 | proto.sendchangegroup(cg) | |||
|
50 | ||||
|
51 | def changegroupsubset(repo, proto, bases, heads): | |||
|
52 | bases = [bin(n) for n in bases.split(' ')] | |||
|
53 | heads = [bin(n) for n in heads.split(' ')] | |||
|
54 | cg = repo.changegroupsubset(bases, heads, 'serve') | |||
|
55 | proto.sendchangegroup(cg) | |||
|
56 | ||||
44 | def heads(repo, proto): |
|
57 | def heads(repo, proto): | |
45 | h = repo.heads() |
|
58 | h = repo.heads() | |
46 | return " ".join(map(hex, h)) + "\n" |
|
59 | return " ".join(map(hex, h)) + "\n" | |
@@ -68,6 +81,8 b' commands = {' | |||||
68 | 'between': (between, 'pairs'), |
|
81 | 'between': (between, 'pairs'), | |
69 | 'branchmap': (branchmap, ''), |
|
82 | 'branchmap': (branchmap, ''), | |
70 | 'branches': (branches, 'nodes'), |
|
83 | 'branches': (branches, 'nodes'), | |
|
84 | 'changegroup': (changegroup, 'roots'), | |||
|
85 | 'changegroupsubset': (changegroupsubset, 'bases heads'), | |||
71 | 'heads': (heads, ''), |
|
86 | 'heads': (heads, ''), | |
72 | 'listkeys': (listkeys, 'namespace'), |
|
87 | 'listkeys': (listkeys, 'namespace'), | |
73 | 'lookup': (lookup, 'key'), |
|
88 | 'lookup': (lookup, 'key'), |
@@ -55,7 +55,7 b' SERVER_SIGNATURE="<address>Apache/2.0.53' | |||||
55 | SERVER_SOFTWARE="Apache/2.0.53 (Fedora)"; export SERVER_SOFTWARE |
|
55 | SERVER_SOFTWARE="Apache/2.0.53 (Fedora)"; export SERVER_SOFTWARE | |
56 |
|
56 | |||
57 | echo % try hgweb request |
|
57 | echo % try hgweb request | |
58 | QUERY_STRING="cmd=changegroup"; export QUERY_STRING |
|
58 | QUERY_STRING="cmd=changegroup&roots=0000000000000000000000000000000000000000"; export QUERY_STRING | |
59 | python hgweb.cgi >page1 2>&1 ; echo $? |
|
59 | python hgweb.cgi >page1 2>&1 ; echo $? | |
60 | python "$TESTDIR/md5sum.py" page1 |
|
60 | python "$TESTDIR/md5sum.py" page1 | |
61 |
|
61 |
@@ -50,7 +50,7 b' echo % lookup' | |||||
50 | echo % branches |
|
50 | echo % branches | |
51 | "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '?cmd=branches&nodes=0000000000000000000000000000000000000000' |
|
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&roots=0000000000000000000000000000000000000000' \ | |
54 | | $TESTDIR/printrepr.py |
|
54 | | $TESTDIR/printrepr.py | |
55 | echo % stream_out |
|
55 | echo % stream_out | |
56 | "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '?cmd=stream_out' |
|
56 | "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '?cmd=stream_out' |
General Comments 0
You need to be logged in to leave comments.
Login now