comparison mercurial/dirstatemap.py @ 50097:ca9d65d69c27 stable

dirstate-v2: complain early on docket name collision The alternative is that the dirstate gets deleted so the corruption persists and is hard to investigate. This happened to me in tests, where the dirstate names are taken from file, since the file got reverted. I expect this can also happen in prod with non-trivial probability (1/4 billion).
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Fri, 18 Nov 2022 13:51:40 +0000
parents 302dd8ae2745
children 0f0880c8a7e5 1891086f6c7f
comparison
equal deleted inserted replaced
50092:010a1e73f69e 50097:ca9d65d69c27
112 def write_v2_no_append(self, tr, st, meta, packed): 112 def write_v2_no_append(self, tr, st, meta, packed):
113 old_docket = self.docket 113 old_docket = self.docket
114 new_docket = docketmod.DirstateDocket.with_new_uuid( 114 new_docket = docketmod.DirstateDocket.with_new_uuid(
115 self.parents(), len(packed), meta 115 self.parents(), len(packed), meta
116 ) 116 )
117 if old_docket.uuid == new_docket.uuid:
118 raise error.ProgrammingError(b'dirstate docket name collision')
117 data_filename = new_docket.data_filename() 119 data_filename = new_docket.data_filename()
118 self._opener.write(data_filename, packed) 120 self._opener.write(data_filename, packed)
119 # Write the new docket after the new data file has been 121 # Write the new docket after the new data file has been
120 # written. Because `st` was opened with `atomictemp=True`, 122 # written. Because `st` was opened with `atomictemp=True`,
121 # the actual `.hg/dirstate` file is only affected on close. 123 # the actual `.hg/dirstate` file is only affected on close.