Show More
@@ -114,12 +114,8 b' def bundle1allowed(repo, action):' | |||
|
114 | 114 | |
|
115 | 115 | return ui.configbool('server', 'bundle1') |
|
116 | 116 | |
|
117 | # For version 1 transports. | |
|
118 | 117 | commands = wireprototypes.commanddict() |
|
119 | 118 | |
|
120 | # For version 2 transports. | |
|
121 | commandsv2 = wireprototypes.commanddict() | |
|
122 | ||
|
123 | 119 | def wireprotocommand(name, args=None, permission='push'): |
|
124 | 120 | """Decorator to declare a wire protocol command. |
|
125 | 121 |
@@ -21,7 +21,6 b' from . import (' | |||
|
21 | 21 | pycompat, |
|
22 | 22 | streamclone, |
|
23 | 23 | util, |
|
24 | wireproto, | |
|
25 | 24 | wireprotoframing, |
|
26 | 25 | wireprototypes, |
|
27 | 26 | ) |
@@ -30,6 +29,8 b" FRAMINGTYPE = b'application/mercurial-ex" | |||
|
30 | 29 | |
|
31 | 30 | HTTP_WIREPROTO_V2 = wireprototypes.HTTP_WIREPROTO_V2 |
|
32 | 31 | |
|
32 | COMMANDS = wireprototypes.commanddict() | |
|
33 | ||
|
33 | 34 | def handlehttpv2request(rctx, req, res, checkperm, urlparts): |
|
34 | 35 | from .hgweb import common as hgwebcommon |
|
35 | 36 | |
@@ -87,7 +88,7 b' def handlehttpv2request(rctx, req, res, ' | |||
|
87 | 88 | # extension. |
|
88 | 89 | extracommands = {'multirequest'} |
|
89 | 90 | |
|
90 |
if command not in |
|
|
91 | if command not in COMMANDS and command not in extracommands: | |
|
91 | 92 | res.status = b'404 Not Found' |
|
92 | 93 | res.headers[b'Content-Type'] = b'text/plain' |
|
93 | 94 | res.setbodybytes(_('unknown wire protocol command: %s\n') % command) |
@@ -98,7 +99,7 b' def handlehttpv2request(rctx, req, res, ' | |||
|
98 | 99 | |
|
99 | 100 | proto = httpv2protocolhandler(req, ui) |
|
100 | 101 | |
|
101 |
if (not |
|
|
102 | if (not COMMANDS.commandavailable(command, proto) | |
|
102 | 103 | and command not in extracommands): |
|
103 | 104 | res.status = b'404 Not Found' |
|
104 | 105 | res.headers[b'Content-Type'] = b'text/plain' |
@@ -254,7 +255,7 b' def _httpv2runcommand(ui, repo, req, res' | |||
|
254 | 255 | proto = httpv2protocolhandler(req, ui, args=command['args']) |
|
255 | 256 | |
|
256 | 257 | if reqcommand == b'multirequest': |
|
257 |
if not |
|
|
258 | if not COMMANDS.commandavailable(command['command'], proto): | |
|
258 | 259 | # TODO proper error mechanism |
|
259 | 260 | res.status = b'200 OK' |
|
260 | 261 | res.headers[b'Content-Type'] = b'text/plain' |
@@ -264,7 +265,7 b' def _httpv2runcommand(ui, repo, req, res' | |||
|
264 | 265 | |
|
265 | 266 | # TODO don't use assert here, since it may be elided by -O. |
|
266 | 267 | assert authedperm in (b'ro', b'rw') |
|
267 |
wirecommand = |
|
|
268 | wirecommand = COMMANDS[command['command']] | |
|
268 | 269 | assert wirecommand.permission in ('push', 'pull') |
|
269 | 270 | |
|
270 | 271 | if authedperm == b'ro' and wirecommand.permission != 'pull': |
@@ -334,7 +335,7 b' def getdispatchrepo(repo, proto, command' | |||
|
334 | 335 | def dispatch(repo, proto, command): |
|
335 | 336 | repo = getdispatchrepo(repo, proto, command) |
|
336 | 337 | |
|
337 |
func, spec = |
|
|
338 | func, spec = COMMANDS[command] | |
|
338 | 339 | args = proto.getargs(spec) |
|
339 | 340 | |
|
340 | 341 | return func(repo, proto, **args) |
@@ -404,7 +405,7 b' def _capabilitiesv2(repo, proto):' | |||
|
404 | 405 | 'framingmediatypes': [FRAMINGTYPE], |
|
405 | 406 | } |
|
406 | 407 | |
|
407 |
for command, entry in |
|
|
408 | for command, entry in COMMANDS.items(): | |
|
408 | 409 | caps['commands'][command] = { |
|
409 | 410 | 'args': entry.args, |
|
410 | 411 | 'permissions': [entry.permission], |
@@ -445,11 +446,11 b' def wireprotocommand(name, args=None, pe' | |||
|
445 | 446 | 'must be declared as dicts') |
|
446 | 447 | |
|
447 | 448 | def register(func): |
|
448 | if name in wireproto.commandsv2: | |
|
449 | if name in COMMANDS: | |
|
449 | 450 | raise error.ProgrammingError('%s command already registered ' |
|
450 | 451 | 'for version 2' % name) |
|
451 | 452 | |
|
452 |
|
|
|
453 | COMMANDS[name] = wireprototypes.commandentry( | |
|
453 | 454 | func, args=args, transports=transports, permission=permission) |
|
454 | 455 | |
|
455 | 456 | return func |
General Comments 0
You need to be logged in to leave comments.
Login now