Mercurial > hg
comparison mercurial/bundle2.py @ 32930:af31d531dda0
changegroup: let callers pass in transaction to apply() (API)
I think passing in the transaction makes it a little clearer and more
consistent with bundle2.
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 15 Jun 2017 22:46:38 -0700 |
parents | a7851519ea02 |
children | 560ceb654180 |
comparison
equal
deleted
inserted
replaced
32929:d11e2343762b | 32930:af31d531dda0 |
---|---|
1472 """apply a changegroup part on the repo | 1472 """apply a changegroup part on the repo |
1473 | 1473 |
1474 This is a very early implementation that will massive rework before being | 1474 This is a very early implementation that will massive rework before being |
1475 inflicted to any end-user. | 1475 inflicted to any end-user. |
1476 """ | 1476 """ |
1477 # Make sure we trigger a transaction creation | 1477 tr = op.gettransaction() |
1478 # | |
1479 # The addchangegroup function will get a transaction object by itself, but | |
1480 # we need to make sure we trigger the creation of a transaction object used | |
1481 # for the whole processing scope. | |
1482 op.gettransaction() | |
1483 unpackerversion = inpart.params.get('version', '01') | 1478 unpackerversion = inpart.params.get('version', '01') |
1484 # We should raise an appropriate exception here | 1479 # We should raise an appropriate exception here |
1485 cg = changegroup.getunbundler(unpackerversion, inpart, None) | 1480 cg = changegroup.getunbundler(unpackerversion, inpart, None) |
1486 # the source and url passed here are overwritten by the one contained in | 1481 # the source and url passed here are overwritten by the one contained in |
1487 # the transaction.hookargs argument. So 'bundle2' is a placeholder | 1482 # the transaction.hookargs argument. So 'bundle2' is a placeholder |
1495 "bundle contains tree manifests, but local repo is " | 1490 "bundle contains tree manifests, but local repo is " |
1496 "non-empty and does not use tree manifests")) | 1491 "non-empty and does not use tree manifests")) |
1497 op.repo.requirements.add('treemanifest') | 1492 op.repo.requirements.add('treemanifest') |
1498 op.repo._applyopenerreqs() | 1493 op.repo._applyopenerreqs() |
1499 op.repo._writerequirements() | 1494 op.repo._writerequirements() |
1500 ret = cg.apply(op.repo, 'bundle2', 'bundle2', expectedtotal=nbchangesets) | 1495 ret = cg.apply(op.repo, tr, 'bundle2', 'bundle2', |
1496 expectedtotal=nbchangesets) | |
1501 op.records.add('changegroup', {'return': ret}) | 1497 op.records.add('changegroup', {'return': ret}) |
1502 if op.reply is not None: | 1498 if op.reply is not None: |
1503 # This is definitely not the final form of this | 1499 # This is definitely not the final form of this |
1504 # return. But one need to start somewhere. | 1500 # return. But one need to start somewhere. |
1505 part = op.reply.newpart('reply:changegroup', mandatory=False) | 1501 part = op.reply.newpart('reply:changegroup', mandatory=False) |
1553 param) | 1549 param) |
1554 digests[typ] = value | 1550 digests[typ] = value |
1555 | 1551 |
1556 real_part = util.digestchecker(url.open(op.ui, raw_url), size, digests) | 1552 real_part = util.digestchecker(url.open(op.ui, raw_url), size, digests) |
1557 | 1553 |
1558 # Make sure we trigger a transaction creation | 1554 tr = op.gettransaction() |
1559 # | |
1560 # The addchangegroup function will get a transaction object by itself, but | |
1561 # we need to make sure we trigger the creation of a transaction object used | |
1562 # for the whole processing scope. | |
1563 op.gettransaction() | |
1564 from . import exchange | 1555 from . import exchange |
1565 cg = exchange.readbundle(op.repo.ui, real_part, raw_url) | 1556 cg = exchange.readbundle(op.repo.ui, real_part, raw_url) |
1566 if not isinstance(cg, changegroup.cg1unpacker): | 1557 if not isinstance(cg, changegroup.cg1unpacker): |
1567 raise error.Abort(_('%s: not a bundle version 1.0') % | 1558 raise error.Abort(_('%s: not a bundle version 1.0') % |
1568 util.hidepassword(raw_url)) | 1559 util.hidepassword(raw_url)) |
1569 ret = cg.apply(op.repo, 'bundle2', 'bundle2') | 1560 ret = cg.apply(op.repo, tr, 'bundle2', 'bundle2') |
1570 op.records.add('changegroup', {'return': ret}) | 1561 op.records.add('changegroup', {'return': ret}) |
1571 if op.reply is not None: | 1562 if op.reply is not None: |
1572 # This is definitely not the final form of this | 1563 # This is definitely not the final form of this |
1573 # return. But one need to start somewhere. | 1564 # return. But one need to start somewhere. |
1574 part = op.reply.newpart('reply:changegroup') | 1565 part = op.reply.newpart('reply:changegroup') |