comparison mercurial/bookmarks.py @ 26520:46dec89fe888

bookmarks: use recordchange instead of writing if transaction is active Before this patch, 'bmstore.write()' always write in-memory bookmark changes into '.hg/bookmarks' regardless of transaction activity. If 'bmstore.write()' is invoked inside a transaction and it writes changes into '.hg/bookmarks', then: - original bookmarks aren't restored at failure of that transaction This breaks "all or nothing" policy of the transaction. BTW, "hg rollback" can restore bookmarks successfully even before this patch, because original bookmarks are saved into '.hg/journal.bookmarks' at the beginning of the transaction, and it (actually renamed as '.hg/undo.bookmarks') is used by "hg rollback". - uncommitted bookmark changes are visible to other processes This is a kind of "dirty read" For example, 'rebase.rebase()' implies 'bmstore.write()', and it may be executed inside the transaction of "hg unshelve". Then, intentional aborting at the end of "hg unshelve" transaction doesn't restore original bookmarks (this is obviously a bug). This patch uses 'bmstore.recordchange()' instead of actual writing by 'bmstore._writerepo()', if any transaction is active This patch also removes meaningless restoring bmstore explicitly at the end of "hg shelve". This patch doesn't choose fixing each 'bmstore.write()' callers as like below, because writing similar code here and there is very redundant. before: bmstore.write() after: tr = repo.currenttransaction() if tr: bmstore.recordchange(tr) else: bmstore.write() Even though 'bmstore.write()' itself may have to be discarded by putting bookmark operations into transaction scope, this patch chose fixing it to implement "transactional dirstate" at first.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Thu, 08 Oct 2015 01:41:30 +0900
parents 0b57b77f9b3e
children 1aee2ab0f902
comparison
equal deleted inserted replaced
26519:48476c6129a2 26520:46dec89fe888
93 if (repo.ui.configbool('devel', 'all-warnings') 93 if (repo.ui.configbool('devel', 'all-warnings')
94 or repo.ui.configbool('devel', 'check-locks')): 94 or repo.ui.configbool('devel', 'check-locks')):
95 l = repo._wlockref and repo._wlockref() 95 l = repo._wlockref and repo._wlockref()
96 if l is None or not l.held: 96 if l is None or not l.held:
97 repo.ui.develwarn('bookmarks write with no wlock') 97 repo.ui.develwarn('bookmarks write with no wlock')
98
99 tr = repo.currenttransaction()
100 if tr:
101 self.recordchange(tr)
102 # invalidatevolatilesets() is omitted because this doesn't
103 # write changes out actually
104 return
105
98 self._writerepo(repo) 106 self._writerepo(repo)
99 repo.invalidatevolatilesets() 107 repo.invalidatevolatilesets()
100 108
101 def _writerepo(self, repo): 109 def _writerepo(self, repo):
102 """Factored out for extensibility""" 110 """Factored out for extensibility"""