Mercurial > evolve
changeset 2058:92c2a54f98ee
exchange: split between modern and legacy code
We make it clearer what code is old crust and what code is the cutting edge
part.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Tue, 07 Mar 2017 15:04:58 +0100 |
parents | 4c195eb4d2c5 |
children | ebbce3be9142 |
files | hgext3rd/evolve/obsexchange.py |
diffstat | 1 files changed, 65 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext3rd/evolve/obsexchange.py Tue Mar 07 14:59:00 2017 +0100 +++ b/hgext3rd/evolve/obsexchange.py Tue Mar 07 15:04:58 2017 +0100 @@ -41,7 +41,68 @@ obsexcmsg = utility.obsexcmsg obsexcprg = utility.obsexcprg -_pushkeyescape = getattr(obsolete, '_pushkeyescape', None) +### adds support for the 'evo_obscommon' argument to getbundle +# +# This argument use the data recovered from the discovery to request only a +# subpart of the obsolete subtree. + +@eh.uisetup +def addgetbundleargs(self): + wireproto.gboptsmap['evo_obscommon'] = 'nodes' + +@eh.wrapfunction(exchange, '_pullbundle2extraprepare') +def _addobscommontob2pull(orig, pullop, kwargs): + ret = orig(pullop, kwargs) + if ('obsmarkers' in kwargs and + pullop.remote.capable('_evoext_getbundle_obscommon')): + boundaries = obsdiscovery._buildpullobsmarkersboundaries(pullop) + common = boundaries['common'] + if common != [node.nullid]: + kwargs['evo_obscommon'] = common + return ret + +@eh.wrapfunction(exchange, '_pullobsolete') +def _pullobsolete(orig, pullop): + if not obsolete.isenabled(pullop.repo, obsolete.exchangeopt): + return None + if 'obsmarkers' in pullop.stepsdone: + return None + wirepull = pullop.remote.capable('_evoext_pullobsmarkers_0') + if not wirepull: + return orig(pullop) + if 'obsolete' not in pullop.remote.listkeys('namespaces'): + return None # remote opted out of obsolescence marker exchange + tr = None + ui = pullop.repo.ui + boundaries = obsdiscovery._buildpullobsmarkersboundaries(pullop) + if not set(boundaries['heads']) - set(boundaries['common']): + obsexcmsg(ui, "nothing to pull\n") + return None + + obsexcmsg(ui, "pull obsolescence markers\n", True) + new = 0 + + if wirepull: + obsdata = pullop.remote.evoext_pullobsmarkers_0(**boundaries) + obsdata = obsdata.read() + if len(obsdata) > 5: + msg = "merging obsolescence markers (%i bytes)\n" % len(obsdata) + obsexcmsg(ui, msg) + tr = pullop.gettransaction() + old = len(pullop.repo.obsstore._all) + pullop.repo.obsstore.mergemarkers(tr, obsdata) + new = len(pullop.repo.obsstore._all) - old + obsexcmsg(ui, "%i obsolescence markers added\n" % new, True) + else: + obsexcmsg(ui, "no unknown remote markers\n") + obsexcmsg(ui, "DONE\n") + if new: + pullop.repo.invalidatevolatilesets() + return tr + +############################################### +### Support for old legacy exchange methods ### +############################################### class pushobsmarkerStringIO(StringIO): """hacky string io for progress""" @@ -107,7 +168,7 @@ repo.ui.warn(msg) repo.ui.warn('(please upgrade your server and enable evolve.serveronly on it)\n') rslts = [] - remotedata = _pushkeyescape(markers).items() + remotedata = obsolete._pushkeyescape(markers).items() totalbytes = sum(len(d) for k, d in remotedata) sentbytes = 0 obsexcmsg(repo.ui, "pushing %i obsolescence markers in %i " @@ -127,6 +188,8 @@ repo.ui.warn(msg) obsexcmsg(repo.ui, "DONE\n") +# Supporting legacy way to push obsmarker so that old client can still push +# them somewhat efficiently @eh.addattr(wireproto.wirepeer, 'evoext_pushobsmarkers_0') def client_pushobsmarkers(self, obsfile): @@ -170,60 +233,6 @@ data = obsfile.read() serveronly._pushobsmarkers(peer._repo, data) -@eh.uisetup -def addgetbundleargs(self): - wireproto.gboptsmap['evo_obscommon'] = 'nodes' - -@eh.wrapfunction(exchange, '_pullbundle2extraprepare') -def _addobscommontob2pull(orig, pullop, kwargs): - ret = orig(pullop, kwargs) - if ('obsmarkers' in kwargs and - pullop.remote.capable('_evoext_getbundle_obscommon')): - boundaries = obsdiscovery._buildpullobsmarkersboundaries(pullop) - common = boundaries['common'] - if common != [node.nullid]: - kwargs['evo_obscommon'] = common - return ret - -@eh.wrapfunction(exchange, '_pullobsolete') -def _pullobsolete(orig, pullop): - if not obsolete.isenabled(pullop.repo, obsolete.exchangeopt): - return None - if 'obsmarkers' in pullop.stepsdone: - return None - wirepull = pullop.remote.capable('_evoext_pullobsmarkers_0') - if not wirepull: - return orig(pullop) - if 'obsolete' not in pullop.remote.listkeys('namespaces'): - return None # remote opted out of obsolescence marker exchange - tr = None - ui = pullop.repo.ui - boundaries = obsdiscovery._buildpullobsmarkersboundaries(pullop) - if not set(boundaries['heads']) - set(boundaries['common']): - obsexcmsg(ui, "nothing to pull\n") - return None - - obsexcmsg(ui, "pull obsolescence markers\n", True) - new = 0 - - if wirepull: - obsdata = pullop.remote.evoext_pullobsmarkers_0(**boundaries) - obsdata = obsdata.read() - if len(obsdata) > 5: - msg = "merging obsolescence markers (%i bytes)\n" % len(obsdata) - obsexcmsg(ui, msg) - tr = pullop.gettransaction() - old = len(pullop.repo.obsstore._all) - pullop.repo.obsstore.mergemarkers(tr, obsdata) - new = len(pullop.repo.obsstore._all) - old - obsexcmsg(ui, "%i obsolescence markers added\n" % new, True) - else: - obsexcmsg(ui, "no unknown remote markers\n") - obsexcmsg(ui, "DONE\n") - if new: - pullop.repo.invalidatevolatilesets() - return tr - @eh.addattr(wireproto.wirepeer, 'evoext_pullobsmarkers_0') def client_pullobsmarkers(self, heads=None, common=None): self.requirecap('_evoext_pullobsmarkers_0', _('look up remote obsmarkers'))