Show More
@@ -175,6 +175,7 b' def uisetup(ui):' | |||||
175 |
|
175 | |||
176 | # ... and wrap some existing ones |
|
176 | # ... and wrap some existing ones | |
177 | wireproto.commands['heads'].func = proto.heads |
|
177 | wireproto.commands['heads'].func = proto.heads | |
|
178 | # TODO also wrap wireproto.commandsv2 once heads is implemented there. | |||
178 |
|
179 | |||
179 | extensions.wrapfunction(webcommands, 'decodepath', overrides.decodepath) |
|
180 | extensions.wrapfunction(webcommands, 'decodepath', overrides.decodepath) | |
180 |
|
181 |
@@ -502,7 +502,11 b' def getdispatchrepo(repo, proto, command' | |||||
502 |
|
502 | |||
503 | def dispatch(repo, proto, command): |
|
503 | def dispatch(repo, proto, command): | |
504 | repo = getdispatchrepo(repo, proto, command) |
|
504 | repo = getdispatchrepo(repo, proto, command) | |
505 | func, spec = commands[command] |
|
505 | ||
|
506 | transportversion = wireprototypes.TRANSPORTS[proto.name]['version'] | |||
|
507 | commandtable = commandsv2 if transportversion == 2 else commands | |||
|
508 | func, spec = commandtable[command] | |||
|
509 | ||||
506 | args = proto.getargs(spec) |
|
510 | args = proto.getargs(spec) | |
507 | return func(repo, proto, *args) |
|
511 | return func(repo, proto, *args) | |
508 |
|
512 | |||
@@ -679,8 +683,12 b" POLICY_ALL = 'all'" | |||||
679 | POLICY_V1_ONLY = 'v1-only' |
|
683 | POLICY_V1_ONLY = 'v1-only' | |
680 | POLICY_V2_ONLY = 'v2-only' |
|
684 | POLICY_V2_ONLY = 'v2-only' | |
681 |
|
685 | |||
|
686 | # For version 1 transports. | |||
682 | commands = commanddict() |
|
687 | commands = commanddict() | |
683 |
|
688 | |||
|
689 | # For version 2 transports. | |||
|
690 | commandsv2 = commanddict() | |||
|
691 | ||||
684 | def wireprotocommand(name, args='', transportpolicy=POLICY_ALL, |
|
692 | def wireprotocommand(name, args='', transportpolicy=POLICY_ALL, | |
685 | permission='push'): |
|
693 | permission='push'): | |
686 | """Decorator to declare a wire protocol command. |
|
694 | """Decorator to declare a wire protocol command. | |
@@ -702,12 +710,15 b" def wireprotocommand(name, args='', tran" | |||||
702 | """ |
|
710 | """ | |
703 | if transportpolicy == POLICY_ALL: |
|
711 | if transportpolicy == POLICY_ALL: | |
704 | transports = set(wireprototypes.TRANSPORTS) |
|
712 | transports = set(wireprototypes.TRANSPORTS) | |
|
713 | transportversions = {1, 2} | |||
705 | elif transportpolicy == POLICY_V1_ONLY: |
|
714 | elif transportpolicy == POLICY_V1_ONLY: | |
706 | transports = {k for k, v in wireprototypes.TRANSPORTS.items() |
|
715 | transports = {k for k, v in wireprototypes.TRANSPORTS.items() | |
707 | if v['version'] == 1} |
|
716 | if v['version'] == 1} | |
|
717 | transportversions = {1} | |||
708 | elif transportpolicy == POLICY_V2_ONLY: |
|
718 | elif transportpolicy == POLICY_V2_ONLY: | |
709 | transports = {k for k, v in wireprototypes.TRANSPORTS.items() |
|
719 | transports = {k for k, v in wireprototypes.TRANSPORTS.items() | |
710 | if v['version'] == 2} |
|
720 | if v['version'] == 2} | |
|
721 | transportversions = {2} | |||
711 | else: |
|
722 | else: | |
712 | raise error.ProgrammingError('invalid transport policy value: %s' % |
|
723 | raise error.ProgrammingError('invalid transport policy value: %s' % | |
713 | transportpolicy) |
|
724 | transportpolicy) | |
@@ -724,8 +735,21 b" def wireprotocommand(name, args='', tran" | |||||
724 | permission) |
|
735 | permission) | |
725 |
|
736 | |||
726 | def register(func): |
|
737 | def register(func): | |
727 | commands[name] = commandentry(func, args=args, transports=transports, |
|
738 | if 1 in transportversions: | |
|
739 | if name in commands: | |||
|
740 | raise error.ProgrammingError('%s command already registered ' | |||
|
741 | 'for version 1' % name) | |||
|
742 | commands[name] = commandentry(func, args=args, | |||
|
743 | transports=transports, | |||
728 | permission=permission) |
|
744 | permission=permission) | |
|
745 | if 2 in transportversions: | |||
|
746 | if name in commandsv2: | |||
|
747 | raise error.ProgrammingError('%s command already registered ' | |||
|
748 | 'for version 2' % name) | |||
|
749 | commandsv2[name] = commandentry(func, args=args, | |||
|
750 | transports=transports, | |||
|
751 | permission=permission) | |||
|
752 | ||||
729 | return func |
|
753 | return func | |
730 | return register |
|
754 | return register | |
731 |
|
755 |
@@ -335,7 +335,7 b' def _handlehttpv2request(rctx, req, res,' | |||||
335 | # extension. |
|
335 | # extension. | |
336 | extracommands = {'multirequest'} |
|
336 | extracommands = {'multirequest'} | |
337 |
|
337 | |||
338 | if command not in wireproto.commands and command not in extracommands: |
|
338 | if command not in wireproto.commandsv2 and command not in extracommands: | |
339 | res.status = b'404 Not Found' |
|
339 | res.status = b'404 Not Found' | |
340 | res.headers[b'Content-Type'] = b'text/plain' |
|
340 | res.headers[b'Content-Type'] = b'text/plain' | |
341 | res.setbodybytes(_('unknown wire protocol command: %s\n') % command) |
|
341 | res.setbodybytes(_('unknown wire protocol command: %s\n') % command) | |
@@ -346,7 +346,7 b' def _handlehttpv2request(rctx, req, res,' | |||||
346 |
|
346 | |||
347 | proto = httpv2protocolhandler(req, ui) |
|
347 | proto = httpv2protocolhandler(req, ui) | |
348 |
|
348 | |||
349 | if (not wireproto.commands.commandavailable(command, proto) |
|
349 | if (not wireproto.commandsv2.commandavailable(command, proto) | |
350 | and command not in extracommands): |
|
350 | and command not in extracommands): | |
351 | res.status = b'404 Not Found' |
|
351 | res.status = b'404 Not Found' | |
352 | res.headers[b'Content-Type'] = b'text/plain' |
|
352 | res.headers[b'Content-Type'] = b'text/plain' | |
@@ -502,7 +502,7 b' def _httpv2runcommand(ui, repo, req, res' | |||||
502 | proto = httpv2protocolhandler(req, ui, args=command['args']) |
|
502 | proto = httpv2protocolhandler(req, ui, args=command['args']) | |
503 |
|
503 | |||
504 | if reqcommand == b'multirequest': |
|
504 | if reqcommand == b'multirequest': | |
505 | if not wireproto.commands.commandavailable(command['command'], proto): |
|
505 | if not wireproto.commandsv2.commandavailable(command['command'], proto): | |
506 | # TODO proper error mechanism |
|
506 | # TODO proper error mechanism | |
507 | res.status = b'200 OK' |
|
507 | res.status = b'200 OK' | |
508 | res.headers[b'Content-Type'] = b'text/plain' |
|
508 | res.headers[b'Content-Type'] = b'text/plain' | |
@@ -512,7 +512,7 b' def _httpv2runcommand(ui, repo, req, res' | |||||
512 |
|
512 | |||
513 | # TODO don't use assert here, since it may be elided by -O. |
|
513 | # TODO don't use assert here, since it may be elided by -O. | |
514 | assert authedperm in (b'ro', b'rw') |
|
514 | assert authedperm in (b'ro', b'rw') | |
515 | wirecommand = wireproto.commands[command['command']] |
|
515 | wirecommand = wireproto.commandsv2[command['command']] | |
516 | assert wirecommand.permission in ('push', 'pull') |
|
516 | assert wirecommand.permission in ('push', 'pull') | |
517 |
|
517 | |||
518 | if authedperm == b'ro' and wirecommand.permission != 'pull': |
|
518 | if authedperm == b'ro' and wirecommand.permission != 'pull': |
@@ -13,6 +13,8 b' stringio = util.stringio' | |||||
13 | class proto(object): |
|
13 | class proto(object): | |
14 | def __init__(self, args): |
|
14 | def __init__(self, args): | |
15 | self.args = args |
|
15 | self.args = args | |
|
16 | self.name = 'dummyproto' | |||
|
17 | ||||
16 | def getargs(self, spec): |
|
18 | def getargs(self, spec): | |
17 | args = self.args |
|
19 | args = self.args | |
18 | args.setdefault(b'*', {}) |
|
20 | args.setdefault(b'*', {}) | |
@@ -22,6 +24,11 b' class proto(object):' | |||||
22 | def checkperm(self, perm): |
|
24 | def checkperm(self, perm): | |
23 | pass |
|
25 | pass | |
24 |
|
26 | |||
|
27 | wireprototypes.TRANSPORTS['dummyproto'] = { | |||
|
28 | 'transport': 'dummy', | |||
|
29 | 'version': 1, | |||
|
30 | } | |||
|
31 | ||||
25 | class clientpeer(wireproto.wirepeer): |
|
32 | class clientpeer(wireproto.wirepeer): | |
26 | def __init__(self, serverrepo, ui): |
|
33 | def __init__(self, serverrepo, ui): | |
27 | self.serverrepo = serverrepo |
|
34 | self.serverrepo = serverrepo |
General Comments 0
You need to be logged in to leave comments.
Login now