Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 32862:76bb53f8d374
unbundle: use context manager for transaction
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 15 Jun 2017 14:47:18 -0700 |
parents | cb48dfd9672d |
children | 0d98b11b8467 |
comparison
equal
deleted
inserted
replaced
32861:a470bbb4e3af | 32862:76bb53f8d374 |
---|---|
5315 with repo.lock(): | 5315 with repo.lock(): |
5316 for fname in fnames: | 5316 for fname in fnames: |
5317 f = hg.openpath(ui, fname) | 5317 f = hg.openpath(ui, fname) |
5318 gen = exchange.readbundle(ui, f, fname) | 5318 gen = exchange.readbundle(ui, f, fname) |
5319 if isinstance(gen, bundle2.unbundle20): | 5319 if isinstance(gen, bundle2.unbundle20): |
5320 tr = repo.transaction('unbundle') | 5320 with repo.transaction('unbundle') as tr: |
5321 try: | 5321 try: |
5322 op = bundle2.applybundle(repo, gen, tr, source='unbundle', | 5322 op = bundle2.applybundle(repo, gen, tr, |
5323 url='bundle:' + fname) | 5323 source='unbundle', |
5324 tr.close() | 5324 url='bundle:' + fname) |
5325 except error.BundleUnknownFeatureError as exc: | 5325 except error.BundleUnknownFeatureError as exc: |
5326 raise error.Abort(_('%s: unknown bundle feature, %s') | 5326 raise error.Abort( |
5327 % (fname, exc), | 5327 _('%s: unknown bundle feature, %s') % (fname, exc), |
5328 hint=_("see https://mercurial-scm.org/" | 5328 hint=_("see https://mercurial-scm.org/" |
5329 "wiki/BundleFeature for more " | 5329 "wiki/BundleFeature for more " |
5330 "information")) | 5330 "information")) |
5331 finally: | |
5332 if tr: | |
5333 tr.release() | |
5334 changes = [r.get('return', 0) | 5331 changes = [r.get('return', 0) |
5335 for r in op.records['changegroup']] | 5332 for r in op.records['changegroup']] |
5336 modheads = changegroup.combineresults(changes) | 5333 modheads = changegroup.combineresults(changes) |
5337 elif isinstance(gen, streamclone.streamcloneapplier): | 5334 elif isinstance(gen, streamclone.streamcloneapplier): |
5338 raise error.Abort( | 5335 raise error.Abort( |