[PATCH 2 of 6] upgrade: use the repository 'ui' as the base for the new repository

Boris Feld boris.feld at octobus.net
Fri Dec 8 11:19:16 UTC 2017


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1512669335 -3600
#      Thu Dec 07 18:55:35 2017 +0100
# Node ID 2c12e70358f6754054becbf4c016ef5ca2bedddb
# Parent  90a8cc66a579cf9122e8fef91e4bc1f48062ff60
# EXP-Topic upgrade.config
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 2c12e70358f6
upgrade: use the repository 'ui' as the base for the new repository

The `repo.baseui` contains all the configuration but the one specific to the
repository (so it can be used when dealing with local peer and sub-
repository). However, we need the repository config to be taken into account
when doing the upgrade. Otherwise, the upgrade related config that exists in
the repository config won't be taken into account when performing the update.
A buggy and surprising behavior.

We had to work around protection set around `repo.ui.copy` since we are an
uncommon case.

diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -830,9 +830,22 @@ def upgraderepo(ui, repo, run=False, opt
         try:
             ui.write(_('creating temporary repository to stage migrated '
                        'data: %s\n') % tmppath)
-            dstrepo = localrepo.localrepository(repo.baseui,
-                                                path=tmppath,
-                                                create=True)
+
+            # repo.ui is protected against copy:
+            #
+            # running `repo.ui.copy` actually call `repo.baseui.copy`. Here, we
+            # -really- wants to copy the actual `repo.ui` object (since we
+            # create a copy of the repository).
+            #
+            # We have to work around the protection.
+            oldcopy = repo.ui.copy
+            try:
+                repo.ui.__dict__.pop('copy', None)
+                dstrepo = localrepo.localrepository(repo.ui,
+                                                    path=tmppath,
+                                                    create=True)
+            finally:
+                repo.ui.copy = oldcopy
 
             with dstrepo.wlock(), dstrepo.lock():
                 backuppath = _upgraderepo(ui, repo, dstrepo, newreqs,
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
@@ -531,12 +531,12 @@ repository config is taken in account
   migrating 9 total revisions (3 in filelogs, 3 in manifests, 3 in changelog)
   migrating 497 bytes in store; 882 bytes tracked data
   migrating 1 filelogs containing 3 revisions (182 bytes in store; 573 bytes tracked data)
-  finished migrating 3 filelog revisions across 1 filelogs; change in size: 0 bytes
+  finished migrating 3 filelog revisions across 1 filelogs; change in size: -63 bytes
   migrating 1 manifests containing 3 revisions (141 bytes in store; 138 bytes tracked data)
   finished migrating 3 manifest revisions across 1 manifests; change in size: 0 bytes
   migrating changelog containing 3 revisions (174 bytes in store; 171 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
+  finished migrating 9 total revisions; total change in store size: -63 bytes
   copying phaseroots
   data fully migrated to temporary repository
   marking source repository as being upgraded; clients will be unable to read from repository
@@ -552,7 +552,7 @@ repository config is taken in account
      rev    offset  length  delta linkrev nodeid       p1           p2
        0         0      77     -1       0 bcc1d3df78b2 000000000000 000000000000
        1        77      21      0       1 af3e29f7a72e bcc1d3df78b2 000000000000
-       2        98      84     -1       2 8daf79c5522b af3e29f7a72e 000000000000
+       2        98      21      1       2 8daf79c5522b af3e29f7a72e 000000000000
   $ cd ..
 
   $ cat << EOF >> $HGRCPATH



More information about the Mercurial-devel mailing list