Mercurial > hg
comparison mercurial/bundle2.py @ 20952:b24ee5076b94
bundle2: make it possible have a global transaction for the unbundling
We use the `gettransaction` method approach already used for pull. We
need this because we do not know beforehand if the bundle needs a
transaction to be created. And (1) we do not want to create a
transaction for nothing. (2) Some bundle2 bundles may be read-only and
do not require any lock or transaction to be held.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Wed, 02 Apr 2014 23:56:49 -0700 |
parents | c7ceae0faf69 |
children | e995d104c87f |
comparison
equal
deleted
inserted
replaced
20951:f977c732bf34 | 20952:b24ee5076b94 |
---|---|
236 * a way to retrieve a transaction to add changes to the repo, | 236 * a way to retrieve a transaction to add changes to the repo, |
237 * a way to record the result of processing each part, | 237 * a way to record the result of processing each part, |
238 * a way to construct a bundle response when applicable. | 238 * a way to construct a bundle response when applicable. |
239 """ | 239 """ |
240 | 240 |
241 def __init__(self, repo): | 241 def __init__(self, repo, transactiongetter): |
242 self.repo = repo | 242 self.repo = repo |
243 self.ui = repo.ui | 243 self.ui = repo.ui |
244 self.records = unbundlerecords() | 244 self.records = unbundlerecords() |
245 | 245 self.gettransaction = transactiongetter |
246 def processbundle(repo, unbundler): | 246 |
247 class TransactionUnavailable(RuntimeError): | |
248 pass | |
249 | |
250 def _notransaction(): | |
251 """default method to get a transaction while processing a bundle | |
252 | |
253 Raise an exception to highlight the fact that no transaction was expected | |
254 to be created""" | |
255 raise TransactionUnavailable() | |
256 | |
257 def processbundle(repo, unbundler, transactiongetter=_notransaction): | |
247 """This function process a bundle, apply effect to/from a repo | 258 """This function process a bundle, apply effect to/from a repo |
248 | 259 |
249 It iterates over each part then searches for and uses the proper handling | 260 It iterates over each part then searches for and uses the proper handling |
250 code to process the part. Parts are processed in order. | 261 code to process the part. Parts are processed in order. |
251 | 262 |
252 This is very early version of this function that will be strongly reworked | 263 This is very early version of this function that will be strongly reworked |
253 before final usage. | 264 before final usage. |
254 | 265 |
255 Unknown Mandatory part will abort the process. | 266 Unknown Mandatory part will abort the process. |
256 """ | 267 """ |
257 op = bundleoperation(repo) | 268 op = bundleoperation(repo, transactiongetter) |
258 # todo: | 269 # todo: |
259 # - replace this is a init function soon. | 270 # - replace this is a init function soon. |
260 # - exception catching | 271 # - exception catching |
261 unbundler.params | 272 unbundler.params |
262 iterparts = iter(unbundler) | 273 iterparts = iter(unbundler) |
530 """apply a changegroup part on the repo | 541 """apply a changegroup part on the repo |
531 | 542 |
532 This is a very early implementation that will massive rework before being | 543 This is a very early implementation that will massive rework before being |
533 inflicted to any end-user. | 544 inflicted to any end-user. |
534 """ | 545 """ |
546 # Make sure we trigger a transaction creation | |
547 # | |
548 # The addchangegroup function will get a transaction object by itself, but | |
549 # we need to make sure we trigger the creation of a transaction object used | |
550 # for the whole processing scope. | |
551 op.gettransaction() | |
535 data = StringIO.StringIO(part.data) | 552 data = StringIO.StringIO(part.data) |
536 data.seek(0) | 553 data.seek(0) |
537 cg = changegroup.readbundle(data, 'bundle2part') | 554 cg = changegroup.readbundle(data, 'bundle2part') |
538 ret = changegroup.addchangegroup(op.repo, cg, 'bundle2', 'bundle2') | 555 ret = changegroup.addchangegroup(op.repo, cg, 'bundle2', 'bundle2') |
539 op.records.add('changegroup', {'return': ret}) | 556 op.records.add('changegroup', {'return': ret}) |