4 # |
4 # |
5 # This software may be used and distributed according to the terms of the |
5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2 or any later version. |
6 # GNU General Public License version 2 or any later version. |
7 |
7 |
8 import cStringIO, zlib, tempfile, errno, os, sys, urllib, copy |
8 import cStringIO, zlib, tempfile, errno, os, sys, urllib, copy |
9 from mercurial import util, streamclone |
9 from mercurial import util, streamclone, pushkey |
10 from mercurial.node import bin, hex |
10 from mercurial.node import bin, hex |
11 from mercurial import changegroup as changegroupmod |
11 from mercurial import changegroup as changegroupmod |
12 from common import ErrorResponse, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR |
12 from common import ErrorResponse, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR |
13 |
13 |
14 # __all__ is populated with the allowed commands. Be sure to add to it if |
14 # __all__ is populated with the allowed commands. Be sure to add to it if |
15 # you're adding a new command, or the new command won't work. |
15 # you're adding a new command, or the new command won't work. |
16 |
16 |
17 __all__ = [ |
17 __all__ = [ |
18 'lookup', 'heads', 'branches', 'between', 'changegroup', |
18 'lookup', 'heads', 'branches', 'between', 'changegroup', |
19 'changegroupsubset', 'capabilities', 'unbundle', 'stream_out', |
19 'changegroupsubset', 'capabilities', 'unbundle', 'stream_out', |
20 'branchmap', |
20 'branchmap', 'pushkey', 'listkeys' |
21 ] |
21 ] |
22 |
22 |
23 HGTYPE = 'application/mercurial-0.1' |
23 HGTYPE = 'application/mercurial-0.1' |
24 basecaps = 'lookup changegroupsubset branchmap'.split() |
24 basecaps = 'lookup changegroupsubset branchmap pushkey'.split() |
25 |
25 |
26 def lookup(repo, req): |
26 def lookup(repo, req): |
27 try: |
27 try: |
28 r = hex(repo.lookup(req.form['key'][0])) |
28 r = hex(repo.lookup(req.form['key'][0])) |
29 success = 1 |
29 success = 1 |
202 try: |
202 try: |
203 for chunk in streamclone.stream_out(repo): |
203 for chunk in streamclone.stream_out(repo): |
204 yield chunk |
204 yield chunk |
205 except streamclone.StreamException, inst: |
205 except streamclone.StreamException, inst: |
206 yield str(inst) |
206 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 |