Mercurial > hg
comparison mercurial/revlogutils/docket.py @ 47324:0a3fa41fa719
revlogv2: use a unique filename for data
Having a unique data will allow for ambiguity less rewriting of revlog content,
something useful to clarify handling of some operation like censoring or
stripping.
Differential Revision: https://phab.mercurial-scm.org/D10772
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 19 May 2021 16:55:36 +0200 |
parents | f612db768c7a |
children | f286d715f9ab |
comparison
equal
deleted
inserted
replaced
47323:f612db768c7a | 47324:0a3fa41fa719 |
---|---|
87 # | 87 # |
88 # * 4 bytes: revlog version | 88 # * 4 bytes: revlog version |
89 # | This is mandatory as docket must be compatible with the previous | 89 # | This is mandatory as docket must be compatible with the previous |
90 # | revlog index header. | 90 # | revlog index header. |
91 # * 1 bytes: size of index uuid | 91 # * 1 bytes: size of index uuid |
92 # * 1 bytes: size of data uuid | |
92 # * 8 bytes: size of index-data | 93 # * 8 bytes: size of index-data |
93 # * 8 bytes: pending size of index-data | 94 # * 8 bytes: pending size of index-data |
94 # * 8 bytes: size of data | 95 # * 8 bytes: size of data |
95 # * 8 bytes: pending size of data | 96 # * 8 bytes: pending size of data |
96 # * 1 bytes: default compression header | 97 # * 1 bytes: default compression header |
97 S_HEADER = struct.Struct(constants.INDEX_HEADER.format + 'BLLLLc') | 98 S_HEADER = struct.Struct(constants.INDEX_HEADER.format + 'BBLLLLc') |
98 | 99 |
99 | 100 |
100 class RevlogDocket(object): | 101 class RevlogDocket(object): |
101 """metadata associated with revlog""" | 102 """metadata associated with revlog""" |
102 | 103 |
104 self, | 105 self, |
105 revlog, | 106 revlog, |
106 use_pending=False, | 107 use_pending=False, |
107 version_header=None, | 108 version_header=None, |
108 index_uuid=None, | 109 index_uuid=None, |
110 data_uuid=None, | |
109 index_end=0, | 111 index_end=0, |
110 pending_index_end=0, | 112 pending_index_end=0, |
111 data_end=0, | 113 data_end=0, |
112 pending_data_end=0, | 114 pending_data_end=0, |
113 default_compression_header=None, | 115 default_compression_header=None, |
117 self._dirty = False | 119 self._dirty = False |
118 self._radix = revlog.radix | 120 self._radix = revlog.radix |
119 self._path = revlog._docket_file | 121 self._path = revlog._docket_file |
120 self._opener = revlog.opener | 122 self._opener = revlog.opener |
121 self._index_uuid = index_uuid | 123 self._index_uuid = index_uuid |
124 self._data_uuid = data_uuid | |
122 # thes asserts should be True as long as we have a single index filename | 125 # thes asserts should be True as long as we have a single index filename |
123 assert index_end <= pending_index_end | 126 assert index_end <= pending_index_end |
124 assert data_end <= pending_data_end | 127 assert data_end <= pending_data_end |
125 self._initial_index_end = index_end | 128 self._initial_index_end = index_end |
126 self._pending_index_end = pending_index_end | 129 self._pending_index_end = pending_index_end |
138 """file path to the current index file associated to this docket""" | 141 """file path to the current index file associated to this docket""" |
139 # very simplistic version at first | 142 # very simplistic version at first |
140 if self._index_uuid is None: | 143 if self._index_uuid is None: |
141 self._index_uuid = make_uid() | 144 self._index_uuid = make_uid() |
142 return b"%s-%s.idx" % (self._radix, self._index_uuid) | 145 return b"%s-%s.idx" % (self._radix, self._index_uuid) |
146 | |
147 def data_filepath(self): | |
148 """file path to the current index file associated to this docket""" | |
149 # very simplistic version at first | |
150 if self._data_uuid is None: | |
151 self._data_uuid = make_uid() | |
152 return b"%s-%s.dat" % (self._radix, self._data_uuid) | |
143 | 153 |
144 @property | 154 @property |
145 def index_end(self): | 155 def index_end(self): |
146 return self._index_end | 156 return self._index_end |
147 | 157 |
193 # this assert should be True as long as we have a single index filename | 203 # this assert should be True as long as we have a single index filename |
194 assert official_data_end <= self._data_end | 204 assert official_data_end <= self._data_end |
195 data = ( | 205 data = ( |
196 self._version_header, | 206 self._version_header, |
197 len(self._index_uuid), | 207 len(self._index_uuid), |
208 len(self._data_uuid), | |
198 official_index_end, | 209 official_index_end, |
199 self._index_end, | 210 self._index_end, |
200 official_data_end, | 211 official_data_end, |
201 self._data_end, | 212 self._data_end, |
202 self.default_compression_header, | 213 self.default_compression_header, |
203 ) | 214 ) |
204 s = [] | 215 s = [] |
205 s.append(S_HEADER.pack(*data)) | 216 s.append(S_HEADER.pack(*data)) |
206 s.append(self._index_uuid) | 217 s.append(self._index_uuid) |
218 s.append(self._data_uuid) | |
207 return b''.join(s) | 219 return b''.join(s) |
208 | 220 |
209 | 221 |
210 def default_docket(revlog, version_header): | 222 def default_docket(revlog, version_header): |
211 """given a revlog version a new docket object for the given revlog""" | 223 """given a revlog version a new docket object for the given revlog""" |
228 offset = S_HEADER.size | 240 offset = S_HEADER.size |
229 version_header = header[0] | 241 version_header = header[0] |
230 index_uuid_size = header[1] | 242 index_uuid_size = header[1] |
231 index_uuid = data[offset : offset + index_uuid_size] | 243 index_uuid = data[offset : offset + index_uuid_size] |
232 offset += index_uuid_size | 244 offset += index_uuid_size |
233 index_size = header[2] | 245 data_uuid_size = header[2] |
234 pending_index_size = header[3] | 246 data_uuid = data[offset : offset + data_uuid_size] |
235 data_size = header[4] | 247 offset += data_uuid_size |
236 pending_data_size = header[5] | 248 index_size = header[3] |
237 default_compression_header = header[6] | 249 pending_index_size = header[4] |
250 data_size = header[5] | |
251 pending_data_size = header[6] | |
252 default_compression_header = header[7] | |
238 docket = RevlogDocket( | 253 docket = RevlogDocket( |
239 revlog, | 254 revlog, |
240 use_pending=use_pending, | 255 use_pending=use_pending, |
241 version_header=version_header, | 256 version_header=version_header, |
242 index_uuid=index_uuid, | 257 index_uuid=index_uuid, |
258 data_uuid=data_uuid, | |
243 index_end=index_size, | 259 index_end=index_size, |
244 pending_index_end=pending_index_size, | 260 pending_index_end=pending_index_size, |
245 data_end=data_size, | 261 data_end=data_size, |
246 pending_data_end=pending_data_size, | 262 pending_data_end=pending_data_size, |
247 default_compression_header=default_compression_header, | 263 default_compression_header=default_compression_header, |