comparison mercurial/exchange.py @ 22936:dae236906fb2

pull: make discovery phase extensible We apply the same approach as for push and make the discovery extensible. There is only one user in core right now, but we already know we'll need something smarter for obsmarkers. In fact the evolve extension could use this to cleanly extend discovery. The main motivation for this change is consistency between push and pull.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Sat, 27 Sep 2014 00:29:06 -0700
parents 68439b154063
children 92bf9abc4deb
comparison
equal deleted inserted replaced
22935:ee297602a208 22936:dae236906fb2
866 pullop.releasetransaction() 866 pullop.releasetransaction()
867 lock.release() 867 lock.release()
868 868
869 return pullop 869 return pullop
870 870
871 # list of steps to perform discovery before pull
872 pulldiscoveryorder = []
873
874 # Mapping between step name and function
875 #
876 # This exists to help extensions wrap steps if necessary
877 pulldiscoverymapping = {}
878
879 def pulldiscovery(stepname):
880 """decorator for function performing discovery before pull
881
882 The function is added to the step -> function mapping and appended to the
883 list of steps. Beware that decorated function will be added in order (this
884 may matter).
885
886 You can only use this decorator for a new step, if you want to wrap a step
887 from an extension, change the pulldiscovery dictionary directly."""
888 def dec(func):
889 assert stepname not in pulldiscoverymapping
890 pulldiscoverymapping[stepname] = func
891 pulldiscoveryorder.append(stepname)
892 return func
893 return dec
894
871 def _pulldiscovery(pullop): 895 def _pulldiscovery(pullop):
896 """Run all discovery steps"""
897 for stepname in pulldiscoveryorder:
898 step = pulldiscoverymapping[stepname]
899 step(pullop)
900
901 @pulldiscovery('changegroup')
902 def _pulldiscoverychangegroup(pullop):
872 """discovery phase for the pull 903 """discovery phase for the pull
873 904
874 Current handle changeset discovery only, will change handle all discovery 905 Current handle changeset discovery only, will change handle all discovery
875 at some point.""" 906 at some point."""
876 tmp = discovery.findcommonincoming(pullop.repo.unfiltered(), 907 tmp = discovery.findcommonincoming(pullop.repo.unfiltered(),