D3748: import: use context manager for lock, dirstateguard, transaction
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Fri Jun 15 13:04:33 EDT 2018
martinvonz added a comment.
In https://phab.mercurial-scm.org/D3748#58738, @yuja wrote:
> > + if not opts.get('no_commit'):
> > + lock = repo.lock()
> > + tr = repo.transaction('import')
> > + dsguard = util.nullcontextmanager()
> > + else:
> > + lock = util.nullcontextmanager()
> > + tr = util.nullcontextmanager()
> > + dsguard = dirstateguard.dirstateguard(repo, 'import')
> > + with lock, tr, dsguard:
>
> Doesn't it leave a stale `lock` if `repo.transaction()` raises exception?
Good catch. I have often wished that our transactions and locks respected the context manager protocol and did the locking in __enter__. How do you feel about this workaround (see updated code)?
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D3748
To: martinvonz, #hg-reviewers
Cc: yuja, mercurial-devel
More information about the Mercurial-devel
mailing list