diff --git a/hgext/histedit.py b/hgext/histedit.py --- a/hgext/histedit.py +++ b/hgext/histedit.py @@ -1199,7 +1199,7 @@ def _aborthistedit(ui, repo, state): gen = exchange.readbundle(ui, f, backupfile) with repo.transaction('histedit.abort') as tr: if not isinstance(gen, bundle2.unbundle20): - gen.apply(repo, 'histedit', 'bundle:' + backupfile) + gen.apply(repo, tr, 'histedit', 'bundle:' + backupfile) else: bundle2.applybundle(repo, gen, tr, source='histedit', diff --git a/hgext/shelve.py b/hgext/shelve.py --- a/hgext/shelve.py +++ b/hgext/shelve.py @@ -127,7 +127,7 @@ class shelvedfile(object): try: gen = exchange.readbundle(self.repo.ui, fp, self.fname, self.vfs) if not isinstance(gen, bundle2.unbundle20): - gen.apply(self.repo, 'unshelve', + gen.apply(self.repo, self.repo.currenttransaction(), 'unshelve', 'bundle:' + self.vfs.join(self.fname), targetphase=phases.secret) else: diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py --- a/mercurial/bundle2.py +++ b/mercurial/bundle2.py @@ -1474,12 +1474,7 @@ def handlechangegroup(op, inpart): This is a very early implementation that will massive rework before being inflicted to any end-user. """ - # Make sure we trigger a transaction creation - # - # The addchangegroup function will get a transaction object by itself, but - # we need to make sure we trigger the creation of a transaction object used - # for the whole processing scope. - op.gettransaction() + tr = op.gettransaction() unpackerversion = inpart.params.get('version', '01') # We should raise an appropriate exception here cg = changegroup.getunbundler(unpackerversion, inpart, None) @@ -1497,7 +1492,8 @@ def handlechangegroup(op, inpart): op.repo.requirements.add('treemanifest') op.repo._applyopenerreqs() op.repo._writerequirements() - ret = cg.apply(op.repo, 'bundle2', 'bundle2', expectedtotal=nbchangesets) + ret = cg.apply(op.repo, tr, 'bundle2', 'bundle2', + expectedtotal=nbchangesets) op.records.add('changegroup', {'return': ret}) if op.reply is not None: # This is definitely not the final form of this @@ -1555,18 +1551,13 @@ def handleremotechangegroup(op, inpart): real_part = util.digestchecker(url.open(op.ui, raw_url), size, digests) - # Make sure we trigger a transaction creation - # - # The addchangegroup function will get a transaction object by itself, but - # we need to make sure we trigger the creation of a transaction object used - # for the whole processing scope. - op.gettransaction() + tr = op.gettransaction() from . import exchange cg = exchange.readbundle(op.repo.ui, real_part, raw_url) if not isinstance(cg, changegroup.cg1unpacker): raise error.Abort(_('%s: not a bundle version 1.0') % util.hidepassword(raw_url)) - ret = cg.apply(op.repo, 'bundle2', 'bundle2') + ret = cg.apply(op.repo, tr, 'bundle2', 'bundle2') op.records.add('changegroup', {'return': ret}) if op.reply is not None: # This is definitely not the final form of this diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py --- a/mercurial/changegroup.py +++ b/mercurial/changegroup.py @@ -256,7 +256,7 @@ class cg1unpacker(object): repo.ui.progress(_('manifests'), None) self.callback = None - def apply(self, repo, srctype, url, emptyok=False, + def apply(self, repo, tr, srctype, url, emptyok=False, targetphase=phases.draft, expectedtotal=None): """Add the changegroup returned by source.read() to this repo. srctype is a string like 'push', 'pull', or 'unbundle'. url is @@ -279,12 +279,11 @@ class cg1unpacker(object): changesets = files = revisions = 0 try: - with repo.transaction("\n".join([srctype, - util.hidepassword(url)])) as tr: - # The transaction could have been created before and already - # carries source information. In this case we use the top - # level data. We overwrite the argument because we need to use - # the top level value (if they exist) in this function. + if True: + # The transaction may already carry source information. In this + # case we use the top level data. We overwrite the argument + # because we need to use the top level value (if they exist) + # in this function. srctype = tr.hookargs.setdefault('source', srctype) url = tr.hookargs.setdefault('url', url) repo.hook('prechangegroup', throw=True, **tr.hookargs) diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -5339,8 +5339,8 @@ def unbundle(ui, repo, fname1, *fnames, modheads = changegroup.combineresults(changes) else: txnname = 'unbundle\n%s' % util.hidepassword(url) - with repo.transaction(txnname): - modheads = gen.apply(repo, 'unbundle', url) + with repo.transaction(txnname) as tr: + modheads = gen.apply(repo, tr, 'unbundle', url) return postincoming(ui, repo, modheads, opts.get(r'update'), None, None) diff --git a/mercurial/exchange.py b/mercurial/exchange.py --- a/mercurial/exchange.py +++ b/mercurial/exchange.py @@ -1430,7 +1430,7 @@ def _pullchangeset(pullop): pullop.repo.ui.status(_("no changes found\n")) pullop.cgresult = 0 return - pullop.gettransaction() + tr = pullop.gettransaction() if pullop.heads is None and list(pullop.common) == [nullid]: pullop.repo.ui.status(_("requesting all changes\n")) elif pullop.heads is None and pullop.remote.capable('changegroupsubset'): @@ -1449,7 +1449,7 @@ def _pullchangeset(pullop): "changegroupsubset.")) else: cg = pullop.remote.changegroupsubset(pullop.fetch, pullop.heads, 'pull') - pullop.cgresult = cg.apply(pullop.repo, 'pull', pullop.remote.url()) + pullop.cgresult = cg.apply(pullop.repo, tr, 'pull', pullop.remote.url()) def _pullphase(pullop): # Get remote phases data from remote @@ -1735,8 +1735,8 @@ def unbundle(repo, cg, heads, source, ur if not isinstance(cg, bundle2.unbundle20): # legacy case: bundle1 (changegroup 01) txnname = "\n".join([source, util.hidepassword(url)]) - with repo.lock(), repo.transaction(txnname): - r = cg.apply(repo, source, url) + with repo.lock(), repo.transaction(txnname) as tr: + r = cg.apply(repo, tr, source, url) else: r = None try: @@ -2001,7 +2001,7 @@ def trypullbundlefromurl(ui, repo, url): elif isinstance(cg, streamclone.streamcloneapplier): cg.apply(repo) else: - cg.apply(repo, 'clonebundles', url) + cg.apply(repo, tr, 'clonebundles', url) return True except urlerr.httperror as e: ui.warn(_('HTTP error fetching bundle: %s\n') % str(e)) diff --git a/mercurial/repair.py b/mercurial/repair.py --- a/mercurial/repair.py +++ b/mercurial/repair.py @@ -208,8 +208,8 @@ def strip(ui, repo, nodelist, backup=Tru url=tmpbundleurl) else: txnname = "strip\n%s" % util.hidepassword(tmpbundleurl) - with repo.transaction(txnname): - gen.apply(repo, 'strip', tmpbundleurl, True) + with repo.transaction(txnname) as tr: + gen.apply(repo, tr, 'strip', tmpbundleurl, True) if not repo.ui.verbose: repo.ui.popbuffer() f.close()