# HG changeset patch # User Sean Farley # Date 1497998203 25200 # Node ID ac57603a44feaac4579130ac31ecf20587f42f8a # Parent ee081f91b179a60d069976c5d75443f501a58586 commands: replace locking code with a context manager Note that this means that we're unnecessarily creating a transaction in the pure "--inactive" (i.e. when deactivating the current bookmark), but that should be harmless. diff -r ee081f91b179 -r ac57603a44fe mercurial/commands.py --- a/mercurial/commands.py Tue Jun 20 15:18:40 2017 -0700 +++ b/mercurial/commands.py Tue Jun 20 15:36:43 2017 -0700 @@ -967,36 +967,24 @@ raise error.Abort(_("bookmark name required")) if delete or rename or names or inactive: - wlock = lock = tr = None - try: - wlock = repo.wlock() - lock = repo.lock() - marks = repo._bookmarks + with repo.wlock(), repo.lock(), repo.transaction('bookmark') as tr: if delete: - tr = repo.transaction('bookmark') bookmarks.delete(repo, tr, names) elif rename: - tr = repo.transaction('bookmark') if not names: raise error.Abort(_("new bookmark name required")) elif len(names) > 1: raise error.Abort(_("only one new bookmark name allowed")) bookmarks.rename(repo, tr, rename, names[0], force, inactive) elif names: - tr = repo.transaction('bookmark') bookmarks.addbookmarks(repo, tr, names, rev, force, inactive) elif inactive: - if len(marks) == 0: + if len(repo._bookmarks) == 0: ui.status(_("no bookmarks set\n")) elif not repo._activebookmark: ui.status(_("no active bookmark\n")) else: bookmarks.deactivate(repo) - if tr is not None: - marks.recordchange(tr) - tr.close() - finally: - lockmod.release(tr, lock, wlock) else: # show bookmarks fm = ui.formatter('bookmarks', opts) hexfn = fm.hexfunc