Mercurial > public > mercurial-scm > hg
comparison mercurial/upgrade_utils/engine.py @ 46229:52abb1af2995
engine: prevent a function call for each store file
Python function calls are not cheap. Instead of calling the function once for
each file in store, we use a dedicated function which filters and yields the
required files.
Differential Revision: https://phab.mercurial-scm.org/D9673
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Thu, 31 Dec 2020 14:28:00 +0530 |
parents | e22aed089567 |
children | 8023991dc811 |
comparison
equal
deleted
inserted
replaced
46228:e73b40c790ec | 46229:52abb1af2995 |
---|---|
374 ) | 374 ) |
375 % (revcount, util.bytecount(dstsize - srcsize)) | 375 % (revcount, util.bytecount(dstsize - srcsize)) |
376 ) | 376 ) |
377 | 377 |
378 | 378 |
379 def _filterstorefile(srcrepo, dstrepo, requirements, path, mode, st): | 379 def _files_to_copy_post_revlog_clone(srcrepo): |
380 """Determine whether to copy a store file during upgrade. | 380 """yields files which should be copied to destination after revlogs |
381 | 381 are cloned""" |
382 This function is called when migrating store files from ``srcrepo`` to | 382 for path, kind, st in sorted(srcrepo.store.vfs.readdir(b'', stat=True)): |
383 ``dstrepo`` as part of upgrading a repository. | 383 # don't copy revlogs as they are already cloned |
384 | 384 if path.endswith((b'.i', b'.d', b'.n', b'.nd')): |
385 Args: | 385 continue |
386 srcrepo: repo we are copying from | 386 # Skip transaction related files. |
387 dstrepo: repo we are copying to | 387 if path.startswith(b'undo'): |
388 requirements: set of requirements for ``dstrepo`` | 388 continue |
389 path: store file being examined | 389 # Only copy regular files. |
390 mode: the ``ST_MODE`` file type of ``path`` | 390 if kind != stat.S_IFREG: |
391 st: ``stat`` data structure for ``path`` | 391 continue |
392 | 392 # Skip other skipped files. |
393 Function should return ``True`` if the file is to be copied. | 393 if path in (b'lock', b'fncache'): |
394 """ | 394 continue |
395 # Skip revlogs. | 395 # TODO: should we skip cache too? |
396 if path.endswith((b'.i', b'.d', b'.n', b'.nd')): | 396 |
397 return False | 397 yield path |
398 # Skip transaction related files. | |
399 if path.startswith(b'undo'): | |
400 return False | |
401 # Only copy regular files. | |
402 if mode != stat.S_IFREG: | |
403 return False | |
404 # Skip other skipped files. | |
405 if path in (b'lock', b'fncache'): | |
406 return False | |
407 | |
408 return True | |
409 | 398 |
410 | 399 |
411 def _replacestores(currentrepo, upgradedrepo, backupvfs, upgrade_op): | 400 def _replacestores(currentrepo, upgradedrepo, backupvfs, upgrade_op): |
412 """Replace the stores after current repository is upgraded | 401 """Replace the stores after current repository is upgraded |
413 | 402 |
463 tr, | 452 tr, |
464 upgrade_op, | 453 upgrade_op, |
465 ) | 454 ) |
466 | 455 |
467 # Now copy other files in the store directory. | 456 # Now copy other files in the store directory. |
468 # The sorted() makes execution deterministic. | 457 for p in _files_to_copy_post_revlog_clone(srcrepo): |
469 for p, kind, st in sorted(srcrepo.store.vfs.readdir(b'', stat=True)): | |
470 if not _filterstorefile( | |
471 srcrepo, dstrepo, upgrade_op.new_requirements, p, kind, st | |
472 ): | |
473 continue | |
474 | |
475 srcrepo.ui.status(_(b'copying %s\n') % p) | 458 srcrepo.ui.status(_(b'copying %s\n') % p) |
476 src = srcrepo.store.rawvfs.join(p) | 459 src = srcrepo.store.rawvfs.join(p) |
477 dst = dstrepo.store.rawvfs.join(p) | 460 dst = dstrepo.store.rawvfs.join(p) |
478 util.copyfile(src, dst, copystat=True) | 461 util.copyfile(src, dst, copystat=True) |
479 | 462 |