comparison mercurial/revlogutils/rewrite.py @ 47471:aab064416f0c

censor: rename `rl` to `revlog` in the main function Now that the bulk of the code moved to smaller function we are less restricted on line length and we can use more explicite naming. Differential Revision: https://phab.mercurial-scm.org/D10902
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 22 Jun 2021 22:35:37 +0200
parents d6afe1478a2a
children c81a5297f185
comparison
equal deleted inserted replaced
47470:d6afe1478a2a 47471:aab064416f0c
123 123
124 rl.clearcaches() 124 rl.clearcaches()
125 rl._loadindex() 125 rl._loadindex()
126 126
127 127
128 def v2_censor(rl, tr, censornode, tombstone=b''): 128 def v2_censor(revlog, tr, censornode, tombstone=b''):
129 """censors a revision in a "version 2" revlog""" 129 """censors a revision in a "version 2" revlog"""
130 # General principle 130 # General principle
131 # 131 #
132 # We create new revlog files (index/data/sidedata) to copy the content of 132 # We create new revlog files (index/data/sidedata) to copy the content of
133 # the existing data without the censored data. 133 # the existing data without the censored data.
138 # final destination. 138 # final destination.
139 # 139 #
140 # All data before the censored data can be blindly copied. The rest needs 140 # All data before the censored data can be blindly copied. The rest needs
141 # to be copied as we go and the associated index entry needs adjustement. 141 # to be copied as we go and the associated index entry needs adjustement.
142 142
143 assert rl._format_version != REVLOGV0, rl._format_version 143 assert revlog._format_version != REVLOGV0, revlog._format_version
144 assert rl._format_version != REVLOGV1, rl._format_version 144 assert revlog._format_version != REVLOGV1, revlog._format_version
145 145
146 old_index = rl.index 146 old_index = revlog.index
147 docket = rl._docket 147 docket = revlog._docket
148 148
149 censor_rev = rl.rev(censornode) 149 censor_rev = revlog.rev(censornode)
150 tombstone = storageutil.packmeta({b'censored': tombstone}, b'') 150 tombstone = storageutil.packmeta({b'censored': tombstone}, b'')
151 151
152 censored_entry = rl.index[censor_rev] 152 censored_entry = revlog.index[censor_rev]
153 index_cutoff = rl.index.entry_size * censor_rev 153 index_cutoff = revlog.index.entry_size * censor_rev
154 data_cutoff = censored_entry[ENTRY_DATA_OFFSET] >> 16 154 data_cutoff = censored_entry[ENTRY_DATA_OFFSET] >> 16
155 sidedata_cutoff = rl.sidedata_cut_off(censor_rev) 155 sidedata_cutoff = revlog.sidedata_cut_off(censor_rev)
156 156
157 with pycompat.unnamedtempfile(mode=b"w+b") as tmp_storage: 157 with pycompat.unnamedtempfile(mode=b"w+b") as tmp_storage:
158 # rev → (new_base, data_start, data_end, compression_mode) 158 # rev → (new_base, data_start, data_end, compression_mode)
159 rewritten_entries = _precompute_rewritten_delta( 159 rewritten_entries = _precompute_rewritten_delta(
160 rl, 160 revlog,
161 old_index, 161 old_index,
162 {censor_rev}, 162 {censor_rev},
163 tmp_storage, 163 tmp_storage,
164 ) 164 )
165 165
166 all_files = _setup_new_files( 166 all_files = _setup_new_files(
167 rl, 167 revlog,
168 index_cutoff, 168 index_cutoff,
169 data_cutoff, 169 data_cutoff,
170 sidedata_cutoff, 170 sidedata_cutoff,
171 ) 171 )
172 172
181 new_sidedata_file, 181 new_sidedata_file,
182 ) = open_files 182 ) = open_files
183 183
184 # writing the censored revision 184 # writing the censored revision
185 _rewrite_censor( 185 _rewrite_censor(
186 rl, 186 revlog,
187 old_index, 187 old_index,
188 open_files, 188 open_files,
189 censor_rev, 189 censor_rev,
190 tombstone, 190 tombstone,
191 ) 191 )
192 192
193 # Writing all subsequent revisions 193 # Writing all subsequent revisions
194 for rev in range(censor_rev + 1, len(old_index)): 194 for rev in range(censor_rev + 1, len(old_index)):
195 _rewrite_simple( 195 _rewrite_simple(
196 rl, 196 revlog,
197 old_index, 197 old_index,
198 open_files, 198 open_files,
199 rev, 199 rev,
200 rewritten_entries, 200 rewritten_entries,
201 tmp_storage, 201 tmp_storage,