Show More
@@ -16,8 +16,10 b' import webcommands, protocol, webutil' | |||||
16 | perms = { |
|
16 | perms = { | |
17 | 'changegroup': 'pull', |
|
17 | 'changegroup': 'pull', | |
18 | 'changegroupsubset': 'pull', |
|
18 | 'changegroupsubset': 'pull', | |
|
19 | 'stream_out': 'pull', | |||
|
20 | 'listkeys': 'pull', | |||
19 | 'unbundle': 'push', |
|
21 | 'unbundle': 'push', | |
20 |
' |
|
22 | 'pushkey': 'push', | |
21 | } |
|
23 | } | |
22 |
|
24 | |||
23 | class hgweb(object): |
|
25 | class hgweb(object): |
@@ -6,7 +6,7 b'' | |||||
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 | |
@@ -17,11 +17,11 b' from common import ErrorResponse, HTTP_O' | |||||
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: | |
@@ -204,3 +204,22 b' def stream_out(repo, req):' | |||||
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 |
@@ -8,7 +8,7 b'' | |||||
8 |
|
8 | |||
9 | from node import bin, hex, nullid |
|
9 | from node import bin, hex, nullid | |
10 | from i18n import _ |
|
10 | from i18n import _ | |
11 | import repo, changegroup, statichttprepo, error, url, util |
|
11 | import repo, changegroup, statichttprepo, error, url, util, pushkey | |
12 | import os, urllib, urllib2, urlparse, zlib, httplib |
|
12 | import os, urllib, urllib2, urlparse, zlib, httplib | |
13 | import errno, socket |
|
13 | import errno, socket | |
14 | import encoding |
|
14 | import encoding | |
@@ -259,6 +259,31 b' class httprepository(repo.repository):' | |||||
259 | def stream_out(self): |
|
259 | def stream_out(self): | |
260 | return self.do_cmd('stream_out') |
|
260 | return self.do_cmd('stream_out') | |
261 |
|
261 | |||
|
262 | def pushkey(self, namespace, key, old, new): | |||
|
263 | if not self.capable('pushkey'): | |||
|
264 | return False | |||
|
265 | d = self.do_cmd("pushkey", data="", # force a POST | |||
|
266 | namespace=namespace, key=key, old=old, new=new).read() | |||
|
267 | code, output = d.split('\n', 1) | |||
|
268 | try: | |||
|
269 | ret = bool(int(code)) | |||
|
270 | except ValueError, err: | |||
|
271 | raise error.ResponseError( | |||
|
272 | _('push failed (unexpected response):'), d) | |||
|
273 | for l in output.splitlines(True): | |||
|
274 | self.ui.status(_('remote: '), l) | |||
|
275 | return ret | |||
|
276 | ||||
|
277 | def listkeys(self, namespace): | |||
|
278 | if not self.capable('pushkey'): | |||
|
279 | return {} | |||
|
280 | d = self.do_cmd("listkeys", namespace=namespace).read() | |||
|
281 | r = {} | |||
|
282 | for l in d.splitlines(): | |||
|
283 | k, v = l.split('\t') | |||
|
284 | r[k.decode('string-escape')] = v.decode('string-escape') | |||
|
285 | return r | |||
|
286 | ||||
262 | class httpsrepository(httprepository): |
|
287 | class httpsrepository(httprepository): | |
263 | def __init__(self, ui, path): |
|
288 | def __init__(self, ui, path): | |
264 | if not url.has_https: |
|
289 | if not url.has_https: |
@@ -845,7 +845,7 b' graph.render(data);' | |||||
845 | % capabilities |
|
845 | % capabilities | |
846 | 200 Script output follows |
|
846 | 200 Script output follows | |
847 |
|
847 | |||
848 | lookup changegroupsubset branchmap unbundle=HG10GZ,HG10BZ,HG10UN% heads |
|
848 | lookup changegroupsubset branchmap pushkey unbundle=HG10GZ,HG10BZ,HG10UN% heads | |
849 | 200 Script output follows |
|
849 | 200 Script output follows | |
850 |
|
850 | |||
851 | 1d22e65f027e5a0609357e7d8e7508cd2ba5d2fe |
|
851 | 1d22e65f027e5a0609357e7d8e7508cd2ba5d2fe |
General Comments 0
You need to be logged in to leave comments.
Login now