comparison mercurial/revlog.py @ 48571:ccd9cb73125c stable

revlog: fix a bug where transaction can be aborted partially Fix a repo corruption bug caused by a partial transaction rollback. Differential Revision: https://phab.mercurial-scm.org/D12009
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Thu, 20 Jan 2022 14:06:36 +0000
parents ebac18733142
children e845537f6adb
comparison
equal deleted inserted replaced
48570:f38ae2d7390e 48571:ccd9cb73125c
2004 troffset = tr.findoffset(self._indexfile) 2004 troffset = tr.findoffset(self._indexfile)
2005 if troffset is None: 2005 if troffset is None:
2006 raise error.RevlogError( 2006 raise error.RevlogError(
2007 _(b"%s not found in the transaction") % self._indexfile 2007 _(b"%s not found in the transaction") % self._indexfile
2008 ) 2008 )
2009 trindex = 0 2009 trindex = None
2010 tr.add(self._datafile, 0) 2010 tr.add(self._datafile, 0)
2011 2011
2012 existing_handles = False 2012 existing_handles = False
2013 if self._writinghandles is not None: 2013 if self._writinghandles is not None:
2014 existing_handles = True 2014 existing_handles = True
2027 new_dfh.truncate(0) # drop any potentially existing data 2027 new_dfh.truncate(0) # drop any potentially existing data
2028 try: 2028 try:
2029 with self._indexfp() as read_ifh: 2029 with self._indexfp() as read_ifh:
2030 for r in self: 2030 for r in self:
2031 new_dfh.write(self._getsegmentforrevs(r, r, df=read_ifh)[1]) 2031 new_dfh.write(self._getsegmentforrevs(r, r, df=read_ifh)[1])
2032 if troffset <= self.start(r) + r * self.index.entry_size: 2032 if (
2033 trindex is None
2034 and troffset
2035 <= self.start(r) + r * self.index.entry_size
2036 ):
2033 trindex = r 2037 trindex = r
2034 new_dfh.flush() 2038 new_dfh.flush()
2039
2040 if trindex is None:
2041 trindex = 0
2035 2042
2036 with self.__index_new_fp() as fp: 2043 with self.__index_new_fp() as fp:
2037 self._format_flags &= ~FLAG_INLINE_DATA 2044 self._format_flags &= ~FLAG_INLINE_DATA
2038 self._inline = False 2045 self._inline = False
2039 for i in self: 2046 for i in self: