diff 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
line wrap: on
line diff
--- a/mercurial/revlog.py	Thu Jan 20 14:02:58 2022 +0000
+++ b/mercurial/revlog.py	Thu Jan 20 14:06:36 2022 +0000
@@ -2006,7 +2006,7 @@
             raise error.RevlogError(
                 _(b"%s not found in the transaction") % self._indexfile
             )
-        trindex = 0
+        trindex = None
         tr.add(self._datafile, 0)
 
         existing_handles = False
@@ -2029,10 +2029,17 @@
             with self._indexfp() as read_ifh:
                 for r in self:
                     new_dfh.write(self._getsegmentforrevs(r, r, df=read_ifh)[1])
-                    if troffset <= self.start(r) + r * self.index.entry_size:
+                    if (
+                        trindex is None
+                        and troffset
+                        <= self.start(r) + r * self.index.entry_size
+                    ):
                         trindex = r
                 new_dfh.flush()
 
+            if trindex is None:
+                trindex = 0
+
             with self.__index_new_fp() as fp:
                 self._format_flags &= ~FLAG_INLINE_DATA
                 self._inline = False