Show More
@@ -270,72 +270,97 b' def v2_censor(rl, tr, censornode, tombst' | |||
|
270 | 270 | tombstone, |
|
271 | 271 | ) |
|
272 | 272 | |
|
273 |
|
|
|
273 | # Writing all subsequent revisions | |
|
274 | 274 | for rev in range(censor_rev + 1, len(old_index)): |
|
275 | entry = old_index[rev] | |
|
276 | flags = entry[ENTRY_DATA_OFFSET] & 0xFFFF | |
|
277 | old_data_offset = entry[ENTRY_DATA_OFFSET] >> 16 | |
|
275 | _rewrite_simple( | |
|
276 | rl, | |
|
277 | old_index, | |
|
278 | open_files, | |
|
279 | rev, | |
|
280 | rewritten_entries, | |
|
281 | tmp_storage, | |
|
282 | ) | |
|
283 | docket.write(transaction=None, stripping=True) | |
|
284 | ||
|
278 | 285 | |
|
279 | if rev not in rewritten_entries: | |
|
280 | old_data_file.seek(old_data_offset) | |
|
281 | new_data_size = entry[ENTRY_DATA_COMPRESSED_LENGTH] | |
|
282 | new_data = old_data_file.read(new_data_size) | |
|
283 | data_delta_base = entry[ENTRY_DELTA_BASE] | |
|
284 | d_comp_mode = entry[ENTRY_DATA_COMPRESSION_MODE] | |
|
285 | else: | |
|
286 | ( | |
|
287 | data_delta_base, | |
|
288 | start, | |
|
289 | end, | |
|
290 | d_comp_mode, | |
|
291 | ) = rewritten_entries[rev] | |
|
292 | new_data_size = end - start | |
|
293 | tmp_storage.seek(start) | |
|
294 | new_data = tmp_storage.read(new_data_size) | |
|
295 | ||
|
296 | # It might be faster to group continuous read/write operation, | |
|
297 | # however, this is censor, an operation that is not focussed | |
|
298 | # around stellar performance. So I have not written this | |
|
299 | # optimisation yet. | |
|
300 | new_data_offset = new_data_file.tell() | |
|
301 | new_data_file.write(new_data) | |
|
286 | def _rewrite_simple( | |
|
287 | revlog, | |
|
288 | old_index, | |
|
289 | all_files, | |
|
290 | rev, | |
|
291 | rewritten_entries, | |
|
292 | tmp_storage, | |
|
293 | ): | |
|
294 | """append a normal revision to the index after the rewritten one(s)""" | |
|
295 | ( | |
|
296 | old_data_file, | |
|
297 | old_sidedata_file, | |
|
298 | new_index_file, | |
|
299 | new_data_file, | |
|
300 | new_sidedata_file, | |
|
301 | ) = all_files | |
|
302 | entry = old_index[rev] | |
|
303 | flags = entry[ENTRY_DATA_OFFSET] & 0xFFFF | |
|
304 | old_data_offset = entry[ENTRY_DATA_OFFSET] >> 16 | |
|
302 | 305 | |
|
303 | sidedata_size = entry[ENTRY_SIDEDATA_COMPRESSED_LENGTH] | |
|
304 | new_sidedata_offset = new_sidedata_file.tell() | |
|
305 | if 0 < sidedata_size: | |
|
306 | old_sidedata_offset = entry[ENTRY_SIDEDATA_OFFSET] | |
|
307 | old_sidedata_file.seek(old_sidedata_offset) | |
|
308 | new_sidedata = old_sidedata_file.read(sidedata_size) | |
|
309 | new_sidedata_file.write(new_sidedata) | |
|
306 | if rev not in rewritten_entries: | |
|
307 | old_data_file.seek(old_data_offset) | |
|
308 | new_data_size = entry[ENTRY_DATA_COMPRESSED_LENGTH] | |
|
309 | new_data = old_data_file.read(new_data_size) | |
|
310 | data_delta_base = entry[ENTRY_DELTA_BASE] | |
|
311 | d_comp_mode = entry[ENTRY_DATA_COMPRESSION_MODE] | |
|
312 | else: | |
|
313 | ( | |
|
314 | data_delta_base, | |
|
315 | start, | |
|
316 | end, | |
|
317 | d_comp_mode, | |
|
318 | ) = rewritten_entries[rev] | |
|
319 | new_data_size = end - start | |
|
320 | tmp_storage.seek(start) | |
|
321 | new_data = tmp_storage.read(new_data_size) | |
|
310 | 322 | |
|
311 | data_uncompressed_length = entry[ENTRY_DATA_UNCOMPRESSED_LENGTH] | |
|
312 | sd_com_mode = entry[ENTRY_SIDEDATA_COMPRESSION_MODE] | |
|
313 | assert data_delta_base <= rev, (data_delta_base, rev) | |
|
323 | # It might be faster to group continuous read/write operation, | |
|
324 | # however, this is censor, an operation that is not focussed | |
|
325 | # around stellar performance. So I have not written this | |
|
326 | # optimisation yet. | |
|
327 | new_data_offset = new_data_file.tell() | |
|
328 | new_data_file.write(new_data) | |
|
314 | 329 | |
|
315 | new_entry = revlogutils.entry( | |
|
316 | flags=flags, | |
|
317 | data_offset=new_data_offset, | |
|
318 | data_compressed_length=new_data_size, | |
|
319 | data_uncompressed_length=data_uncompressed_length, | |
|
320 | data_delta_base=data_delta_base, | |
|
321 | link_rev=entry[ENTRY_LINK_REV], | |
|
322 | parent_rev_1=entry[ENTRY_PARENT_1], | |
|
323 | parent_rev_2=entry[ENTRY_PARENT_2], | |
|
324 | node_id=entry[ENTRY_NODE_ID], | |
|
325 | sidedata_offset=new_sidedata_offset, | |
|
326 | sidedata_compressed_length=sidedata_size, | |
|
327 | data_compression_mode=d_comp_mode, | |
|
328 | sidedata_compression_mode=sd_com_mode, | |
|
329 | ) | |
|
330 | rl.index.append(new_entry) | |
|
331 | entry_bin = rl.index.entry_binary(rev) | |
|
332 | new_index_file.write(entry_bin) | |
|
330 | sidedata_size = entry[ENTRY_SIDEDATA_COMPRESSED_LENGTH] | |
|
331 | new_sidedata_offset = new_sidedata_file.tell() | |
|
332 | if 0 < sidedata_size: | |
|
333 | old_sidedata_offset = entry[ENTRY_SIDEDATA_OFFSET] | |
|
334 | old_sidedata_file.seek(old_sidedata_offset) | |
|
335 | new_sidedata = old_sidedata_file.read(sidedata_size) | |
|
336 | new_sidedata_file.write(new_sidedata) | |
|
337 | ||
|
338 | data_uncompressed_length = entry[ENTRY_DATA_UNCOMPRESSED_LENGTH] | |
|
339 | sd_com_mode = entry[ENTRY_SIDEDATA_COMPRESSION_MODE] | |
|
340 | assert data_delta_base <= rev, (data_delta_base, rev) | |
|
333 | 341 | |
|
334 | docket.index_end = new_index_file.tell() | |
|
335 | docket.data_end = new_data_file.tell() | |
|
336 | docket.sidedata_end = new_sidedata_file.tell() | |
|
342 | new_entry = revlogutils.entry( | |
|
343 | flags=flags, | |
|
344 | data_offset=new_data_offset, | |
|
345 | data_compressed_length=new_data_size, | |
|
346 | data_uncompressed_length=data_uncompressed_length, | |
|
347 | data_delta_base=data_delta_base, | |
|
348 | link_rev=entry[ENTRY_LINK_REV], | |
|
349 | parent_rev_1=entry[ENTRY_PARENT_1], | |
|
350 | parent_rev_2=entry[ENTRY_PARENT_2], | |
|
351 | node_id=entry[ENTRY_NODE_ID], | |
|
352 | sidedata_offset=new_sidedata_offset, | |
|
353 | sidedata_compressed_length=sidedata_size, | |
|
354 | data_compression_mode=d_comp_mode, | |
|
355 | sidedata_compression_mode=sd_com_mode, | |
|
356 | ) | |
|
357 | revlog.index.append(new_entry) | |
|
358 | entry_bin = revlog.index.entry_binary(rev) | |
|
359 | new_index_file.write(entry_bin) | |
|
337 | 360 | |
|
338 | docket.write(transaction=None, stripping=True) | |
|
361 | revlog._docket.index_end = new_index_file.tell() | |
|
362 | revlog._docket.data_end = new_data_file.tell() | |
|
363 | revlog._docket.sidedata_end = new_sidedata_file.tell() | |
|
339 | 364 | |
|
340 | 365 | |
|
341 | 366 | def _rewrite_censor( |
General Comments 0
You need to be logged in to leave comments.
Login now