Mercurial > hg
comparison mercurial/upgrade_utils/engine.py @ 46194:4d1cec4e5e1f
engine: unwrap a hard to understand for loop
The loop was iterating over all the datafiles and maintaining a set to check
whether filelogs have been processed, manifests have been processed or not.
The code was hard to understand and it assumed that `alldatafiles` are ordered
in a certain way.
This refactors the for loop in separate parts for each manifests, changelog and
filelogs. This will also help in future work where we will like more better
handling on whether we want to upgrade filelogs or not.
Differential Revision: https://phab.mercurial-scm.org/D9580
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Mon, 14 Dec 2020 14:38:01 +0530 |
parents | 85f7cf314b39 |
children | 6b40aac4da8e |
comparison
equal
deleted
inserted
replaced
46193:85f7cf314b39 | 46194:4d1cec4e5e1f |
---|---|
182 csrcsize = 0 | 182 csrcsize = 0 |
183 crawsize = 0 | 183 crawsize = 0 |
184 cdstsize = 0 | 184 cdstsize = 0 |
185 | 185 |
186 alldatafiles = list(srcrepo.store.walk()) | 186 alldatafiles = list(srcrepo.store.walk()) |
187 # mapping of data files which needs to be cloned | |
188 # key is unencoded filename | |
189 # value is revlog_object_from_srcrepo | |
190 manifests = {} | |
191 changelogs = {} | |
192 filelogs = {} | |
187 | 193 |
188 # Perform a pass to collect metadata. This validates we can open all | 194 # Perform a pass to collect metadata. This validates we can open all |
189 # source files and allows a unified progress bar to be displayed. | 195 # source files and allows a unified progress bar to be displayed. |
190 for unencoded, encoded, size in alldatafiles: | 196 for unencoded, encoded, size in alldatafiles: |
191 if unencoded.endswith(b'.d'): | 197 if unencoded.endswith(b'.d'): |
207 srcsize += datasize | 213 srcsize += datasize |
208 srcrawsize += rawsize | 214 srcrawsize += rawsize |
209 | 215 |
210 # This is for the separate progress bars. | 216 # This is for the separate progress bars. |
211 if isinstance(rl, changelog.changelog): | 217 if isinstance(rl, changelog.changelog): |
218 changelogs[unencoded] = rl | |
212 crevcount += len(rl) | 219 crevcount += len(rl) |
213 csrcsize += datasize | 220 csrcsize += datasize |
214 crawsize += rawsize | 221 crawsize += rawsize |
215 elif isinstance(rl, manifest.manifestrevlog): | 222 elif isinstance(rl, manifest.manifestrevlog): |
223 manifests[unencoded] = rl | |
216 mcount += 1 | 224 mcount += 1 |
217 mrevcount += len(rl) | 225 mrevcount += len(rl) |
218 msrcsize += datasize | 226 msrcsize += datasize |
219 mrawsize += rawsize | 227 mrawsize += rawsize |
220 elif isinstance(rl, filelog.filelog): | 228 elif isinstance(rl, filelog.filelog): |
229 filelogs[unencoded] = rl | |
221 fcount += 1 | 230 fcount += 1 |
222 frevcount += len(rl) | 231 frevcount += len(rl) |
223 fsrcsize += datasize | 232 fsrcsize += datasize |
224 frawsize += rawsize | 233 frawsize += rawsize |
225 else: | 234 else: |
246 def oncopiedrevision(rl, rev, node): | 255 def oncopiedrevision(rl, rev, node): |
247 progress.increment() | 256 progress.increment() |
248 | 257 |
249 sidedatacompanion = getsidedatacompanion(srcrepo, dstrepo) | 258 sidedatacompanion = getsidedatacompanion(srcrepo, dstrepo) |
250 | 259 |
251 # Do the actual copying. | 260 # Migrating filelogs |
252 # FUTURE this operation can be farmed off to worker processes. | 261 ui.status( |
253 seen = set() | 262 _( |
254 for unencoded, encoded, size in alldatafiles: | 263 b'migrating %d filelogs containing %d revisions ' |
255 if unencoded.endswith(b'.d'): | 264 b'(%s in store; %s tracked data)\n' |
256 continue | 265 ) |
257 | 266 % ( |
258 oldrl = _revlogfrompath(srcrepo, unencoded) | 267 fcount, |
259 | 268 frevcount, |
260 if isinstance(oldrl, changelog.changelog) and b'c' not in seen: | 269 util.bytecount(fsrcsize), |
261 ui.status( | 270 util.bytecount(frawsize), |
262 _( | 271 ) |
263 b'finished migrating %d manifest revisions across %d ' | 272 ) |
264 b'manifests; change in size: %s\n' | 273 progress = srcrepo.ui.makeprogress(_(b'file revisions'), total=frevcount) |
265 ) | 274 for unencoded, oldrl in sorted(filelogs.items()): |
266 % (mrevcount, mcount, util.bytecount(mdstsize - msrcsize)) | |
267 ) | |
268 | |
269 ui.status( | |
270 _( | |
271 b'migrating changelog containing %d revisions ' | |
272 b'(%s in store; %s tracked data)\n' | |
273 ) | |
274 % ( | |
275 crevcount, | |
276 util.bytecount(csrcsize), | |
277 util.bytecount(crawsize), | |
278 ) | |
279 ) | |
280 seen.add(b'c') | |
281 progress = srcrepo.ui.makeprogress( | |
282 _(b'changelog revisions'), total=crevcount | |
283 ) | |
284 elif isinstance(oldrl, manifest.manifestrevlog) and b'm' not in seen: | |
285 ui.status( | |
286 _( | |
287 b'finished migrating %d filelog revisions across %d ' | |
288 b'filelogs; change in size: %s\n' | |
289 ) | |
290 % (frevcount, fcount, util.bytecount(fdstsize - fsrcsize)) | |
291 ) | |
292 | |
293 ui.status( | |
294 _( | |
295 b'migrating %d manifests containing %d revisions ' | |
296 b'(%s in store; %s tracked data)\n' | |
297 ) | |
298 % ( | |
299 mcount, | |
300 mrevcount, | |
301 util.bytecount(msrcsize), | |
302 util.bytecount(mrawsize), | |
303 ) | |
304 ) | |
305 seen.add(b'm') | |
306 if progress: | |
307 progress.complete() | |
308 progress = srcrepo.ui.makeprogress( | |
309 _(b'manifest revisions'), total=mrevcount | |
310 ) | |
311 elif b'f' not in seen: | |
312 ui.status( | |
313 _( | |
314 b'migrating %d filelogs containing %d revisions ' | |
315 b'(%s in store; %s tracked data)\n' | |
316 ) | |
317 % ( | |
318 fcount, | |
319 frevcount, | |
320 util.bytecount(fsrcsize), | |
321 util.bytecount(frawsize), | |
322 ) | |
323 ) | |
324 seen.add(b'f') | |
325 if progress: | |
326 progress.complete() | |
327 progress = srcrepo.ui.makeprogress( | |
328 _(b'file revisions'), total=frevcount | |
329 ) | |
330 | |
331 newrl = _perform_clone( | 275 newrl = _perform_clone( |
332 ui, | 276 ui, |
333 dstrepo, | 277 dstrepo, |
334 tr, | 278 tr, |
335 oldrl, | 279 oldrl, |
340 sidedatacompanion, | 284 sidedatacompanion, |
341 oncopiedrevision, | 285 oncopiedrevision, |
342 ) | 286 ) |
343 info = newrl.storageinfo(storedsize=True) | 287 info = newrl.storageinfo(storedsize=True) |
344 datasize = info[b'storedsize'] or 0 | 288 datasize = info[b'storedsize'] or 0 |
345 | |
346 dstsize += datasize | 289 dstsize += datasize |
347 | 290 fdstsize += datasize |
348 if isinstance(newrl, changelog.changelog): | 291 ui.status( |
349 cdstsize += datasize | 292 _( |
350 elif isinstance(newrl, manifest.manifestrevlog): | 293 b'finished migrating %d filelog revisions across %d ' |
351 mdstsize += datasize | 294 b'filelogs; change in size: %s\n' |
352 else: | 295 ) |
353 fdstsize += datasize | 296 % (frevcount, fcount, util.bytecount(fdstsize - fsrcsize)) |
354 | 297 ) |
298 | |
299 # Migrating manifests | |
300 ui.status( | |
301 _( | |
302 b'migrating %d manifests containing %d revisions ' | |
303 b'(%s in store; %s tracked data)\n' | |
304 ) | |
305 % ( | |
306 mcount, | |
307 mrevcount, | |
308 util.bytecount(msrcsize), | |
309 util.bytecount(mrawsize), | |
310 ) | |
311 ) | |
312 if progress: | |
313 progress.complete() | |
314 progress = srcrepo.ui.makeprogress( | |
315 _(b'manifest revisions'), total=mrevcount | |
316 ) | |
317 for unencoded, oldrl in sorted(manifests.items()): | |
318 newrl = _perform_clone( | |
319 ui, | |
320 dstrepo, | |
321 tr, | |
322 oldrl, | |
323 unencoded, | |
324 deltareuse, | |
325 forcedeltabothparents, | |
326 revlogs, | |
327 sidedatacompanion, | |
328 oncopiedrevision, | |
329 ) | |
330 info = newrl.storageinfo(storedsize=True) | |
331 datasize = info[b'storedsize'] or 0 | |
332 dstsize += datasize | |
333 mdstsize += datasize | |
334 ui.status( | |
335 _( | |
336 b'finished migrating %d manifest revisions across %d ' | |
337 b'manifests; change in size: %s\n' | |
338 ) | |
339 % (mrevcount, mcount, util.bytecount(mdstsize - msrcsize)) | |
340 ) | |
341 | |
342 # Migrating changelog | |
343 ui.status( | |
344 _( | |
345 b'migrating changelog containing %d revisions ' | |
346 b'(%s in store; %s tracked data)\n' | |
347 ) | |
348 % ( | |
349 crevcount, | |
350 util.bytecount(csrcsize), | |
351 util.bytecount(crawsize), | |
352 ) | |
353 ) | |
354 if progress: | |
355 progress.complete() | |
356 progress = srcrepo.ui.makeprogress( | |
357 _(b'changelog revisions'), total=crevcount | |
358 ) | |
359 for unencoded, oldrl in sorted(changelogs.items()): | |
360 newrl = _perform_clone( | |
361 ui, | |
362 dstrepo, | |
363 tr, | |
364 oldrl, | |
365 unencoded, | |
366 deltareuse, | |
367 forcedeltabothparents, | |
368 revlogs, | |
369 sidedatacompanion, | |
370 oncopiedrevision, | |
371 ) | |
372 info = newrl.storageinfo(storedsize=True) | |
373 datasize = info[b'storedsize'] or 0 | |
374 dstsize += datasize | |
375 cdstsize += datasize | |
355 progress.complete() | 376 progress.complete() |
356 | |
357 ui.status( | 377 ui.status( |
358 _( | 378 _( |
359 b'finished migrating %d changelog revisions; change in size: ' | 379 b'finished migrating %d changelog revisions; change in size: ' |
360 b'%s\n' | 380 b'%s\n' |
361 ) | 381 ) |