Mercurial > public > mercurial-scm > hg
comparison mercurial/bundle2.py @ 20948:329cd74b52bd
bundle2: introduce a bundleoperation object
This object will hold all data and state gathered through the processing of a
bundle. This will allow:
- each handler to be aware of the things unbundled so far
- the caller to retrieve data about the execution
- bear useful object and logic (like repo, transaction)
- bear possible bundle2 reply triggered by the unbundling.
For now the object is very simple but it will grow at the same time as the
bundle2 implementation.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Wed, 02 Apr 2014 22:24:44 -0700 |
parents | c33d7bf53812 |
children | 571f2903ff1e |
comparison
equal
deleted
inserted
replaced
20947:c33d7bf53812 | 20948:329cd74b52bd |
---|---|
181 assert lparttype not in parthandlermapping | 181 assert lparttype not in parthandlermapping |
182 parthandlermapping[lparttype] = func | 182 parthandlermapping[lparttype] = func |
183 return func | 183 return func |
184 return _decorator | 184 return _decorator |
185 | 185 |
186 class bundleoperation(object): | |
187 """an object that represents a single bundling process | |
188 | |
189 Its purpose is to carry unbundle-related objects and states. | |
190 | |
191 A new object should be created at the beginning of each bundle processing. | |
192 The object is to be returned by the processing function. | |
193 | |
194 The object has very little content now it will ultimately contain: | |
195 * an access to the repo the bundle is applied to, | |
196 * a ui object, | |
197 * a way to retrieve a transaction to add changes to the repo, | |
198 * a way to record the result of processing each part, | |
199 * a way to construct a bundle response when applicable. | |
200 """ | |
201 | |
202 def __init__(self, repo): | |
203 self.repo = repo | |
204 self.ui = repo.ui | |
205 | |
186 def processbundle(repo, unbundler): | 206 def processbundle(repo, unbundler): |
187 """This function process a bundle, apply effect to/from a repo | 207 """This function process a bundle, apply effect to/from a repo |
188 | 208 |
189 It iterates over each part then searches for and uses the proper handling | 209 It iterates over each part then searches for and uses the proper handling |
190 code to process the part. Parts are processed in order. | 210 code to process the part. Parts are processed in order. |
192 This is very early version of this function that will be strongly reworked | 212 This is very early version of this function that will be strongly reworked |
193 before final usage. | 213 before final usage. |
194 | 214 |
195 Unknown Mandatory part will abort the process. | 215 Unknown Mandatory part will abort the process. |
196 """ | 216 """ |
197 ui = repo.ui | 217 op = bundleoperation(repo) |
198 # todo: | 218 # todo: |
199 # - replace this is a init function soon. | 219 # - replace this is a init function soon. |
200 # - exception catching | 220 # - exception catching |
201 unbundler.params | 221 unbundler.params |
202 iterparts = iter(unbundler) | 222 iterparts = iter(unbundler) |
205 parttype = part.type | 225 parttype = part.type |
206 # part key are matched lower case | 226 # part key are matched lower case |
207 key = parttype.lower() | 227 key = parttype.lower() |
208 try: | 228 try: |
209 handler = parthandlermapping[key] | 229 handler = parthandlermapping[key] |
210 ui.debug('found an handler for part %r\n' % parttype) | 230 op.ui.debug('found a handler for part %r\n' % parttype) |
211 except KeyError: | 231 except KeyError: |
212 if key != parttype: # mandatory parts | 232 if key != parttype: # mandatory parts |
213 # todo: | 233 # todo: |
214 # - use a more precise exception | 234 # - use a more precise exception |
215 raise | 235 raise |
216 ui.debug('ignoring unknown advisory part %r\n' % key) | 236 op.ui.debug('ignoring unknown advisory part %r\n' % key) |
217 # todo: | 237 # todo: |
218 # - consume the part once we use streaming | 238 # - consume the part once we use streaming |
219 continue | 239 continue |
220 handler(repo, part) | 240 handler(op, part) |
221 except Exception: | 241 except Exception: |
222 for part in iterparts: | 242 for part in iterparts: |
223 pass # consume the bundle content | 243 pass # consume the bundle content |
224 raise | 244 raise |
225 | 245 |