comparison mercurial/commands.py @ 33007:ee081f91b179

bookmarks: factor out adding a list of bookmarks logic from commands We keep the lock in the caller so that future devs are aware of the locking implications.
author Sean Farley <sean@farley.io>
date Tue, 20 Jun 2017 15:18:40 -0700
parents e0a8dd6c87c7
children ac57603a44fe
comparison
equal deleted inserted replaced
33006:e0a8dd6c87c7 33007:ee081f91b179
969 if delete or rename or names or inactive: 969 if delete or rename or names or inactive:
970 wlock = lock = tr = None 970 wlock = lock = tr = None
971 try: 971 try:
972 wlock = repo.wlock() 972 wlock = repo.wlock()
973 lock = repo.lock() 973 lock = repo.lock()
974 cur = repo.changectx('.').node()
975 marks = repo._bookmarks 974 marks = repo._bookmarks
976 if delete: 975 if delete:
977 tr = repo.transaction('bookmark') 976 tr = repo.transaction('bookmark')
978 bookmarks.delete(repo, tr, names) 977 bookmarks.delete(repo, tr, names)
979 elif rename: 978 elif rename:
983 elif len(names) > 1: 982 elif len(names) > 1:
984 raise error.Abort(_("only one new bookmark name allowed")) 983 raise error.Abort(_("only one new bookmark name allowed"))
985 bookmarks.rename(repo, tr, rename, names[0], force, inactive) 984 bookmarks.rename(repo, tr, rename, names[0], force, inactive)
986 elif names: 985 elif names:
987 tr = repo.transaction('bookmark') 986 tr = repo.transaction('bookmark')
988 newact = None 987 bookmarks.addbookmarks(repo, tr, names, rev, force, inactive)
989 for mark in names:
990 mark = bookmarks.checkformat(repo, mark)
991 if newact is None:
992 newact = mark
993 if inactive and mark == repo._activebookmark:
994 bookmarks.deactivate(repo)
995 return
996 tgt = cur
997 if rev:
998 tgt = scmutil.revsingle(repo, rev).node()
999 marks.checkconflict(mark, force, tgt)
1000 marks[mark] = tgt
1001 if not inactive and cur == marks[newact] and not rev:
1002 bookmarks.activate(repo, newact)
1003 elif cur != tgt and newact == repo._activebookmark:
1004 bookmarks.deactivate(repo)
1005 elif inactive: 988 elif inactive:
1006 if len(marks) == 0: 989 if len(marks) == 0:
1007 ui.status(_("no bookmarks set\n")) 990 ui.status(_("no bookmarks set\n"))
1008 elif not repo._activebookmark: 991 elif not repo._activebookmark:
1009 ui.status(_("no active bookmark\n")) 992 ui.status(_("no active bookmark\n"))