Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 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 |
comparison
equal
deleted
inserted
replaced
33007:ee081f91b179 | 33008:ac57603a44fe |
---|---|
965 raise error.Abort(_("--rev is incompatible with --rename")) | 965 raise error.Abort(_("--rev is incompatible with --rename")) |
966 if not names and (delete or rev): | 966 if not names and (delete or rev): |
967 raise error.Abort(_("bookmark name required")) | 967 raise error.Abort(_("bookmark name required")) |
968 | 968 |
969 if delete or rename or names or inactive: | 969 if delete or rename or names or inactive: |
970 wlock = lock = tr = None | 970 with repo.wlock(), repo.lock(), repo.transaction('bookmark') as tr: |
971 try: | |
972 wlock = repo.wlock() | |
973 lock = repo.lock() | |
974 marks = repo._bookmarks | |
975 if delete: | 971 if delete: |
976 tr = repo.transaction('bookmark') | |
977 bookmarks.delete(repo, tr, names) | 972 bookmarks.delete(repo, tr, names) |
978 elif rename: | 973 elif rename: |
979 tr = repo.transaction('bookmark') | |
980 if not names: | 974 if not names: |
981 raise error.Abort(_("new bookmark name required")) | 975 raise error.Abort(_("new bookmark name required")) |
982 elif len(names) > 1: | 976 elif len(names) > 1: |
983 raise error.Abort(_("only one new bookmark name allowed")) | 977 raise error.Abort(_("only one new bookmark name allowed")) |
984 bookmarks.rename(repo, tr, rename, names[0], force, inactive) | 978 bookmarks.rename(repo, tr, rename, names[0], force, inactive) |
985 elif names: | 979 elif names: |
986 tr = repo.transaction('bookmark') | |
987 bookmarks.addbookmarks(repo, tr, names, rev, force, inactive) | 980 bookmarks.addbookmarks(repo, tr, names, rev, force, inactive) |
988 elif inactive: | 981 elif inactive: |
989 if len(marks) == 0: | 982 if len(repo._bookmarks) == 0: |
990 ui.status(_("no bookmarks set\n")) | 983 ui.status(_("no bookmarks set\n")) |
991 elif not repo._activebookmark: | 984 elif not repo._activebookmark: |
992 ui.status(_("no active bookmark\n")) | 985 ui.status(_("no active bookmark\n")) |
993 else: | 986 else: |
994 bookmarks.deactivate(repo) | 987 bookmarks.deactivate(repo) |
995 if tr is not None: | |
996 marks.recordchange(tr) | |
997 tr.close() | |
998 finally: | |
999 lockmod.release(tr, lock, wlock) | |
1000 else: # show bookmarks | 988 else: # show bookmarks |
1001 fm = ui.formatter('bookmarks', opts) | 989 fm = ui.formatter('bookmarks', opts) |
1002 hexfn = fm.hexfunc | 990 hexfn = fm.hexfunc |
1003 marks = repo._bookmarks | 991 marks = repo._bookmarks |
1004 if len(marks) == 0 and fm.isplain(): | 992 if len(marks) == 0 and fm.isplain(): |