Mercurial > evolve
changeset 4642:a7c4f163656b
cmdrewrite: use context manager for some locks and transactions
These were the trivial cases where I didn't even need to extend the
scope of a transaction or change indentation to fix it.
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 09 May 2019 09:42:51 -0700 |
parents | 686b9a7d3b46 |
children | 77f3699e711e |
files | hgext3rd/evolve/cmdrewrite.py |
diffstat | 1 files changed, 2 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext3rd/evolve/cmdrewrite.py Mon Apr 29 23:43:16 2019 +0530 +++ b/hgext3rd/evolve/cmdrewrite.py Thu May 09 09:42:51 2019 -0700 @@ -149,11 +149,7 @@ def amendpatch(ui, repo, *pats, **opts): """logic for --patch flag of `hg amend` command.""" - lock = wlock = tr = None - try: - wlock = repo.wlock() - lock = repo.lock() - tr = repo.transaction('amend') + with repo.wlock(), repo.lock(), repo.transaction('amend') as tr: cmdutil.bailifchanged(repo) # first get the patch old = repo['.'] @@ -180,11 +176,6 @@ metadata=metadata) phases.retractboundary(repo, tr, old.phase(), [newnode]) hg.updaterepo(repo, newnode, True) - tr.close() - finally: - if tr is not None: - tr.release() - lockmod.release(lock, wlock) def _editandapply(ui, repo, pats, old, p1, fp, diffopts): newnode = None @@ -866,11 +857,7 @@ raise error.Abort(_('revisions must be specified with --fold')) revs = ['.'] - wlock = lock = None - try: - wlock = repo.wlock() - lock = repo.lock() - + with repo.wlock(), repo.lock(): revs = scmutil.revrange(repo, revs) if not opts['fold'] and len(revs) > 1: # TODO: handle multiple revisions. This is somewhat tricky because @@ -950,8 +937,6 @@ ui.status('%i changesets folded\n' % len(revs)) if newp1 is not None: hg.update(repo, newp1) - finally: - lockmod.release(lock, wlock) metadataopts = [ ('d', 'date', '',