comparison hgext/evolve.py @ 1314:d13d97363521

evolve: refactoring of code related to pushing obs markers This removes duplicated code for the pushobsmarkers logic
author Laurent Charignon <lcharignon@fb.com>
date Thu, 30 Apr 2015 14:55:04 -0700
parents 31e96036acd3
children 445d7f46f25d
comparison
equal deleted inserted replaced
1313:31e96036acd3 1314:d13d97363521
2672 def local_pushobsmarker_capabilities(orig, repo, caps): 2672 def local_pushobsmarker_capabilities(orig, repo, caps):
2673 caps = orig(repo, caps) 2673 caps = orig(repo, caps)
2674 caps.add('_evoext_pushobsmarkers_0') 2674 caps.add('_evoext_pushobsmarkers_0')
2675 return caps 2675 return caps
2676 2676
2677 @eh.addattr(localrepo.localpeer, 'evoext_pushobsmarkers_0') 2677 def _pushobsmarkers(repo, data):
2678 def local_pushobsmarkers(peer, obsfile):
2679 data = obsfile.read()
2680 tr = lock = None
2681 try:
2682 lock = peer._repo.lock()
2683 tr = peer._repo.transaction('pushkey: obsolete markers')
2684 new = peer._repo.obsstore.mergemarkers(tr, data)
2685 if new is not None:
2686 obsexcmsg(peer._repo.ui, "%i obsolescence markers added\n" % new, True)
2687 tr.close()
2688 finally:
2689 lockmod.release(tr, lock)
2690 peer._repo.hook('evolve_pushobsmarkers')
2691
2692 def srv_pushobsmarkers(repo, proto):
2693 """wireprotocol command"""
2694 fp = StringIO()
2695 proto.redirect()
2696 proto.getfile(fp)
2697 data = fp.getvalue()
2698 fp.close()
2699 tr = lock = None 2678 tr = lock = None
2700 try: 2679 try:
2701 lock = repo.lock() 2680 lock = repo.lock()
2702 tr = repo.transaction('pushkey: obsolete markers') 2681 tr = repo.transaction('pushkey: obsolete markers')
2703 new = repo.obsstore.mergemarkers(tr, data) 2682 new = repo.obsstore.mergemarkers(tr, data)
2705 obsexcmsg(repo.ui, "%i obsolescence markers added\n" % new, True) 2684 obsexcmsg(repo.ui, "%i obsolescence markers added\n" % new, True)
2706 tr.close() 2685 tr.close()
2707 finally: 2686 finally:
2708 lockmod.release(tr, lock) 2687 lockmod.release(tr, lock)
2709 repo.hook('evolve_pushobsmarkers') 2688 repo.hook('evolve_pushobsmarkers')
2689
2690 @eh.addattr(localrepo.localpeer, 'evoext_pushobsmarkers_0')
2691 def local_pushobsmarkers(peer, obsfile):
2692 data = obsfile.read()
2693 _pushobsmarkers(peer._repo, data)
2694
2695 def srv_pushobsmarkers(repo, proto):
2696 """wireprotocol command"""
2697 fp = StringIO()
2698 proto.redirect()
2699 proto.getfile(fp)
2700 data = fp.getvalue()
2701 fp.close()
2702 _pushobsmarkers(repo, data)
2710 return wireproto.pushres(0) 2703 return wireproto.pushres(0)
2711 2704
2712 def _buildpullobsmarkersboundaries(pullop): 2705 def _buildpullobsmarkersboundaries(pullop):
2713 """small funtion returning the argument for pull markers call 2706 """small funtion returning the argument for pull markers call
2714 may to contains 'heads' and 'common'. skip the key for None. 2707 may to contains 'heads' and 'common'. skip the key for None.