From 8bfeb98530e87a969dd2c1d9f148debd34861c02 Mon Sep 17 00:00:00 2001 From: Bryan O'Sullivan Date: Fri, 15 Jan 2016 13:14:49 -0800 Subject: [PATCH] with: use context manager for transaction in strip --- mercurial/repair.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/mercurial/repair.py b/mercurial/repair.py index 177d3a5154..d7f6d4b67a 100644 --- a/mercurial/repair.py +++ b/mercurial/repair.py @@ -160,26 +160,22 @@ def strip(ui, repo, nodelist, backup=True, topic='backup'): msg = _('programming error: cannot strip from inside a transaction') raise error.Abort(msg, hint=_('contact your extension maintainer')) - tr = repo.transaction("strip") - offset = len(tr.entries) - try: - tr.startgroup() - cl.strip(striprev, tr) - mfst.strip(striprev, tr) - for fn in files: - repo.file(fn).strip(striprev, tr) - tr.endgroup() + with repo.transaction("strip") as tr: + offset = len(tr.entries) + + tr.startgroup() + cl.strip(striprev, tr) + mfst.strip(striprev, tr) + for fn in files: + repo.file(fn).strip(striprev, tr) + tr.endgroup() - try: for i in xrange(offset, len(tr.entries)): file, troffset, ignore = tr.entries[i] repo.svfs(file, 'a').truncate(troffset) if troffset == 0: repo.store.markremoved(file) - tr.close() - finally: - tr.release() if saveheads or savebases: ui.note(_("adding branch\n"))