diff --git a/mercurial/commands.py b/mercurial/commands.py
index febd6bfa770dc4a09af8302e7fcde74f139fe498_bWVyY3VyaWFsL2NvbW1hbmRzLnB5..ac986751910396de9818cf981b35f131a5ab1634_bWVyY3VyaWFsL2NvbW1hbmRzLnB5 100644
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5321,8 +5321,9 @@
                         _('packed bundles cannot be applied with '
                           '"hg unbundle"'),
                         hint=_('use "hg debugapplystreamclonebundle"'))
+            url = 'bundle:' + fname
             if isinstance(gen, bundle2.unbundle20):
                 with repo.transaction('unbundle') as tr:
                     try:
                         op = bundle2.applybundle(repo, gen, tr,
                                                  source='unbundle',
@@ -5324,9 +5325,9 @@
             if isinstance(gen, bundle2.unbundle20):
                 with repo.transaction('unbundle') as tr:
                     try:
                         op = bundle2.applybundle(repo, gen, tr,
                                                  source='unbundle',
-                                                 url='bundle:' + fname)
+                                                 url=url)
                     except error.BundleUnknownFeatureError as exc:
                         raise error.Abort(
                             _('%s: unknown bundle feature, %s') % (fname, exc),
@@ -5337,7 +5338,9 @@
                            for r in op.records['changegroup']]
                 modheads = changegroup.combineresults(changes)
             else:
-                modheads = gen.apply(repo, 'unbundle', 'bundle:' + fname)
+                txnname = 'unbundle\n%s' % util.hidepassword(url)
+                with repo.transaction(txnname):
+                    modheads = gen.apply(repo, 'unbundle', url)
 
     return postincoming(ui, repo, modheads, opts.get(r'update'), None, None)