comparison mercurial/commands.py @ 25744:e78a80f8f51e

bookmarks: change bookmark within a transaction For some time, bookmark can and should be moved in the transaction. This changeset migrates the 'hg bookmarks' commands to use a transaction. Tests regarding rollback and transaction hooks are impacted for obvious reasons. Some have to be slightly updated to keep testing the same things. Some can just be dropped because they do not make sense anymore.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Sun, 28 Sep 2014 00:49:36 -0700
parents 3948cb4d0ae7
children 0d37b9b21467
comparison
equal deleted inserted replaced
25743:ce45bfe8f953 25744:e78a80f8f51e
19 import merge as mergemod 19 import merge as mergemod
20 import minirst, revset, fileset 20 import minirst, revset, fileset
21 import dagparser, context, simplemerge, graphmod, copies 21 import dagparser, context, simplemerge, graphmod, copies
22 import random 22 import random
23 import setdiscovery, treediscovery, dagutil, pvec, localrepo 23 import setdiscovery, treediscovery, dagutil, pvec, localrepo
24 import phases, obsolete, exchange, bundle2, repair 24 import phases, obsolete, exchange, bundle2, repair, lock as lockmod
25 import ui as uimod 25 import ui as uimod
26 26
27 table = {} 27 table = {}
28 28
29 command = cmdutil.command(table) 29 command = cmdutil.command(table)
974 raise util.Abort(_("--rev is incompatible with --rename")) 974 raise util.Abort(_("--rev is incompatible with --rename"))
975 if not names and (delete or rev): 975 if not names and (delete or rev):
976 raise util.Abort(_("bookmark name required")) 976 raise util.Abort(_("bookmark name required"))
977 977
978 if delete or rename or names or inactive: 978 if delete or rename or names or inactive:
979 wlock = repo.wlock() 979 wlock = lock = tr = None
980 try: 980 try:
981 wlock = repo.wlock()
982 lock = repo.lock()
981 cur = repo.changectx('.').node() 983 cur = repo.changectx('.').node()
982 marks = repo._bookmarks 984 marks = repo._bookmarks
983 if delete: 985 if delete:
986 tr = repo.transaction('bookmark')
984 for mark in names: 987 for mark in names:
985 if mark not in marks: 988 if mark not in marks:
986 raise util.Abort(_("bookmark '%s' does not exist") % 989 raise util.Abort(_("bookmark '%s' does not exist") %
987 mark) 990 mark)
988 if mark == repo._activebookmark: 991 if mark == repo._activebookmark:
989 bookmarks.deactivate(repo) 992 bookmarks.deactivate(repo)
990 del marks[mark] 993 del marks[mark]
991 marks.write()
992 994
993 elif rename: 995 elif rename:
996 tr = repo.transaction('bookmark')
994 if not names: 997 if not names:
995 raise util.Abort(_("new bookmark name required")) 998 raise util.Abort(_("new bookmark name required"))
996 elif len(names) > 1: 999 elif len(names) > 1:
997 raise util.Abort(_("only one new bookmark name allowed")) 1000 raise util.Abort(_("only one new bookmark name allowed"))
998 mark = checkformat(names[0]) 1001 mark = checkformat(names[0])
1001 checkconflict(repo, mark, cur, force) 1004 checkconflict(repo, mark, cur, force)
1002 marks[mark] = marks[rename] 1005 marks[mark] = marks[rename]
1003 if repo._activebookmark == rename and not inactive: 1006 if repo._activebookmark == rename and not inactive:
1004 bookmarks.activate(repo, mark) 1007 bookmarks.activate(repo, mark)
1005 del marks[rename] 1008 del marks[rename]
1006 marks.write()
1007
1008 elif names: 1009 elif names:
1010 tr = repo.transaction('bookmark')
1009 newact = None 1011 newact = None
1010 for mark in names: 1012 for mark in names:
1011 mark = checkformat(mark) 1013 mark = checkformat(mark)
1012 if newact is None: 1014 if newact is None:
1013 newact = mark 1015 newact = mark
1021 marks[mark] = tgt 1023 marks[mark] = tgt
1022 if not inactive and cur == marks[newact] and not rev: 1024 if not inactive and cur == marks[newact] and not rev:
1023 bookmarks.activate(repo, newact) 1025 bookmarks.activate(repo, newact)
1024 elif cur != tgt and newact == repo._activebookmark: 1026 elif cur != tgt and newact == repo._activebookmark:
1025 bookmarks.deactivate(repo) 1027 bookmarks.deactivate(repo)
1026 marks.write()
1027
1028 elif inactive: 1028 elif inactive:
1029 if len(marks) == 0: 1029 if len(marks) == 0:
1030 ui.status(_("no bookmarks set\n")) 1030 ui.status(_("no bookmarks set\n"))
1031 elif not repo._activebookmark: 1031 elif not repo._activebookmark:
1032 ui.status(_("no active bookmark\n")) 1032 ui.status(_("no active bookmark\n"))
1033 else: 1033 else:
1034 bookmarks.deactivate(repo) 1034 bookmarks.deactivate(repo)
1035 if tr is not None:
1036 marks.recordchange(tr)
1037 tr.close()
1035 finally: 1038 finally:
1036 wlock.release() 1039 lockmod.release(tr, lock, wlock)
1037 else: # show bookmarks 1040 else: # show bookmarks
1038 fm = ui.formatter('bookmarks', opts) 1041 fm = ui.formatter('bookmarks', opts)
1039 hexfn = fm.hexfunc 1042 hexfn = fm.hexfunc
1040 marks = repo._bookmarks 1043 marks = repo._bookmarks
1041 if len(marks) == 0 and not fm: 1044 if len(marks) == 0 and not fm: