comparison mercurial/bundle2.py @ 20890:ec7fc110faee

bundle2: introduce a `parthandler` decorator Simple syntax sugar to register an handler for a new part type.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Mon, 24 Mar 2014 15:51:00 -0700
parents deed5edb72de
children 1c6cd23fc221
comparison
equal deleted inserted replaced
20889:deed5edb72de 20890:ec7fc110faee
146 The number parameters is variable so we need to build that format 146 The number parameters is variable so we need to build that format
147 dynamically. 147 dynamically.
148 """ 148 """
149 return '>'+('BB'*nbparams) 149 return '>'+('BB'*nbparams)
150 150
151
152 parthandlermapping = {} 151 parthandlermapping = {}
152
153 def parthandler(parttype):
154 """decorator that register a function as a bundle2 part handler
155
156 eg::
157
158 @parthandler('myparttype')
159 def myparttypehandler(...):
160 '''process a part of type "my part".'''
161 ...
162 """
163 def _decorator(func):
164 assert parttype not in parthandlermapping
165 parthandlermapping[parttype] = func
166 return func
167 return _decorator
153 168
154 def processbundle(repo, stream): 169 def processbundle(repo, stream):
155 """This function process a bundle, apply effect to/from a repo 170 """This function process a bundle, apply effect to/from a repo
156 171
157 Currently it: 172 Currently it: