Mercurial > hg
changeset 33008:ac57603a44fe
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.
author | Sean Farley <sean@farley.io> |
---|---|
date | Tue, 20 Jun 2017 15:36:43 -0700 |
parents | ee081f91b179 |
children | 4b81776baa7a |
files | mercurial/commands.py |
diffstat | 1 files changed, 2 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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