def _uisetup(ui): localrepo.featuresetupfuncs.add(featuresetup) hg.wirepeersetupfuncs.append(proto.wirereposetup) cmdutil.outgoinghooks.add(b'largefiles', overrides.outgoinghook) cmdutil.summaryremotehooks.add(b'largefiles', overrides.summaryremotehook) # create the new wireproto commands ... wireprotov1server.wireprotocommand(b'putlfile', b'sha', permission=b'push')(proto.putlfile) wireprotov1server.wireprotocommand(b'getlfile', b'sha', permission=b'pull')(proto.getlfile) wireprotov1server.wireprotocommand(b'statlfile', b'sha', permission=b'pull')(proto.statlfile) wireprotov1server.wireprotocommand(b'lheads', b'', permission=b'pull')( wireprotov1server.heads) extensions.wrapfunction(wireprotov1server.commands[b'heads'], b'func', proto.heads) # TODO also wrap wireproto.commandsv2 once heads is implemented there. # override some extensions' stuff as well for name, module in extensions.extensions(): if name == b'rebase': # TODO: teach exthelper to handle this extensions.wrapfunction(module, b'rebase', overrides.overriderebasecmd)
def _uisetup(ui): localrepo.featuresetupfuncs.add(featuresetup) hg.wirepeersetupfuncs.append(proto.wirereposetup) cmdutil.outgoinghooks.add('largefiles', overrides.outgoinghook) cmdutil.summaryremotehooks.add('largefiles', overrides.summaryremotehook) # create the new wireproto commands ... wireprotov1server.wireprotocommand('putlfile', 'sha', permission='push')(proto.putlfile) wireprotov1server.wireprotocommand('getlfile', 'sha', permission='pull')(proto.getlfile) wireprotov1server.wireprotocommand('statlfile', 'sha', permission='pull')(proto.statlfile) wireprotov1server.wireprotocommand('lheads', '', permission='pull')( wireprotov1server.heads) extensions.wrapfunction(wireprotov1server.commands['heads'], 'func', proto.heads) # TODO also wrap wireproto.commandsv2 once heads is implemented there. # can't do this in reposetup because it needs to have happened before # wirerepo.__init__ is called proto.ssholdcallstream = sshpeer.sshv1peer._callstream proto.httpoldcallstream = httppeer.httppeer._callstream sshpeer.sshv1peer._callstream = proto.sshrepocallstream httppeer.httppeer._callstream = proto.httprepocallstream # override some extensions' stuff as well for name, module in extensions.extensions(): if name == 'rebase': # TODO: teach exthelper to handle this extensions.wrapfunction(module, 'rebase', overrides.overriderebase)
def _registerwireprotocommand(): if b'getannotate' in wireprotov1server.commands: return wireprotov1server.wireprotocommand(b'getannotate', b'path lastnode')(_getannotate)
def uisetup(ui): # Disable auto-status for some commands which assume that all # files in the result are under Mercurial's control entry = extensions.wrapcommand(commands.table, 'add', overrides.overrideadd) addopt = [('', 'large', None, _('add as largefile')), ('', 'normal', None, _('add as normal file')), ('', 'lfsize', '', _('add all files above this size ' '(in megabytes) as largefiles ' '(default: 10)'))] entry[1].extend(addopt) # The scmutil function is called both by the (trivial) addremove command, # and in the process of handling commit -A (issue3542) extensions.wrapfunction(scmutil, 'addremove', overrides.scmutiladdremove) extensions.wrapfunction(cmdutil, 'add', overrides.cmdutiladd) extensions.wrapfunction(cmdutil, 'remove', overrides.cmdutilremove) extensions.wrapfunction(cmdutil, 'forget', overrides.cmdutilforget) extensions.wrapfunction(copies, 'pathcopies', overrides.copiespathcopies) extensions.wrapfunction(upgrade, 'preservedrequirements', overrides.upgraderequirements) extensions.wrapfunction(upgrade, 'supporteddestrequirements', overrides.upgraderequirements) # Subrepos call status function entry = extensions.wrapcommand(commands.table, 'status', overrides.overridestatus) extensions.wrapfunction(subrepo.hgsubrepo, 'status', overrides.overridestatusfn) entry = extensions.wrapcommand(commands.table, 'log', overrides.overridelog) entry = extensions.wrapcommand(commands.table, 'rollback', overrides.overriderollback) entry = extensions.wrapcommand(commands.table, 'verify', overrides.overrideverify) verifyopt = [('', 'large', None, _('verify that all largefiles in current revision exists')), ('', 'lfa', None, _('verify largefiles in all revisions, not just current')), ('', 'lfc', None, _('verify local largefile contents, not just existence'))] entry[1].extend(verifyopt) entry = extensions.wrapcommand(commands.table, 'debugstate', overrides.overridedebugstate) debugstateopt = [('', 'large', None, _('display largefiles dirstate'))] entry[1].extend(debugstateopt) outgoing = lambda orgfunc, *arg, **kwargs: orgfunc(*arg, **kwargs) entry = extensions.wrapcommand(commands.table, 'outgoing', outgoing) outgoingopt = [('', 'large', None, _('display outgoing largefiles'))] entry[1].extend(outgoingopt) cmdutil.outgoinghooks.add('largefiles', overrides.outgoinghook) entry = extensions.wrapcommand(commands.table, 'summary', overrides.overridesummary) summaryopt = [('', 'large', None, _('display outgoing largefiles'))] entry[1].extend(summaryopt) cmdutil.summaryremotehooks.add('largefiles', overrides.summaryremotehook) entry = extensions.wrapcommand(commands.table, 'pull', overrides.overridepull) pullopt = [('', 'all-largefiles', None, _('download all pulled versions of largefiles (DEPRECATED)')), ('', 'lfrev', [], _('download largefiles for these revisions'), _('REV'))] entry[1].extend(pullopt) entry = extensions.wrapcommand(commands.table, 'push', overrides.overridepush) pushopt = [('', 'lfrev', [], _('upload largefiles for these revisions'), _('REV'))] entry[1].extend(pushopt) extensions.wrapfunction(exchange, 'pushoperation', overrides.exchangepushoperation) entry = extensions.wrapcommand(commands.table, 'clone', overrides.overrideclone) cloneopt = [('', 'all-largefiles', None, _('download all versions of all largefiles'))] entry[1].extend(cloneopt) extensions.wrapfunction(hg, 'clone', overrides.hgclone) entry = extensions.wrapcommand(commands.table, 'cat', overrides.overridecat) extensions.wrapfunction(merge, '_checkunknownfile', overrides.overridecheckunknownfile) extensions.wrapfunction(merge, 'calculateupdates', overrides.overridecalculateupdates) extensions.wrapfunction(merge, 'recordupdates', overrides.mergerecordupdates) extensions.wrapfunction(merge, 'update', overrides.mergeupdate) extensions.wrapfunction(filemerge, '_filemerge', overrides.overridefilemerge) extensions.wrapfunction(cmdutil, 'copy', overrides.overridecopy) # Summary calls dirty on the subrepos extensions.wrapfunction(subrepo.hgsubrepo, 'dirty', overrides.overridedirty) extensions.wrapfunction(cmdutil, 'revert', overrides.overriderevert) extensions.wrapcommand(commands.table, 'archive', overrides.overridearchivecmd) extensions.wrapfunction(archival, 'archive', overrides.overridearchive) extensions.wrapfunction(subrepo.hgsubrepo, 'archive', overrides.hgsubrepoarchive) extensions.wrapfunction(webcommands, 'archive', overrides.hgwebarchive) extensions.wrapfunction(cmdutil, 'bailifchanged', overrides.overridebailifchanged) extensions.wrapfunction(cmdutil, 'postcommitstatus', overrides.postcommitstatus) extensions.wrapfunction(scmutil, 'marktouched', overrides.scmutilmarktouched) extensions.wrapfunction(url, 'open', overrides.openlargefile) # create the new wireproto commands ... wireprotov1server.wireprotocommand('putlfile', 'sha', permission='push')(proto.putlfile) wireprotov1server.wireprotocommand('getlfile', 'sha', permission='pull')(proto.getlfile) wireprotov1server.wireprotocommand('statlfile', 'sha', permission='pull')(proto.statlfile) wireprotov1server.wireprotocommand('lheads', '', permission='pull')( wireprotov1server.heads) # ... and wrap some existing ones extensions.wrapfunction(wireprotov1server.commands['heads'], 'func', proto.heads) # TODO also wrap wireproto.commandsv2 once heads is implemented there. extensions.wrapfunction(webcommands, 'decodepath', overrides.decodepath) extensions.wrapfunction(wireprotov1server, '_capabilities', proto._capabilities) # can't do this in reposetup because it needs to have happened before # wirerepo.__init__ is called proto.ssholdcallstream = sshpeer.sshv1peer._callstream proto.httpoldcallstream = httppeer.httppeer._callstream sshpeer.sshv1peer._callstream = proto.sshrepocallstream httppeer.httppeer._callstream = proto.httprepocallstream # override some extensions' stuff as well for name, module in extensions.extensions(): if name == 'purge': extensions.wrapcommand(getattr(module, 'cmdtable'), 'purge', overrides.overridepurge) if name == 'rebase': extensions.wrapcommand(getattr(module, 'cmdtable'), 'rebase', overrides.overriderebase) extensions.wrapfunction(module, 'rebase', overrides.overriderebase) if name == 'transplant': extensions.wrapcommand(getattr(module, 'cmdtable'), 'transplant', overrides.overridetransplant)
def onetimesetup(ui): """Configures the wireprotocol for both clients and servers.""" global onetime if onetime: return onetime = True # support file content requests wireprotov1server.wireprotocommand(b'x_rfl_getflogheads', b'path', permission=b'pull')(getflogheads) wireprotov1server.wireprotocommand(b'x_rfl_getfiles', b'', permission=b'pull')(getfiles) wireprotov1server.wireprotocommand(b'x_rfl_getfile', b'file node', permission=b'pull')(getfile) class streamstate(object): match = None shallowremote = False noflatmf = False state = streamstate() def stream_out_shallow(repo, proto, other): includepattern = None excludepattern = None raw = other.get(b'includepattern') if raw: includepattern = raw.split(b'\0') raw = other.get(b'excludepattern') if raw: excludepattern = raw.split(b'\0') oldshallow = state.shallowremote oldmatch = state.match oldnoflatmf = state.noflatmf try: state.shallowremote = True state.match = match.always() state.noflatmf = other.get(b'noflatmanifest') == b'True' if includepattern or excludepattern: state.match = match.match(repo.root, b'', None, includepattern, excludepattern) streamres = wireprotov1server.stream(repo, proto) # Force the first value to execute, so the file list is computed # within the try/finally scope first = next(streamres.gen) second = next(streamres.gen) def gen(): yield first yield second for value in streamres.gen: yield value return wireprototypes.streamres(gen()) finally: state.shallowremote = oldshallow state.match = oldmatch state.noflatmf = oldnoflatmf wireprotov1server.commands[b'stream_out_shallow'] = ( stream_out_shallow, b'*', ) # don't clone filelogs to shallow clients def _walkstreamfiles(orig, repo, matcher=None): if state.shallowremote: # if we are shallow ourselves, stream our local commits if shallowutil.isenabled(repo): striplen = len(repo.store.path) + 1 readdir = repo.store.rawvfs.readdir visit = [os.path.join(repo.store.path, b'data')] while visit: p = visit.pop() for f, kind, st in readdir(p, stat=True): fp = p + b'/' + f if kind == stat.S_IFREG: if not fp.endswith(b'.i') and not fp.endswith( b'.d'): n = util.pconvert(fp[striplen:]) d = store.decodedir(n) t = store.FILETYPE_OTHER yield (t, d, n, st.st_size) if kind == stat.S_IFDIR: visit.append(fp) if scmutil.istreemanifest(repo): for (t, u, e, s) in repo.store.datafiles(): if u.startswith(b'meta/') and (u.endswith(b'.i') or u.endswith(b'.d')): yield (t, u, e, s) # Return .d and .i files that do not match the shallow pattern match = state.match if match and not match.always(): for (t, u, e, s) in repo.store.datafiles(): f = u[5:-2] # trim data/... and .i/.d if not state.match(f): yield (t, u, e, s) for x in repo.store.topfiles(): if state.noflatmf and x[1][:11] == b'00manifest.': continue yield x elif shallowutil.isenabled(repo): # don't allow cloning from a shallow repo to a full repo # since it would require fetching every version of every # file in order to create the revlogs. raise error.Abort( _(b"Cannot clone from a shallow repo to a full repo.")) else: for x in orig(repo, matcher): yield x extensions.wrapfunction(streamclone, b'_walkstreamfiles', _walkstreamfiles) # expose remotefilelog capabilities def _capabilities(orig, repo, proto): caps = orig(repo, proto) if shallowutil.isenabled(repo) or ui.configbool( b'remotefilelog', b'server'): if isinstance(proto, _sshv1server): # legacy getfiles method which only works over ssh caps.append(constants.NETWORK_CAP_LEGACY_SSH_GETFILES) caps.append(b'x_rfl_getflogheads') caps.append(b'x_rfl_getfile') return caps extensions.wrapfunction(wireprotov1server, b'_capabilities', _capabilities) def _adjustlinkrev(orig, self, *args, **kwargs): # When generating file blobs, taking the real path is too slow on large # repos, so force it to just return the linkrev directly. repo = self._repo if util.safehasattr(repo, b'forcelinkrev') and repo.forcelinkrev: return self._filelog.linkrev(self._filelog.rev(self._filenode)) return orig(self, *args, **kwargs) extensions.wrapfunction(context.basefilectx, b'_adjustlinkrev', _adjustlinkrev) def _iscmd(orig, cmd): if cmd == b'x_rfl_getfiles': return False return orig(cmd) extensions.wrapfunction(wireprotoserver, b'iscmd', _iscmd)