hgext/evolve.py
changeset 1082 74bc8a0c2c02
parent 1081 dddb8a70437c
child 1083 46048124c44b
equal deleted inserted replaced
1081:dddb8a70437c 1082:74bc8a0c2c02
  2424     if (obsolete._enabled and repo.obsstore and
  2424     if (obsolete._enabled and repo.obsstore and
  2425         'obsolete' in remote.listkeys('namespaces')):
  2425         'obsolete' in remote.listkeys('namespaces')):
  2426         markers = pushop.outobsmarkers
  2426         markers = pushop.outobsmarkers
  2427         if not markers:
  2427         if not markers:
  2428             obsexcmsg(repo.ui, "no marker to push\n")
  2428             obsexcmsg(repo.ui, "no marker to push\n")
  2429         elif remote.capable('_evoext_b2x_obsmarkers_0'):
       
  2430             obsdata = pushobsmarkerStringIO()
       
  2431             _encodemarkersstream(obsdata, markers)
       
  2432             obsdata.seek(0)
       
  2433             obsdata.ui = repo.ui
       
  2434             obsexcmsg(repo.ui, "pushing %i obsolescence markers (%i bytes)\n"
       
  2435                                % (len(markers), len(obsdata.getvalue())),
       
  2436                       True)
       
  2437             bundler = bundle2.bundle20(pushop.ui, {})
       
  2438             capsblob = bundle2.encodecaps(pushop.repo.bundle2caps)
       
  2439             bundler.addpart(bundle2.bundlepart('b2x:replycaps', data=capsblob))
       
  2440             cgpart = bundle2.bundlepart('EVOLVE:B2X:OBSMARKERV1', data=obsdata)
       
  2441             bundler.addpart(cgpart)
       
  2442             stream = util.chunkbuffer(bundler.getchunks())
       
  2443             try:
       
  2444                 reply = pushop.remote.unbundle(stream, ['force'], 'push')
       
  2445             except bundle2.UnknownPartError, exc:
       
  2446                 raise util.Abort('missing support for %s' % exc)
       
  2447             try:
       
  2448                 op = bundle2.processbundle(pushop.repo, reply)
       
  2449             except bundle2.UnknownPartError, exc:
       
  2450                 raise util.Abort('missing support for %s' % exc)
       
  2451             obsexcprg(repo.ui, None)
       
  2452         elif remote.capable('_evoext_pushobsmarkers_0'):
  2429         elif remote.capable('_evoext_pushobsmarkers_0'):
  2453             obsdata = pushobsmarkerStringIO()
  2430             obsdata = pushobsmarkerStringIO()
  2454             _encodemarkersstream(obsdata, markers)
  2431             _encodemarkersstream(obsdata, markers)
  2455             obsdata.seek(0)
  2432             obsdata.seek(0)
  2456             obsdata.ui = repo.ui
  2433             obsdata.ui = repo.ui
  2542     finally:
  2519     finally:
  2543         lock.release()
  2520         lock.release()
  2544     repo.hook('evolve_pushobsmarkers')
  2521     repo.hook('evolve_pushobsmarkers')
  2545     return wireproto.pushres(0)
  2522     return wireproto.pushres(0)
  2546 
  2523 
  2547 @bundle2.parthandler('evolve:b2x:obsmarkerv1')
       
  2548 def handleobsmarkerv1(op, inpart):
       
  2549     """add a stream of obsmarker to the repo"""
       
  2550     tr = op.gettransaction()
       
  2551     advparams = dict(inpart.advisoryparams)
       
  2552     length = advparams.get('totalbytes')
       
  2553     if length is None:
       
  2554         obsdata = inpart.read()
       
  2555     else:
       
  2556         length = int(length)
       
  2557         data = StringIO()
       
  2558         current = 0
       
  2559         obsexcprg(op.repo.ui, current, unit="bytes", total=length)
       
  2560         while current < length:
       
  2561             readsize = min(length-current, 4096)
       
  2562             data.write(inpart.read(readsize))
       
  2563             current += readsize
       
  2564             obsexcprg(op.repo.ui, current, unit="bytes", total=length)
       
  2565         obsexcprg(op.repo.ui, None)
       
  2566         obsdata = data.getvalue()
       
  2567     totalsize = len(obsdata)
       
  2568     old = len(op.repo.obsstore._all)
       
  2569     op.repo.obsstore.mergemarkers(tr, obsdata)
       
  2570     new = len(op.repo.obsstore._all) - old
       
  2571     op.records.add('evo_obsmarkers', {'new': new, 'bytes': totalsize})
       
  2572     tr.hookargs['evolve_new_obsmarkers'] = str(new)
       
  2573 
       
  2574 def _buildpullobsmerkersboundaries(pullop):
  2524 def _buildpullobsmerkersboundaries(pullop):
  2575     """small funtion returning the argument for pull markers call
  2525     """small funtion returning the argument for pull markers call
  2576     may to contains 'heads' and 'common'. skip the key for None.
  2526     may to contains 'heads' and 'common'. skip the key for None.
  2577 
  2527 
  2578     Its a separed functio to play around with strategy for that."""
  2528     Its a separed functio to play around with strategy for that."""
  2619 
  2569 
  2620 @eh.wrapfunction(exchange, '_pullobsolete')
  2570 @eh.wrapfunction(exchange, '_pullobsolete')
  2621 def _pullobsolete(orig, pullop):
  2571 def _pullobsolete(orig, pullop):
  2622     if not obsolete._enabled:
  2572     if not obsolete._enabled:
  2623         return None
  2573         return None
  2624     b2xpull = pullop.remote.capable('_evoext_b2x_obsmarkers_0')
       
  2625     wirepull = pullop.remote.capable('_evoext_pullobsmarkers_0')
  2574     wirepull = pullop.remote.capable('_evoext_pullobsmarkers_0')
  2626     if not (b2xpull or wirepull):
  2575     if not wirepull:
  2627         return orig(pullop)
  2576         return orig(pullop)
  2628     if 'obsolete' not in pullop.remote.listkeys('namespaces'):
  2577     if 'obsolete' not in pullop.remote.listkeys('namespaces'):
  2629         return None # remote opted out of obsolescence marker exchange
  2578         return None # remote opted out of obsolescence marker exchange
  2630     tr = None
  2579     tr = None
  2631     ui = pullop.repo.ui
  2580     ui = pullop.repo.ui
  2635         return None
  2584         return None
  2636 
  2585 
  2637     obsexcmsg(ui, "pull obsolescence markers\n", True)
  2586     obsexcmsg(ui, "pull obsolescence markers\n", True)
  2638     new = 0
  2587     new = 0
  2639 
  2588 
  2640     if b2xpull:
  2589     if wirepull:
  2641         kwargs = {'bundlecaps': set(['HG2X'])}
       
  2642         capsblob = bundle2.encodecaps(pullop.repo.bundle2caps)
       
  2643         kwargs['bundlecaps'].add('bundle2=' + urllib.quote(capsblob))
       
  2644         kwargs['heads'] = [nullid]
       
  2645         kwargs['common'] = [nullid]
       
  2646         kwargs['evo_obsmarker'] = '1'
       
  2647         kwargs['evo_obscommon'] = wireproto.encodelist(boundaries['common'])
       
  2648         kwargs['evo_obsheads'] = wireproto.encodelist(boundaries['heads'])
       
  2649         bundle = pullop.remote.getbundle('pull', **kwargs)
       
  2650         try:
       
  2651             op = bundle2.processbundle(pullop.repo, bundle, pullop.gettransaction)
       
  2652         except bundle2.UnknownPartError, exc:
       
  2653             raise util.Abort('missing support for %s' % exc)
       
  2654         bytes = new = 0
       
  2655         for entry in op.records['evo_obsmarkers']:
       
  2656             bytes += entry.get('bytes', 0)
       
  2657             new += entry.get('new', 0)
       
  2658         if 5 < bytes:
       
  2659             obsexcmsg(ui, "merging obsolescence markers (%i bytes)\n"
       
  2660                       % bytes)
       
  2661             obsexcmsg(ui, "%i obsolescence markers added\n" % new, True)
       
  2662             tr = op.gettransaction()
       
  2663         else:
       
  2664             obsexcmsg(ui, "no unknown remote markers\n")
       
  2665         obsexcmsg(ui, "DONE\n")
       
  2666     elif wirepull:
       
  2667         obsdata = pullop.remote.evoext_pullobsmarkers_0(**boundaries)
  2590         obsdata = pullop.remote.evoext_pullobsmarkers_0(**boundaries)
  2668         obsdata = obsdata.read()
  2591         obsdata = obsdata.read()
  2669         if len(obsdata) > 5:
  2592         if len(obsdata) > 5:
  2670             obsexcmsg(ui, "merging obsolescence markers (%i bytes)\n"
  2593             obsexcmsg(ui, "merging obsolescence markers (%i bytes)\n"
  2671                            % len(obsdata))
  2594                            % len(obsdata))
  2795     caps = orig(repo, proto)
  2718     caps = orig(repo, proto)
  2796     if obsolete._enabled:
  2719     if obsolete._enabled:
  2797         caps += ' _evoext_pushobsmarkers_0'
  2720         caps += ' _evoext_pushobsmarkers_0'
  2798         caps += ' _evoext_pullobsmarkers_0'
  2721         caps += ' _evoext_pullobsmarkers_0'
  2799         caps += ' _evoext_obshash_0'
  2722         caps += ' _evoext_obshash_0'
  2800         caps += ' _evoext_b2x_obsmarkers_0'
       
  2801     return caps
  2723     return caps
  2802 
  2724 
  2803 
  2725 
  2804 @eh.extsetup
  2726 @eh.extsetup
  2805 def _installwireprotocol(ui):
  2727 def _installwireprotocol(ui):
  2806     localrepo.moderncaps.add('_evoext_pullobsmarkers_0')
  2728     localrepo.moderncaps.add('_evoext_pullobsmarkers_0')
  2807     localrepo.moderncaps.add('_evoext_b2x_obsmarkers_0')
       
  2808     hgweb_mod.perms['evoext_pushobsmarkers_0'] = 'push'
  2729     hgweb_mod.perms['evoext_pushobsmarkers_0'] = 'push'
  2809     hgweb_mod.perms['evoext_pullobsmarkers_0'] = 'pull'
  2730     hgweb_mod.perms['evoext_pullobsmarkers_0'] = 'pull'
  2810     wireproto.commands['evoext_pushobsmarkers_0'] = (srv_pushobsmarkers, '')
  2731     wireproto.commands['evoext_pushobsmarkers_0'] = (srv_pushobsmarkers, '')
  2811     wireproto.commands['evoext_pullobsmarkers_0'] = (srv_pullobsmarkers, '*')
  2732     wireproto.commands['evoext_pullobsmarkers_0'] = (srv_pullobsmarkers, '*')
  2812     # wrap command content
  2733     # wrap command content