Rev 4406: (jam) BzrDirFormat1.require_stacking upgrades the branch separate in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Jun 4 05:59:54 BST 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 4406
revision-id: pqm at pqm.ubuntu.com-20090604045950-80cudgl0j15xtgi2
parent: pqm at pqm.ubuntu.com-20090603232255-k37f1z7z1ohhmklh
parent: john at arbash-meinel.com-20090604021546-n2pgaxdkilitdpq5
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2009-06-04 05:59:50 +0100
message:
  (jam) BzrDirFormat1.require_stacking upgrades the branch separate
  	from the repo.
modified:
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  bzrlib/tests/blackbox/test_branch.py test_branch.py-20060524161337-noms9gmcwqqrfi8y-1
  bzrlib/tests/per_repository_reference/test_initialize.py test_initialize.py-20090527083941-4rz2urcthjet5e2i-1
    ------------------------------------------------------------
    revno: 4401.1.4
    revision-id: john at arbash-meinel.com-20090604021546-n2pgaxdkilitdpq5
    parent: john at arbash-meinel.com-20090603200355-pklx5ak2o98cizvf
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: 1.16-remote-format-stacking
    timestamp: Wed 2009-06-03 21:15:46 -0500
    message:
      Per Andrew's good advice, use possible_transports=None
    modified:
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
    ------------------------------------------------------------
    revno: 4401.1.3
    revision-id: john at arbash-meinel.com-20090603200355-pklx5ak2o98cizvf
    parent: john at arbash-meinel.com-20090603182221-0oauceo6yt59a08y
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: 1.16-remote-format-stacking
    timestamp: Wed 2009-06-03 15:03:55 -0500
    message:
      Change back to defaulting to --1.6 format, and update the blackbox tests.
    modified:
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
      bzrlib/tests/blackbox/test_branch.py test_branch.py-20060524161337-noms9gmcwqqrfi8y-1
    ------------------------------------------------------------
    revno: 4401.1.2
    revision-id: john at arbash-meinel.com-20090603182221-0oauceo6yt59a08y
    parent: john at arbash-meinel.com-20090603180853-6292ohmtj1gsiew1
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: 1.16-remote-format-stacking
    timestamp: Wed 2009-06-03 13:22:21 -0500
    message:
      Move the logic back up into BzrDirFormat1.require_stacking, passing in the extra params.
      This gives us a single location where formats are hard-coded
      it also means that 'bzr branch --stacked' can preserve the repository
      format, even when the Branch format is 'too old'. (Such as when you
      convert a repo, and don't convert all of the contained branches.)
    modified:
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
    ------------------------------------------------------------
    revno: 4401.1.1
    revision-id: john at arbash-meinel.com-20090603180853-6292ohmtj1gsiew1
    parent: pqm at pqm.ubuntu.com-20090603080435-2gbqwzvbx31zr7ok
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: 1.16-remote-format-stacking
    timestamp: Wed 2009-06-03 13:08:53 -0500
    message:
      Split out the auto-upgrade logic inside CreateRepository.acquire_repository.
      
      Instead of always upgrading the repo format *and* the branch format, now we only upgrade
      the repo if it doesn't support stacking, and only upgrade the branch if *it*
      doesn't support stacking.
      It is a bit of an end-run around the fact that initialize_on_transport_ex
      tries to set a repository format but *doesn't* set a branch format, and then
      goes on to create a repo which wants to know what branch format it would create.
      Which causes it to revert to the default branch format which doesn't support
      stacking.
      
      At least it works.
    modified:
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
      bzrlib/tests/per_repository_reference/test_initialize.py test_initialize.py-20090527083941-4rz2urcthjet5e2i-1
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2009-06-03 04:42:02 +0000
+++ b/bzrlib/bzrdir.py	2009-06-04 02:15:46 +0000
@@ -2358,26 +2358,95 @@
     def set_branch_format(self, format):
         self._branch_format = format
 
-    def require_stacking(self):
+    def require_stacking(self, stack_on=None, possible_transports=None):
+        """We have a request to stack, try to ensure the formats support it.
+
+        :param stack_on: If supplied, it is the URL to a branch that we want to
+            stack on. Check to see if that format supports stacking before
+            forcing an upgrade.
+        """
+        # Stacking is desired. requested by the target, but does the place it
+        # points at support stacking? If it doesn't then we should
+        # not implicitly upgrade. We check this here.
+        new_repo_format = None
+        new_branch_format = None
+
+        # a bit of state for get_target_branch so that we don't try to open it
+        # 2 times, for both repo *and* branch
+        target = [None, False, None] # target_branch, checked, upgrade anyway
+        def get_target_branch():
+            if target[1]:
+                # We've checked, don't check again
+                return target
+            if stack_on is None:
+                # No target format, that means we want to force upgrading
+                target[:] = [None, True, True]
+                return target
+            try:
+                target_dir = BzrDir.open(stack_on,
+                    possible_transports=possible_transports)
+            except errors.NotBranchError:
+                # Nothing there, don't change formats
+                target[:] = [None, True, False]
+                return target
+            except errors.JailBreak:
+                # JailBreak, JFDI and upgrade anyway
+                target[:] = [None, True, True]
+                return target
+            try:
+                target_branch = target_dir.open_branch()
+            except errors.NotBranchError:
+                # No branch, don't upgrade formats
+                target[:] = [None, True, False]
+                return target
+            target[:] = [target_branch, True, False]
+            return target
+
+        if not (self.repository_format.supports_external_lookups):
+            # We need to upgrade the Repository.
+            target_branch, _, do_upgrade = get_target_branch()
+            if target_branch is None:
+                # We don't have a target branch, should we upgrade anyway?
+                if do_upgrade:
+                    # stack_on is inaccessible, JFDI.
+                    # TODO: bad monkey, hard-coded formats...
+                    if self.repository_format.rich_root_data:
+                        new_repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
+                    else:
+                        new_repo_format = pack_repo.RepositoryFormatKnitPack5()
+            else:
+                # If the target already supports stacking, then we know the
+                # project is already able to use stacking, so auto-upgrade
+                # for them
+                new_repo_format = target_branch.repository._format
+                if not new_repo_format.supports_external_lookups:
+                    # target doesn't, source doesn't, so don't auto upgrade
+                    # repo
+                    new_repo_format = None
+            if new_repo_format is not None:
+                self.repository_format = new_repo_format
+                note('Source repository format does not support stacking,'
+                     ' using format:\n  %s',
+                     new_repo_format.get_format_description())
+
         if not self.get_branch_format().supports_stacking():
-            # We need to make a stacked branch, but the default format for the
-            # target doesn't support stacking.  So force a branch that *can*
-            # support stacking.
-            from bzrlib.branch import BzrBranchFormat7
-            branch_format = BzrBranchFormat7()
-            self.set_branch_format(branch_format)
-            mutter("using %r for stacking" % (branch_format,))
-            from bzrlib.repofmt import pack_repo
-            if self.repository_format.rich_root_data:
-                bzrdir_format_name = '1.6.1-rich-root'
-                repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
+            # We just checked the repo, now lets check if we need to
+            # upgrade the branch format
+            target_branch, _, do_upgrade = get_target_branch()
+            if target_branch is None:
+                if do_upgrade:
+                    # TODO: bad monkey, hard-coded formats...
+                    new_branch_format = branch.BzrBranchFormat7()
             else:
-                bzrdir_format_name = '1.6'
-                repo_format = pack_repo.RepositoryFormatKnitPack5()
-            note('Source format does not support stacking, using format:'
-                 ' \'%s\'\n  %s\n',
-                 bzrdir_format_name, repo_format.get_format_description())
-            self.repository_format = repo_format
+                new_branch_format = target_branch._format
+                if not new_branch_format.supports_stacking():
+                    new_branch_format = None
+            if new_branch_format is not None:
+                # Does support stacking, use its format.
+                self.set_branch_format(new_branch_format)
+                note('Source branch format does not support stacking,'
+                     ' using format:\n  %s',
+                     new_branch_format.get_format_description())
 
     def get_converter(self, format=None):
         """See BzrDirFormat.get_converter()."""
@@ -3532,54 +3601,9 @@
         """
         stack_on = self._get_full_stack_on()
         if stack_on:
-            # Stacking is desired. requested by the target, but does the place it
-            # points at support stacking? If it doesn't then we should
-            # not implicitly upgrade. We check this here.
             format = self._bzrdir._format
-            if not (format.repository_format.supports_external_lookups
-                and format.get_branch_format().supports_stacking()):
-                # May need to upgrade - but only do if the target also
-                # supports stacking. Note that this currently wastes
-                # network round trips to check - but we only do this
-                # when the source can't stack so it will fade away
-                # as people do upgrade.
-                branch_format = None
-                repo_format = None
-                try:
-                    target_dir = BzrDir.open(stack_on,
-                        possible_transports=[self._bzrdir.root_transport])
-                except errors.NotBranchError:
-                    # Nothing there, don't change formats
-                    pass
-                except errors.JailBreak:
-                    # stack_on is inaccessible, JFDI.
-                    if format.repository_format.rich_root_data:
-                        repo_format = pack_repo.RepositoryFormatKnitPack6RichRoot()
-                    else:
-                        repo_format = pack_repo.RepositoryFormatKnitPack6()
-                    branch_format = branch.BzrBranchFormat7()
-                else:
-                    try:
-                        target_branch = target_dir.open_branch()
-                    except errors.NotBranchError:
-                        # No branch, don't change formats
-                        pass
-                    else:
-                        branch_format = target_branch._format
-                        repo_format = target_branch.repository._format
-                        if not (branch_format.supports_stacking()
-                            and repo_format.supports_external_lookups):
-                            # Doesn't stack itself, don't force an upgrade
-                            branch_format = None
-                            repo_format = None
-                if branch_format and repo_format:
-                    # Does support stacking, use its format.
-                    format.repository_format = repo_format
-                    format.set_branch_format(branch_format)
-                    note('Source format does not support stacking, '
-                        'using format: \'%s\'\n  %s\n',
-                        branch_format.get_format_description(),
-                        repo_format.get_format_description())
+            format.require_stacking(stack_on=stack_on,
+                                    possible_transports=[self._bzrdir.root_transport])
             if not self._require_stacking:
                 # We have picked up automatic stacking somewhere.
                 note('Using default stacking branch %s at %s', self._stack_on,

=== modified file 'bzrlib/tests/blackbox/test_branch.py'
--- a/bzrlib/tests/blackbox/test_branch.py	2009-04-15 04:45:06 +0000
+++ b/bzrlib/tests/blackbox/test_branch.py	2009-06-03 20:03:55 +0000
@@ -237,9 +237,10 @@
             ['branch', '--stacked', 'trunk', 'shallow'])
         # We should notify the user that we upgraded their format
         self.assertEqualDiff(
-            'Source format does not support stacking, using format: \'1.6\'\n'
+            'Source repository format does not support stacking, using format:\n'
             '  Packs 5 (adds stacking support, requires bzr 1.6)\n'
-            '\n'
+            'Source branch format does not support stacking, using format:\n'
+            '  Branch format 7\n'
             'Created new stacked branch referring to %s.\n' % (trunk.base,),
             err)
 
@@ -249,10 +250,10 @@
             ['branch', '--stacked', 'trunk', 'shallow'])
         # We should notify the user that we upgraded their format
         self.assertEqualDiff(
-            'Source format does not support stacking, using format:'
-            ' \'1.6.1-rich-root\'\n'
+            'Source repository format does not support stacking, using format:\n'
             '  Packs 5 rich-root (adds stacking support, requires bzr 1.6.1)\n'
-            '\n'
+            'Source branch format does not support stacking, using format:\n'
+            '  Branch format 7\n'
             'Created new stacked branch referring to %s.\n' % (trunk.base,),
             err)
 

=== modified file 'bzrlib/tests/per_repository_reference/test_initialize.py'
--- a/bzrlib/tests/per_repository_reference/test_initialize.py	2009-05-29 09:56:12 +0000
+++ b/bzrlib/tests/per_repository_reference/test_initialize.py	2009-06-03 18:08:53 +0000
@@ -52,8 +52,4 @@
         trans = self.make_smart_server('stacked')
         repo = self.initialize_and_check_on_transport(base, trans)
         network_name = base.repository._format.network_name()
-        if network_name != repo._format.network_name():
-            raise tests.KnownFailure('Remote initialize_on_transport_ex()'
-                ' tries to "upgrade" the format because it doesn\'t have a'
-                ' branch format, and hard-codes the new repository format.')
         self.assertEqual(network_name, repo._format.network_name())




More information about the bazaar-commits mailing list