changeset 47467:3ab267f0cbe4

censor: extract the part about writing the censored revision in a function The v2_censor function is huge, now that its content has settled a bit it is a good time to split individual part inside dedicated function. We start with a small function that process the censored revision. Differential Revision: https://phab.mercurial-scm.org/D10898
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 22 Jun 2021 21:41:33 +0200
parents f7a94e2d4470
children 9b70aa7bcbab
files mercurial/revlogutils/rewrite.py
diffstat 1 files changed, 58 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlogutils/rewrite.py	Tue Jun 22 21:22:55 2021 +0200
+++ b/mercurial/revlogutils/rewrite.py	Tue Jun 22 21:41:33 2021 +0200
@@ -261,36 +261,14 @@
             new_sidedata_file.seek(0, os.SEEK_END)
             assert new_sidedata_file.tell() == sidedata_cutoff
 
-            ### writing the censored revision
-            entry = old_index[censor_rev]
-
-            # XXX consider trying the default compression too
-            new_data_size = len(tombstone)
-            new_data_offset = new_data_file.tell()
-            new_data_file.write(tombstone)
-
-            # we are not adding any sidedata as they might leak info about the censored version
-
-            new_entry = revlogutils.entry(
-                flags=constants.REVIDX_ISCENSORED,
-                data_offset=new_data_offset,
-                data_compressed_length=new_data_size,
-                data_uncompressed_length=new_data_size,
-                data_delta_base=censor_rev,
-                link_rev=entry[ENTRY_LINK_REV],
-                parent_rev_1=entry[ENTRY_PARENT_1],
-                parent_rev_2=entry[ENTRY_PARENT_2],
-                node_id=entry[ENTRY_NODE_ID],
-                sidedata_offset=0,
-                sidedata_compressed_length=0,
-                data_compression_mode=COMP_MODE_PLAIN,
-                sidedata_compression_mode=COMP_MODE_PLAIN,
+            # writing the censored revision
+            _rewrite_censor(
+                rl,
+                old_index,
+                open_files,
+                censor_rev,
+                tombstone,
             )
-            rl.index.append(new_entry)
-            entry_bin = rl.index.entry_binary(censor_rev)
-            new_index_file.write(entry_bin)
-            docket.index_end = new_index_file.tell()
-            docket.data_end = new_data_file.tell()
 
             #### Writing all subsequent revisions
             for rev in range(censor_rev + 1, len(old_index)):
@@ -358,3 +336,54 @@
                 docket.sidedata_end = new_sidedata_file.tell()
 
     docket.write(transaction=None, stripping=True)
+
+
+def _rewrite_censor(
+    revlog,
+    old_index,
+    all_files,
+    rev,
+    tombstone,
+):
+    """rewrite and append a censored revision"""
+    (
+        old_data_file,
+        old_sidedata_file,
+        new_index_file,
+        new_data_file,
+        new_sidedata_file,
+    ) = all_files
+    entry = old_index[rev]
+
+    # XXX consider trying the default compression too
+    new_data_size = len(tombstone)
+    new_data_offset = new_data_file.tell()
+    new_data_file.write(tombstone)
+
+    # we are not adding any sidedata as they might leak info about the censored version
+
+    link_rev = entry[ENTRY_LINK_REV]
+
+    p1 = entry[ENTRY_PARENT_1]
+    p2 = entry[ENTRY_PARENT_2]
+
+    new_entry = revlogutils.entry(
+        flags=constants.REVIDX_ISCENSORED,
+        data_offset=new_data_offset,
+        data_compressed_length=new_data_size,
+        data_uncompressed_length=new_data_size,
+        data_delta_base=rev,
+        link_rev=link_rev,
+        parent_rev_1=p1,
+        parent_rev_2=p2,
+        node_id=entry[ENTRY_NODE_ID],
+        sidedata_offset=0,
+        sidedata_compressed_length=0,
+        data_compression_mode=COMP_MODE_PLAIN,
+        sidedata_compression_mode=COMP_MODE_PLAIN,
+    )
+    revlog.index.append(new_entry)
+    entry_bin = revlog.index.entry_binary(rev)
+    new_index_file.write(entry_bin)
+    revlog._docket.index_end = new_index_file.tell()
+    revlog._docket.data_end = new_data_file.tell()