comparison mercurial/localrepo.py @ 29191:ad1ce3c7af72

localrepo: use dirstate savebackup instead of handling dirstate file manually This is one step towards having dirstate manage its own storage. It will be useful for the implementation of sql dirstate [1]. This introduced a small test change: now we always write the dirstate before saving backup so in some cases where dirstate file didn't exist yet savebackup can create it. [1] https://www.mercurial-scm.org/wiki/SQLDirstatePlan
author Mateusz Kwapich <mitrandir@fb.com>
date Wed, 11 May 2016 14:18:52 -0700
parents e51f34183599
children ee935a6e1ea2
comparison
equal deleted inserted replaced
29190:e51f34183599 29191:ad1ce3c7af72
1010 if self.svfs.exists("journal"): 1010 if self.svfs.exists("journal"):
1011 raise error.RepoError( 1011 raise error.RepoError(
1012 _("abandoned transaction found"), 1012 _("abandoned transaction found"),
1013 hint=_("run 'hg recover' to clean up transaction")) 1013 hint=_("run 'hg recover' to clean up transaction"))
1014 1014
1015 # make journal.dirstate contain in-memory changes at this point
1016 self.dirstate.write(None)
1017
1018 idbase = "%.40f#%f" % (random.random(), time.time()) 1015 idbase = "%.40f#%f" % (random.random(), time.time())
1019 txnid = 'TXN:' + util.sha1(idbase).hexdigest() 1016 txnid = 'TXN:' + util.sha1(idbase).hexdigest()
1020 self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid) 1017 self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid)
1021 1018
1022 self._writejournal(desc) 1019 self._writejournal(desc)
1097 1094
1098 def undofiles(self): 1095 def undofiles(self):
1099 return [(vfs, undoname(x)) for vfs, x in self._journalfiles()] 1096 return [(vfs, undoname(x)) for vfs, x in self._journalfiles()]
1100 1097
1101 def _writejournal(self, desc): 1098 def _writejournal(self, desc):
1102 self.vfs.write("journal.dirstate", 1099 self.dirstate.savebackup(None, prefix='journal.')
1103 self.vfs.tryread("dirstate"))
1104 self.vfs.write("journal.branch", 1100 self.vfs.write("journal.branch",
1105 encoding.fromlocal(self.dirstate.branch())) 1101 encoding.fromlocal(self.dirstate.branch()))
1106 self.vfs.write("journal.desc", 1102 self.vfs.write("journal.desc",
1107 "%d\n%s\n" % (len(self), desc)) 1103 "%d\n%s\n" % (len(self), desc))
1108 self.vfs.write("journal.bookmarks", 1104 self.vfs.write("journal.bookmarks",