extensions.wrapfunction() is a more robust method for wrapping a
function, since it allows multiple wrappers.
While we're here, wrap the function registered with the command instead
of installing a new command handler.
yuja |
hg-reviewers |
extensions.wrapfunction() is a more robust method for wrapping a
function, since it allows multiple wrappers.
While we're here, wrap the function registered with the command instead
of installing a new command handler.
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
# advertise the largefiles=serve capability | # advertise the largefiles=serve capability | ||||
def _capabilities(orig, repo, proto): | def _capabilities(orig, repo, proto): | ||||
'''announce largefile server capability''' | '''announce largefile server capability''' | ||||
caps = orig(repo, proto) | caps = orig(repo, proto) | ||||
caps.append('largefiles=serve') | caps.append('largefiles=serve') | ||||
return caps | return caps | ||||
def heads(repo, proto): | def heads(orig, repo, proto): | ||||
'''Wrap server command - largefile capable clients will know to call | '''Wrap server command - largefile capable clients will know to call | ||||
lheads instead''' | lheads instead''' | ||||
if lfutil.islfilesrepo(repo): | if lfutil.islfilesrepo(repo): | ||||
return wireprototypes.ooberror(LARGEFILES_REQUIRED_MSG) | return wireprototypes.ooberror(LARGEFILES_REQUIRED_MSG) | ||||
return wireproto.heads(repo, proto) | |||||
return orig(repo, proto) | |||||
def sshrepocallstream(self, cmd, **args): | def sshrepocallstream(self, cmd, **args): | ||||
if cmd == 'heads' and self.capable('largefiles'): | if cmd == 'heads' and self.capable('largefiles'): | ||||
cmd = 'lheads' | cmd = 'lheads' | ||||
if cmd == 'batch' and self.capable('largefiles'): | if cmd == 'batch' and self.capable('largefiles'): | ||||
args[r'cmds'] = args[r'cmds'].replace('heads ', 'lheads ') | args[r'cmds'] = args[r'cmds'].replace('heads ', 'lheads ') | ||||
return ssholdcallstream(self, cmd, **args) | return ssholdcallstream(self, cmd, **args) | ||||
headsre = re.compile(br'(^|;)heads\b') | headsre = re.compile(br'(^|;)heads\b') | ||||
def httprepocallstream(self, cmd, **args): | def httprepocallstream(self, cmd, **args): | ||||
if cmd == 'heads' and self.capable('largefiles'): | if cmd == 'heads' and self.capable('largefiles'): | ||||
cmd = 'lheads' | cmd = 'lheads' | ||||
if cmd == 'batch' and self.capable('largefiles'): | if cmd == 'batch' and self.capable('largefiles'): | ||||
args[r'cmds'] = headsre.sub('lheads', args[r'cmds']) | args[r'cmds'] = headsre.sub('lheads', args[r'cmds']) | ||||
return httpoldcallstream(self, cmd, **args) | return httpoldcallstream(self, cmd, **args) |
wireproto.wireprotocommand('getlfile', 'sha', permission='pull')( | wireproto.wireprotocommand('getlfile', 'sha', permission='pull')( | ||||
proto.getlfile) | proto.getlfile) | ||||
wireproto.wireprotocommand('statlfile', 'sha', permission='pull')( | wireproto.wireprotocommand('statlfile', 'sha', permission='pull')( | ||||
proto.statlfile) | proto.statlfile) | ||||
wireproto.wireprotocommand('lheads', '', permission='pull')( | wireproto.wireprotocommand('lheads', '', permission='pull')( | ||||
wireproto.heads) | wireproto.heads) | ||||
# ... and wrap some existing ones | # ... and wrap some existing ones | ||||
wireproto.commands['heads'].func = proto.heads | extensions.wrapfunction(wireproto.commands['heads'], 'func', proto.heads) | ||||
# TODO also wrap wireproto.commandsv2 once heads is implemented there. | # TODO also wrap wireproto.commandsv2 once heads is implemented there. | ||||
extensions.wrapfunction(webcommands, 'decodepath', overrides.decodepath) | extensions.wrapfunction(webcommands, 'decodepath', overrides.decodepath) | ||||
extensions.wrapfunction(wireproto, '_capabilities', proto._capabilities) | extensions.wrapfunction(wireproto, '_capabilities', proto._capabilities) | ||||
# can't do this in reposetup because it needs to have happened before | # can't do this in reposetup because it needs to have happened before | ||||
# wirerepo.__init__ is called | # wirerepo.__init__ is called |