D3748: import: use context manager for lock, dirstateguard, transaction

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Sun Jun 17 09:33:41 EDT 2018


martinvonz added a comment.


  In https://phab.mercurial-scm.org/D3748#58833, @yuja wrote:
  
  > > +        if not opts.get('no_commit'):
  > >  +            lock = repo.lock()
  > >  +            try:
  > > 
  > >   tr = repo.transaction('import')
  > > 
  > > - else:
  > > - dsguard = dirstateguard.dirstateguard(repo, 'import') +            except: +                lock.release()
  >
  > Needs to re-raise.
  >
  > > +            dsguard = util.nullcontextmanager()
  > >  +        else:
  > >  +            lock = util.nullcontextmanager()
  > >  +            tr = util.nullcontextmanager()
  > >  +            dsguard = dirstateguard.dirstateguard(repo, 'import')
  > >  +        with lock, tr, dsguard:
  >
  > Another option is to wrap transaction and dirstateguard by lambda or partial,
  >  and call them with "with".
  >
  >   with lock(), tr(), dsguard():
  >
  
  
  Good idea. Done.

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