We'll be adding more arguments in upcoming commits. Using named
arguments will make the code easier to read.
Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
We'll be adding more arguments in upcoming commits. Using named
arguments will make the code easier to read.
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/wireproto.py (6 lines) |
Status | Author | Revision | |
---|---|---|---|
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Abandoned | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Abandoned | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg |
def _merge(self, func, args): | def _merge(self, func, args): | ||||
"""Merge this instance with an incoming 2-tuple. | """Merge this instance with an incoming 2-tuple. | ||||
This is called when a caller using the old 2-tuple API attempts | This is called when a caller using the old 2-tuple API attempts | ||||
to replace an instance. The incoming values are merged with | to replace an instance. The incoming values are merged with | ||||
data not captured by the 2-tuple and a new instance containing | data not captured by the 2-tuple and a new instance containing | ||||
the union of the two objects is returned. | the union of the two objects is returned. | ||||
""" | """ | ||||
return commandentry(func, args) | return commandentry(func, args=args) | ||||
# Old code treats instances as 2-tuples. So expose that interface. | # Old code treats instances as 2-tuples. So expose that interface. | ||||
def __iter__(self): | def __iter__(self): | ||||
yield self.func | yield self.func | ||||
yield self.args | yield self.args | ||||
def __getitem__(self, i): | def __getitem__(self, i): | ||||
if i == 0: | if i == 0: | ||||
# It is common for extensions to wrap wire protocol commands via | # It is common for extensions to wrap wire protocol commands via | ||||
# e.g. ``wireproto.commands[x] = (newfn, args)``. Because callers | # e.g. ``wireproto.commands[x] = (newfn, args)``. Because callers | ||||
# doing this aren't aware of the new API that uses objects to store | # doing this aren't aware of the new API that uses objects to store | ||||
# command entries, we automatically merge old state with new. | # command entries, we automatically merge old state with new. | ||||
if k in self: | if k in self: | ||||
v = self[k]._merge(v[0], v[1]) | v = self[k]._merge(v[0], v[1]) | ||||
else: | else: | ||||
v = commandentry(v[0], v[1]) | v = commandentry(v[0], args=v[1]) | ||||
else: | else: | ||||
raise ValueError('command entries must be commandentry instances ' | raise ValueError('command entries must be commandentry instances ' | ||||
'or 2-tuples') | 'or 2-tuples') | ||||
return super(commanddict, self).__setitem__(k, v) | return super(commanddict, self).__setitem__(k, v) | ||||
def commandavailable(self, command, proto): | def commandavailable(self, command, proto): | ||||
"""Determine if a command is available for the requested protocol.""" | """Determine if a command is available for the requested protocol.""" | ||||
# For now, commands are available for all protocols. So do a simple | # For now, commands are available for all protocols. So do a simple | ||||
# membership test. | # membership test. | ||||
return command in self | return command in self | ||||
commands = commanddict() | commands = commanddict() | ||||
def wireprotocommand(name, args=''): | def wireprotocommand(name, args=''): | ||||
"""Decorator to declare a wire protocol command. | """Decorator to declare a wire protocol command. | ||||
``name`` is the name of the wire protocol command being provided. | ``name`` is the name of the wire protocol command being provided. | ||||
``args`` is a space-delimited list of named arguments that the command | ``args`` is a space-delimited list of named arguments that the command | ||||
accepts. ``*`` is a special value that says to accept all arguments. | accepts. ``*`` is a special value that says to accept all arguments. | ||||
""" | """ | ||||
def register(func): | def register(func): | ||||
commands[name] = commandentry(func, args) | commands[name] = commandentry(func, args=args) | ||||
return func | return func | ||||
return register | return register | ||||
@wireprotocommand('batch', 'cmds *') | @wireprotocommand('batch', 'cmds *') | ||||
def batch(repo, proto, cmds, others): | def batch(repo, proto, cmds, others): | ||||
repo = repo.filtered("served") | repo = repo.filtered("served") | ||||
res = [] | res = [] | ||||
for pair in cmds.split(';'): | for pair in cmds.split(';'): |