##// END OF EJS Templates
censor: extract the part about creating and opening new files in a function...
marmoute -
r48262:d6afe147 default
parent child Browse files
Show More
@@ -163,55 +163,12 b' def v2_censor(rl, tr, censornode, tombst'
163 tmp_storage,
163 tmp_storage,
164 )
164 )
165
165
166 old_index_filepath = rl.opener.join(docket.index_filepath())
166 all_files = _setup_new_files(
167 old_data_filepath = rl.opener.join(docket.data_filepath())
167 rl,
168 old_sidedata_filepath = rl.opener.join(docket.sidedata_filepath())
168 index_cutoff,
169
169 data_cutoff,
170 new_index_filepath = rl.opener.join(docket.new_index_file())
170 sidedata_cutoff,
171 new_data_filepath = rl.opener.join(docket.new_data_file())
172 new_sidedata_filepath = rl.opener.join(docket.new_sidedata_file())
173
174 util.copyfile(
175 old_index_filepath, new_index_filepath, nb_bytes=index_cutoff
176 )
177 util.copyfile(
178 old_data_filepath, new_data_filepath, nb_bytes=data_cutoff
179 )
180 util.copyfile(
181 old_sidedata_filepath,
182 new_sidedata_filepath,
183 nb_bytes=sidedata_cutoff,
184 )
171 )
185 rl.opener.register_file(docket.index_filepath())
186 rl.opener.register_file(docket.data_filepath())
187 rl.opener.register_file(docket.sidedata_filepath())
188
189 docket.index_end = index_cutoff
190 docket.data_end = data_cutoff
191 docket.sidedata_end = sidedata_cutoff
192
193 # reload the revlog internal information
194 rl.clearcaches()
195 rl._loadindex(docket=docket)
196
197 @contextlib.contextmanager
198 def all_files():
199 # hide opening in an helper function to please check-code, black
200 # and various python ersion at the same time
201 with open(old_data_filepath, 'rb') as old_data_file:
202 with open(old_sidedata_filepath, 'rb') as old_sidedata_file:
203 with open(new_index_filepath, 'r+b') as new_index_file:
204 with open(new_data_filepath, 'r+b') as new_data_file:
205 with open(
206 new_sidedata_filepath, 'r+b'
207 ) as new_sidedata_file:
208 yield (
209 old_data_file,
210 old_sidedata_file,
211 new_index_file,
212 new_data_file,
213 new_sidedata_file,
214 )
215
172
216 # we dont need to open the old index file since its content already
173 # we dont need to open the old index file since its content already
217 # exist in a usable form in `old_index`.
174 # exist in a usable form in `old_index`.
@@ -223,12 +180,6 b' def v2_censor(rl, tr, censornode, tombst'
223 new_data_file,
180 new_data_file,
224 new_sidedata_file,
181 new_sidedata_file,
225 ) = open_files
182 ) = open_files
226 new_index_file.seek(0, os.SEEK_END)
227 assert new_index_file.tell() == index_cutoff
228 new_data_file.seek(0, os.SEEK_END)
229 assert new_data_file.tell() == data_cutoff
230 new_sidedata_file.seek(0, os.SEEK_END)
231 assert new_sidedata_file.tell() == sidedata_cutoff
232
183
233 # writing the censored revision
184 # writing the censored revision
234 _rewrite_censor(
185 _rewrite_censor(
@@ -305,6 +256,80 b' def _precompute_rewritten_delta('
305 return rewritten_entries
256 return rewritten_entries
306
257
307
258
259 def _setup_new_files(
260 revlog,
261 index_cutoff,
262 data_cutoff,
263 sidedata_cutoff,
264 ):
265 """
266
267 return a context manager to open all the relevant files:
268 - old_data_file,
269 - old_sidedata_file,
270 - new_index_file,
271 - new_data_file,
272 - new_sidedata_file,
273
274 The old_index_file is not here because it is accessed through the
275 `old_index` object if the caller function.
276 """
277 docket = revlog._docket
278 old_index_filepath = revlog.opener.join(docket.index_filepath())
279 old_data_filepath = revlog.opener.join(docket.data_filepath())
280 old_sidedata_filepath = revlog.opener.join(docket.sidedata_filepath())
281
282 new_index_filepath = revlog.opener.join(docket.new_index_file())
283 new_data_filepath = revlog.opener.join(docket.new_data_file())
284 new_sidedata_filepath = revlog.opener.join(docket.new_sidedata_file())
285
286 util.copyfile(old_index_filepath, new_index_filepath, nb_bytes=index_cutoff)
287 util.copyfile(old_data_filepath, new_data_filepath, nb_bytes=data_cutoff)
288 util.copyfile(
289 old_sidedata_filepath,
290 new_sidedata_filepath,
291 nb_bytes=sidedata_cutoff,
292 )
293 revlog.opener.register_file(docket.index_filepath())
294 revlog.opener.register_file(docket.data_filepath())
295 revlog.opener.register_file(docket.sidedata_filepath())
296
297 docket.index_end = index_cutoff
298 docket.data_end = data_cutoff
299 docket.sidedata_end = sidedata_cutoff
300
301 # reload the revlog internal information
302 revlog.clearcaches()
303 revlog._loadindex(docket=docket)
304
305 @contextlib.contextmanager
306 def all_files_opener():
307 # hide opening in an helper function to please check-code, black
308 # and various python version at the same time
309 with open(old_data_filepath, 'rb') as old_data_file:
310 with open(old_sidedata_filepath, 'rb') as old_sidedata_file:
311 with open(new_index_filepath, 'r+b') as new_index_file:
312 with open(new_data_filepath, 'r+b') as new_data_file:
313 with open(
314 new_sidedata_filepath, 'r+b'
315 ) as new_sidedata_file:
316 new_index_file.seek(0, os.SEEK_END)
317 assert new_index_file.tell() == index_cutoff
318 new_data_file.seek(0, os.SEEK_END)
319 assert new_data_file.tell() == data_cutoff
320 new_sidedata_file.seek(0, os.SEEK_END)
321 assert new_sidedata_file.tell() == sidedata_cutoff
322 yield (
323 old_data_file,
324 old_sidedata_file,
325 new_index_file,
326 new_data_file,
327 new_sidedata_file,
328 )
329
330 return all_files_opener
331
332
308 def _rewrite_simple(
333 def _rewrite_simple(
309 revlog,
334 revlog,
310 old_index,
335 old_index,
General Comments 0
You need to be logged in to leave comments. Login now