Mercurial > evolve
comparison hgext/evolve.py @ 1033:908273755215
evolve: move OBSEXC message in a dedicated function
This will help use to rework them.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Fri, 08 Aug 2014 16:48:38 -0700 |
parents | 0fcddde7dae6 |
children | 5fd28e46e8f5 |
comparison
equal
deleted
inserted
replaced
1032:0fcddde7dae6 | 1033:908273755215 |
---|---|
2223 | 2223 |
2224 ##################################################################### | 2224 ##################################################################### |
2225 ### Obsolescence marker exchange experimenation ### | 2225 ### Obsolescence marker exchange experimenation ### |
2226 ##################################################################### | 2226 ##################################################################### |
2227 | 2227 |
2228 def obsexcmsg(ui, message): | |
2229 message = 'OBSEXC: ' + message | |
2230 ui.status(message) | |
2231 | |
2232 | |
2228 @command('debugobsoleterelevant', | 2233 @command('debugobsoleterelevant', |
2229 [], | 2234 [], |
2230 'REVSET') | 2235 'REVSET') |
2231 def debugobsoleterelevant(ui, repo, *revsets): | 2236 def debugobsoleterelevant(ui, repo, *revsets): |
2232 """print allobsolescence marker relevant to a set of revision""" | 2237 """print allobsolescence marker relevant to a set of revision""" |
2382 and remote.capable('_evoext_b2x_obsmarkers_0')): | 2387 and remote.capable('_evoext_b2x_obsmarkers_0')): |
2383 # | 2388 # |
2384 pushop.stepsdone.add('obsmarkers') | 2389 pushop.stepsdone.add('obsmarkers') |
2385 markers = _obsmarkersdiscovery(pushop) | 2390 markers = _obsmarkersdiscovery(pushop) |
2386 if not markers: | 2391 if not markers: |
2387 repo.ui.status("OBSEXC: no marker to push\n") | 2392 obsexcmsg(repo.ui, "no marker to push\n") |
2388 repo.ui.status("OBSEXC: DONE\n") | 2393 obsexcmsg(repo.ui, "DONE\n") |
2389 return | 2394 return |
2390 obsdata = pushobsmarkerStringIO() | 2395 obsdata = pushobsmarkerStringIO() |
2391 _encodemarkersstream(obsdata, markers) | 2396 _encodemarkersstream(obsdata, markers) |
2392 obsdata.seek(0) | 2397 obsdata.seek(0) |
2393 obsdata.ui = repo.ui | 2398 obsdata.ui = repo.ui |
2394 repo.ui.status("OBSEXC: pushing %i markers (%i bytes)\n" | 2399 obsexcmsg(repo.ui, "pushing %i markers (%i bytes)\n" |
2395 % (len(markers), len(obsdata.getvalue()))) | 2400 % (len(markers), len(obsdata.getvalue()))) |
2396 bundler.newpart('EVOLVE:B2X:OBSMARKERV1', data=obsdata) | 2401 bundler.newpart('EVOLVE:B2X:OBSMARKERV1', data=obsdata) |
2397 def callback(op): | 2402 def callback(op): |
2398 repo.ui.progress('OBSEXC', None) | 2403 repo.ui.progress('OBSEXC', None) |
2399 repo.ui.status("OBSEXC: DONE\n") | 2404 obsexcmsg(repo.ui, "DONE\n") |
2400 return callback | 2405 return callback |
2401 bundle2partsgenerators.append(_pushb2phases) | 2406 bundle2partsgenerators.append(_pushb2phases) |
2402 bundle2partsgenerators.append(_pushb2obsmarker) | 2407 bundle2partsgenerators.append(_pushb2obsmarker) |
2403 | 2408 |
2404 | 2409 |
2422 if h not in sch) | 2427 if h not in sch) |
2423 else: | 2428 else: |
2424 commonheads = pushop.outgoing.missingheads | 2429 commonheads = pushop.outgoing.missingheads |
2425 if (obsolete._enabled and repo.obsstore and | 2430 if (obsolete._enabled and repo.obsstore and |
2426 'obsolete' in remote.listkeys('namespaces')): | 2431 'obsolete' in remote.listkeys('namespaces')): |
2427 repo.ui.status("OBSEXC: computing relevant nodes\n") | 2432 obsexcmsg(repo.ui, "computing relevant nodes\n") |
2428 revs = unfi.revs('::%ln', commonheads) | 2433 revs = unfi.revs('::%ln', commonheads) |
2429 common = [] | 2434 common = [] |
2430 if remote.capable('_evoext_obshash_0'): | 2435 if remote.capable('_evoext_obshash_0'): |
2431 repo.ui.status("OBSEXC: looking for common markers in %i nodes\n" | 2436 obsexcmsg(repo.ui, "looking for common markers in %i nodes\n" |
2432 % len(revs)) | 2437 % len(revs)) |
2433 common = findcommonobsmarkers(pushop.ui, unfi, remote, revs) | 2438 common = findcommonobsmarkers(pushop.ui, unfi, remote, revs) |
2434 revs = list(unfi.revs('%ld - (::%ln)', revs, common)) | 2439 revs = list(unfi.revs('%ld - (::%ln)', revs, common)) |
2435 nodes = [cl.node(r) for r in revs] | 2440 nodes = [cl.node(r) for r in revs] |
2436 if nodes: | 2441 if nodes: |
2437 repo.ui.status("OBSEXC: computing markers relevant to %i nodes\n" | 2442 obsexcmsg(repo.ui, "computing markers relevant to %i nodes\n" |
2438 % len(nodes)) | 2443 % len(nodes)) |
2439 markers = repo.obsstore.relevantmarkers(nodes) | 2444 markers = repo.obsstore.relevantmarkers(nodes) |
2440 else: | 2445 else: |
2441 repo.ui.status("OBSEXC: markers already in sync\n") | 2446 obsexcmsg(repo.ui, "markers already in sync\n") |
2442 markers = [] | 2447 markers = [] |
2443 return markers | 2448 return markers |
2444 | 2449 |
2445 @eh.wrapfunction(exchange, '_pushobsolete') | 2450 @eh.wrapfunction(exchange, '_pushobsolete') |
2446 def _pushobsolete(orig, pushop): | 2451 def _pushobsolete(orig, pushop): |
2457 cl = unfi.changelog | 2462 cl = unfi.changelog |
2458 if (obsolete._enabled and repo.obsstore and | 2463 if (obsolete._enabled and repo.obsstore and |
2459 'obsolete' in remote.listkeys('namespaces')): | 2464 'obsolete' in remote.listkeys('namespaces')): |
2460 markers = _obsmarkersdiscovery(pushop) | 2465 markers = _obsmarkersdiscovery(pushop) |
2461 if not markers: | 2466 if not markers: |
2462 repo.ui.status("OBSEXC: no marker to push\n") | 2467 obsexcmsg(repo.ui, "no marker to push\n") |
2463 elif remote.capable('_evoext_b2x_obsmarkers_0'): | 2468 elif remote.capable('_evoext_b2x_obsmarkers_0'): |
2464 obsdata = pushobsmarkerStringIO() | 2469 obsdata = pushobsmarkerStringIO() |
2465 _encodemarkersstream(obsdata, markers) | 2470 _encodemarkersstream(obsdata, markers) |
2466 obsdata.seek(0) | 2471 obsdata.seek(0) |
2467 obsdata.ui = repo.ui | 2472 obsdata.ui = repo.ui |
2468 repo.ui.status("OBSEXC: pushing %i markers (%i bytes)\n" | 2473 obsexcmsg(repo.ui, "pushing %i markers (%i bytes)\n" |
2469 % (len(markers), len(obsdata.getvalue()))) | 2474 % (len(markers), len(obsdata.getvalue()))) |
2470 bundler = bundle2.bundle20(pushop.ui, {}) | 2475 bundler = bundle2.bundle20(pushop.ui, {}) |
2471 capsblob = bundle2.encodecaps(pushop.repo.bundle2caps) | 2476 capsblob = bundle2.encodecaps(pushop.repo.bundle2caps) |
2472 bundler.addpart(bundle2.bundlepart('b2x:replycaps', data=capsblob)) | 2477 bundler.addpart(bundle2.bundlepart('b2x:replycaps', data=capsblob)) |
2473 cgpart = bundle2.bundlepart('EVOLVE:B2X:OBSMARKERV1', data=obsdata) | 2478 cgpart = bundle2.bundlepart('EVOLVE:B2X:OBSMARKERV1', data=obsdata) |
2474 bundler.addpart(cgpart) | 2479 bundler.addpart(cgpart) |
2485 elif remote.capable('_evoext_pushobsmarkers_0'): | 2490 elif remote.capable('_evoext_pushobsmarkers_0'): |
2486 obsdata = pushobsmarkerStringIO() | 2491 obsdata = pushobsmarkerStringIO() |
2487 _encodemarkersstream(obsdata, markers) | 2492 _encodemarkersstream(obsdata, markers) |
2488 obsdata.seek(0) | 2493 obsdata.seek(0) |
2489 obsdata.ui = repo.ui | 2494 obsdata.ui = repo.ui |
2490 repo.ui.status("OBSEXC: pushing %i markers (%i bytes)\n" | 2495 obsexcmsg(repo.ui, "pushing %i markers (%i bytes)\n" |
2491 % (len(markers), len(obsdata.getvalue()))) | 2496 % (len(markers), len(obsdata.getvalue()))) |
2492 remote.evoext_pushobsmarkers_0(obsdata) | 2497 remote.evoext_pushobsmarkers_0(obsdata) |
2493 repo.ui.progress('OBSEXC', None) | 2498 repo.ui.progress('OBSEXC', None) |
2494 else: | 2499 else: |
2495 rslts = [] | 2500 rslts = [] |
2496 remotedata = _pushkeyescape(markers).items() | 2501 remotedata = _pushkeyescape(markers).items() |
2497 totalbytes = sum(len(d) for k,d in remotedata) | 2502 totalbytes = sum(len(d) for k,d in remotedata) |
2498 sentbytes = 0 | 2503 sentbytes = 0 |
2499 repo.ui.status("OBSEXC: pushing %i markers in %i pushkey payload (%i bytes)\n" | 2504 obsexcmsg(repo.ui, "pushing %i markers in %i pushkey payload (%i bytes)\n" |
2500 % (len(markers), len(remotedata), totalbytes)) | 2505 % (len(markers), len(remotedata), totalbytes)) |
2501 for key, data in remotedata: | 2506 for key, data in remotedata: |
2502 repo.ui.progress('OBSEXC', sentbytes, item=key, unit="bytes", | 2507 repo.ui.progress('OBSEXC', sentbytes, item=key, unit="bytes", |
2503 total=totalbytes) | 2508 total=totalbytes) |
2504 rslts.append(remote.pushkey('obsolete', key, '', data)) | 2509 rslts.append(remote.pushkey('obsolete', key, '', data)) |
2505 sentbytes += len(data) | 2510 sentbytes += len(data) |
2507 total=totalbytes) | 2512 total=totalbytes) |
2508 repo.ui.progress('OBSEXC', None) | 2513 repo.ui.progress('OBSEXC', None) |
2509 if [r for r in rslts if not r]: | 2514 if [r for r in rslts if not r]: |
2510 msg = _('failed to push some obsolete markers!\n') | 2515 msg = _('failed to push some obsolete markers!\n') |
2511 repo.ui.warn(msg) | 2516 repo.ui.warn(msg) |
2512 repo.ui.status("OBSEXC: DONE\n") | 2517 obsexcmsg(repo.ui, "DONE\n") |
2513 | 2518 |
2514 | 2519 |
2515 @eh.addattr(wireproto.wirepeer, 'evoext_pushobsmarkers_0') | 2520 @eh.addattr(wireproto.wirepeer, 'evoext_pushobsmarkers_0') |
2516 def client_pushobsmarkers(self, obsfile): | 2521 def client_pushobsmarkers(self, obsfile): |
2517 """wireprotocol peer method""" | 2522 """wireprotocol peer method""" |
2592 remote = pullop.remote | 2597 remote = pullop.remote |
2593 unfi = repo.unfiltered() | 2598 unfi = repo.unfiltered() |
2594 revs = unfi.revs('::%ln', pullop.pulledsubset) | 2599 revs = unfi.revs('::%ln', pullop.pulledsubset) |
2595 common = [nullid] | 2600 common = [nullid] |
2596 if remote.capable('_evoext_obshash_0'): | 2601 if remote.capable('_evoext_obshash_0'): |
2597 repo.ui.status("OBSEXC: looking for common markers in %i nodes\n" | 2602 obsexcmsg(repo.ui, "looking for common markers in %i nodes\n" |
2598 % len(revs)) | 2603 % len(revs)) |
2599 common = findcommonobsmarkers(repo.ui, repo, remote, revs) | 2604 common = findcommonobsmarkers(repo.ui, repo, remote, revs) |
2600 return {'heads': pullop.pulledsubset, 'common': common} | 2605 return {'heads': pullop.pulledsubset, 'common': common} |
2601 | 2606 |
2602 @eh.uisetup | 2607 @eh.uisetup |
2603 def addgetbundleargs(self): | 2608 def addgetbundleargs(self): |
2638 return orig(pullop) | 2643 return orig(pullop) |
2639 if 'obsolete' not in pullop.remote.listkeys('namespaces'): | 2644 if 'obsolete' not in pullop.remote.listkeys('namespaces'): |
2640 return None # remote opted out of obsolescence marker exchange | 2645 return None # remote opted out of obsolescence marker exchange |
2641 tr = None | 2646 tr = None |
2642 ui = pullop.repo.ui | 2647 ui = pullop.repo.ui |
2643 ui.status("OBSEXC: pull obsolescence markers\n") | 2648 obsexcmsg(ui, "pull obsolescence markers\n") |
2644 boundaries = _buildpullobsmerkersboundaries(pullop) | 2649 boundaries = _buildpullobsmerkersboundaries(pullop) |
2645 new = 0 | 2650 new = 0 |
2646 | 2651 |
2647 if b2xpull: | 2652 if b2xpull: |
2648 kwargs = {'bundlecaps': set(['HG2X'])} | 2653 kwargs = {'bundlecaps': set(['HG2X'])} |
2661 bytes = new = 0 | 2666 bytes = new = 0 |
2662 for entry in op.records['evo_obsmarkers']: | 2667 for entry in op.records['evo_obsmarkers']: |
2663 bytes += entry.get('bytes', 0) | 2668 bytes += entry.get('bytes', 0) |
2664 new += entry.get('new', 0) | 2669 new += entry.get('new', 0) |
2665 if 5 < bytes: | 2670 if 5 < bytes: |
2666 ui.status("OBSEXC: merging obsolescence markers (%i bytes)\n" | 2671 obsexcmsg(ui, "merging obsolescence markers (%i bytes)\n" |
2667 % bytes) | 2672 % bytes) |
2668 ui.status("OBSEXC: %i markers added\n" % new) | 2673 obsexcmsg(ui, "%i markers added\n" % new) |
2669 tr = op.gettransaction() | 2674 tr = op.gettransaction() |
2670 else: | 2675 else: |
2671 ui.status("OBSEXC: no unknown remote markers\n") | 2676 obsexcmsg(ui, "no unknown remote markers\n") |
2672 ui.status("OBSEXC: DONE\n") | 2677 obsexcmsg(ui, "DONE\n") |
2673 elif wirepull: | 2678 elif wirepull: |
2674 obsdata = pullop.remote.evoext_pullobsmarkers_0(**boundaries) | 2679 obsdata = pullop.remote.evoext_pullobsmarkers_0(**boundaries) |
2675 obsdata = obsdata.read() | 2680 obsdata = obsdata.read() |
2676 if len(obsdata) > 5: | 2681 if len(obsdata) > 5: |
2677 ui.status("OBSEXC: merging obsolescence markers (%i bytes)\n" | 2682 obsexcmsg(ui, "merging obsolescence markers (%i bytes)\n" |
2678 % len(obsdata)) | 2683 % len(obsdata)) |
2679 tr = pullop.gettransaction() | 2684 tr = pullop.gettransaction() |
2680 old = len(pullop.repo.obsstore._all) | 2685 old = len(pullop.repo.obsstore._all) |
2681 pullop.repo.obsstore.mergemarkers(tr, obsdata) | 2686 pullop.repo.obsstore.mergemarkers(tr, obsdata) |
2682 new = len(pullop.repo.obsstore._all) - old | 2687 new = len(pullop.repo.obsstore._all) - old |
2683 ui.status("OBSEXC: %i markers added\n" % new) | 2688 obsexcmsg(ui, "%i markers added\n" % new) |
2684 else: | 2689 else: |
2685 ui.status("OBSEXC: no unknown remote markers\n") | 2690 obsexcmsg(ui, "no unknown remote markers\n") |
2686 ui.status("OBSEXC: DONE\n") | 2691 obsexcmsg(ui, "DONE\n") |
2687 if new: | 2692 if new: |
2688 pullop.repo.invalidatevolatilesets() | 2693 pullop.repo.invalidatevolatilesets() |
2689 return tr | 2694 return tr |
2690 | 2695 |
2691 def _getobsmarkersstream(repo, heads=None, common=None): | 2696 def _getobsmarkersstream(repo, heads=None, common=None): |