##// END OF EJS Templates
changegroup: let callers pass in transaction to apply() (API)...
Martin von Zweigbergk -
r32930:af31d531 default
parent child Browse files
Show More
@@ -1199,7 +1199,7 b' def _aborthistedit(ui, repo, state):'
1199 gen = exchange.readbundle(ui, f, backupfile)
1199 gen = exchange.readbundle(ui, f, backupfile)
1200 with repo.transaction('histedit.abort') as tr:
1200 with repo.transaction('histedit.abort') as tr:
1201 if not isinstance(gen, bundle2.unbundle20):
1201 if not isinstance(gen, bundle2.unbundle20):
1202 gen.apply(repo, 'histedit', 'bundle:' + backupfile)
1202 gen.apply(repo, tr, 'histedit', 'bundle:' + backupfile)
1203 else:
1203 else:
1204 bundle2.applybundle(repo, gen, tr,
1204 bundle2.applybundle(repo, gen, tr,
1205 source='histedit',
1205 source='histedit',
@@ -127,7 +127,7 b' class shelvedfile(object):'
127 try:
127 try:
128 gen = exchange.readbundle(self.repo.ui, fp, self.fname, self.vfs)
128 gen = exchange.readbundle(self.repo.ui, fp, self.fname, self.vfs)
129 if not isinstance(gen, bundle2.unbundle20):
129 if not isinstance(gen, bundle2.unbundle20):
130 gen.apply(self.repo, 'unshelve',
130 gen.apply(self.repo, self.repo.currenttransaction(), 'unshelve',
131 'bundle:' + self.vfs.join(self.fname),
131 'bundle:' + self.vfs.join(self.fname),
132 targetphase=phases.secret)
132 targetphase=phases.secret)
133 else:
133 else:
@@ -1474,12 +1474,7 b' def handlechangegroup(op, inpart):'
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)
@@ -1497,7 +1492,8 b' def handlechangegroup(op, inpart):'
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
@@ -1555,18 +1551,13 b' def handleremotechangegroup(op, inpart):'
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
@@ -256,7 +256,7 b' class cg1unpacker(object):'
256 repo.ui.progress(_('manifests'), None)
256 repo.ui.progress(_('manifests'), None)
257 self.callback = None
257 self.callback = None
258
258
259 def apply(self, repo, srctype, url, emptyok=False,
259 def apply(self, repo, tr, srctype, url, emptyok=False,
260 targetphase=phases.draft, expectedtotal=None):
260 targetphase=phases.draft, expectedtotal=None):
261 """Add the changegroup returned by source.read() to this repo.
261 """Add the changegroup returned by source.read() to this repo.
262 srctype is a string like 'push', 'pull', or 'unbundle'. url is
262 srctype is a string like 'push', 'pull', or 'unbundle'. url is
@@ -279,12 +279,11 b' class cg1unpacker(object):'
279 changesets = files = revisions = 0
279 changesets = files = revisions = 0
280
280
281 try:
281 try:
282 with repo.transaction("\n".join([srctype,
282 if True:
283 util.hidepassword(url)])) as tr:
283 # The transaction may already carry source information. In this
284 # The transaction could have been created before and already
284 # case we use the top level data. We overwrite the argument
285 # carries source information. In this case we use the top
285 # because we need to use the top level value (if they exist)
286 # level data. We overwrite the argument because we need to use
286 # in this function.
287 # the top level value (if they exist) in this function.
288 srctype = tr.hookargs.setdefault('source', srctype)
287 srctype = tr.hookargs.setdefault('source', srctype)
289 url = tr.hookargs.setdefault('url', url)
288 url = tr.hookargs.setdefault('url', url)
290 repo.hook('prechangegroup', throw=True, **tr.hookargs)
289 repo.hook('prechangegroup', throw=True, **tr.hookargs)
@@ -5339,8 +5339,8 b' def unbundle(ui, repo, fname1, *fnames, '
5339 modheads = changegroup.combineresults(changes)
5339 modheads = changegroup.combineresults(changes)
5340 else:
5340 else:
5341 txnname = 'unbundle\n%s' % util.hidepassword(url)
5341 txnname = 'unbundle\n%s' % util.hidepassword(url)
5342 with repo.transaction(txnname):
5342 with repo.transaction(txnname) as tr:
5343 modheads = gen.apply(repo, 'unbundle', url)
5343 modheads = gen.apply(repo, tr, 'unbundle', url)
5344
5344
5345 return postincoming(ui, repo, modheads, opts.get(r'update'), None, None)
5345 return postincoming(ui, repo, modheads, opts.get(r'update'), None, None)
5346
5346
@@ -1430,7 +1430,7 b' def _pullchangeset(pullop):'
1430 pullop.repo.ui.status(_("no changes found\n"))
1430 pullop.repo.ui.status(_("no changes found\n"))
1431 pullop.cgresult = 0
1431 pullop.cgresult = 0
1432 return
1432 return
1433 pullop.gettransaction()
1433 tr = pullop.gettransaction()
1434 if pullop.heads is None and list(pullop.common) == [nullid]:
1434 if pullop.heads is None and list(pullop.common) == [nullid]:
1435 pullop.repo.ui.status(_("requesting all changes\n"))
1435 pullop.repo.ui.status(_("requesting all changes\n"))
1436 elif pullop.heads is None and pullop.remote.capable('changegroupsubset'):
1436 elif pullop.heads is None and pullop.remote.capable('changegroupsubset'):
@@ -1449,7 +1449,7 b' def _pullchangeset(pullop):'
1449 "changegroupsubset."))
1449 "changegroupsubset."))
1450 else:
1450 else:
1451 cg = pullop.remote.changegroupsubset(pullop.fetch, pullop.heads, 'pull')
1451 cg = pullop.remote.changegroupsubset(pullop.fetch, pullop.heads, 'pull')
1452 pullop.cgresult = cg.apply(pullop.repo, 'pull', pullop.remote.url())
1452 pullop.cgresult = cg.apply(pullop.repo, tr, 'pull', pullop.remote.url())
1453
1453
1454 def _pullphase(pullop):
1454 def _pullphase(pullop):
1455 # Get remote phases data from remote
1455 # Get remote phases data from remote
@@ -1735,8 +1735,8 b' def unbundle(repo, cg, heads, source, ur'
1735 if not isinstance(cg, bundle2.unbundle20):
1735 if not isinstance(cg, bundle2.unbundle20):
1736 # legacy case: bundle1 (changegroup 01)
1736 # legacy case: bundle1 (changegroup 01)
1737 txnname = "\n".join([source, util.hidepassword(url)])
1737 txnname = "\n".join([source, util.hidepassword(url)])
1738 with repo.lock(), repo.transaction(txnname):
1738 with repo.lock(), repo.transaction(txnname) as tr:
1739 r = cg.apply(repo, source, url)
1739 r = cg.apply(repo, tr, source, url)
1740 else:
1740 else:
1741 r = None
1741 r = None
1742 try:
1742 try:
@@ -2001,7 +2001,7 b' def trypullbundlefromurl(ui, repo, url):'
2001 elif isinstance(cg, streamclone.streamcloneapplier):
2001 elif isinstance(cg, streamclone.streamcloneapplier):
2002 cg.apply(repo)
2002 cg.apply(repo)
2003 else:
2003 else:
2004 cg.apply(repo, 'clonebundles', url)
2004 cg.apply(repo, tr, 'clonebundles', url)
2005 return True
2005 return True
2006 except urlerr.httperror as e:
2006 except urlerr.httperror as e:
2007 ui.warn(_('HTTP error fetching bundle: %s\n') % str(e))
2007 ui.warn(_('HTTP error fetching bundle: %s\n') % str(e))
@@ -208,8 +208,8 b' def strip(ui, repo, nodelist, backup=Tru'
208 url=tmpbundleurl)
208 url=tmpbundleurl)
209 else:
209 else:
210 txnname = "strip\n%s" % util.hidepassword(tmpbundleurl)
210 txnname = "strip\n%s" % util.hidepassword(tmpbundleurl)
211 with repo.transaction(txnname):
211 with repo.transaction(txnname) as tr:
212 gen.apply(repo, 'strip', tmpbundleurl, True)
212 gen.apply(repo, tr, 'strip', tmpbundleurl, True)
213 if not repo.ui.verbose:
213 if not repo.ui.verbose:
214 repo.ui.popbuffer()
214 repo.ui.popbuffer()
215 f.close()
215 f.close()
General Comments 0
You need to be logged in to leave comments. Login now