# HG changeset patch # User Gregory Szorc <gregory.sz...@gmail.com> # Date 1480041290 28800 # Thu Nov 24 18:34:50 2016 -0800 # Node ID 96b6f747358116643b039d9c91157cde27106662 # Parent 01fe6742b8df6a5d832096291267366cf5ae9da2 repair: copy non-revlog store files during upgrade
The store contains more than just revlogs. This patch teaches the upgrade code to copy regular files as well. As the test changes demonstrate, the phaseroots file is now copied. diff --git a/mercurial/repair.py b/mercurial/repair.py --- a/mercurial/repair.py +++ b/mercurial/repair.py @@ -10,6 +10,7 @@ from __future__ import absolute_import import errno import hashlib +import stat import tempfile import time @@ -801,6 +802,44 @@ def _copyrevlogs(ui, srcrepo, dstrepo, t ui.write(_('finished migrating %d total revisions; total change in store ' 'size: %s\n') % (revcount, util.bytecount(dstsize - srcsize))) +def _upgradefilterstorefile(srcrepo, dstrepo, requirements, path, mode, st): + """Determine whether to copy a store file during upgrade. + + This function is called when migrating store files from ``srcrepo`` to + ``dstrepo`` as part of upgrading a repository. + + Args: + srcrepo: repo we are copying from + dstrepo: repo we are copying to + requirements: set of requirements for ``dstrepo`` + path: store file being examined + mode: the ``ST_MODE`` file type of ``path`` + st: ``stat`` data structure for ``path`` + + Function should return ``True`` if the file is to be copied. + """ + # Skip revlogs. + if path.endswith(('.i', '.d')): + return False + # Skip transaction related files. + if path.startswith('undo'): + return False + # Only copy regular files. + if mode != stat.S_IFREG: + return False + # Skip other skipped files. + if path in ('lock', 'fncache'): + return False + + return True + +def _upgradefinishdatamigration(ui, srcrepo, dstrepo, requirements): + """Hook point for extensions to perform additional actions during upgrade. + + This function is called after revlogs and store files have been copied but + before the new store is swapped into the original location. + """ + def _upgraderepo(ui, srcrepo, dstrepo, requirements, actions): """Do the low-level work of upgrading a repository. @@ -830,7 +869,18 @@ def _upgraderepo(ui, srcrepo, dstrepo, r _copyrevlogs(ui, srcrepo, dstrepo, tr, deltareuse, 'redeltamultibase' in actions) - # TODO copy non-revlog store files + # Now copy other files in the store directory. + for p, kind, st in srcrepo.store.vfs.readdir('', stat=True): + if not _upgradefilterstorefile(srcrepo, dstrepo, requirements, + p, kind, st): + continue + + srcrepo.ui.write(_('copying %s\n') % p) + src = srcrepo.store.vfs.join(p) + dst = dstrepo.store.vfs.join(p) + util.copyfile(src, dst, copystat=True) + + _upgradefinishdatamigration(ui, srcrepo, dstrepo, requirements) ui.write(_('data fully migrated to temporary repository\n')) diff --git a/tests/test-upgrade-repo.t b/tests/test-upgrade-repo.t --- a/tests/test-upgrade-repo.t +++ b/tests/test-upgrade-repo.t @@ -241,6 +241,7 @@ Upgrading a repository to generaldelta w migrating changelog containing 3 revisions (184 bytes in store; 181 bytes tracked data) finished migrating 3 changelog revisions; change in size: 0 bytes finished migrating 9 total revisions; total change in store size: 0 bytes + copying phaseroots data fully migrated to temporary repository marking source repository as being upgraded; clients will be unable to read from repository starting in-place swap of repository data @@ -276,6 +277,7 @@ store directory has files we expect 00manifest.i data fncache + phaseroots undo undo.backupfiles undo.phaseroots _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel