/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Jelmer Vernooij
  • Date: 2009-05-28 16:04:39 UTC
  • mfrom: (4387 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4405.
  • Revision ID: jelmer@samba.org-20090528160439-4z0xlrk5nejobm7q
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 
38
38
import bzrlib
39
39
from bzrlib import (
 
40
    branch,
40
41
    config,
41
42
    errors,
42
43
    graph,
44
45
    lockdir,
45
46
    osutils,
46
47
    remote,
 
48
    repository,
47
49
    revision as _mod_revision,
48
50
    ui,
49
51
    urlutils,
60
62
from bzrlib.push import (
61
63
    PushResult,
62
64
    )
 
65
from bzrlib.repofmt import pack_repo
63
66
from bzrlib.smart.client import _SmartClient
64
67
from bzrlib.store.versioned import WeaveStore
65
68
from bzrlib.transactions import WriteTransaction
178
181
                                       preserve_stacking=preserve_stacking)
179
182
 
180
183
    def clone_on_transport(self, transport, revision_id=None,
181
 
                           force_new_repo=False, preserve_stacking=False,
182
 
                           stacked_on=None):
 
184
        force_new_repo=False, preserve_stacking=False, stacked_on=None,
 
185
        create_prefix=False, use_existing_dir=True):
183
186
        """Clone this bzrdir and its contents to transport verbatim.
184
187
 
185
188
        :param transport: The transport for the location to produce the clone
191
194
                               even if one is available.
192
195
        :param preserve_stacking: When cloning a stacked branch, stack the
193
196
            new branch on top of the other branch's stacked-on branch.
 
197
        :param create_prefix: Create any missing directories leading up to
 
198
            to_transport.
 
199
        :param use_existing_dir: Use an existing directory if one exists.
194
200
        """
195
 
        transport.ensure_base()
 
201
        # Overview: put together a broad description of what we want to end up
 
202
        # with; then make as few api calls as possible to do it.
 
203
        
 
204
        # We may want to create a repo/branch/tree, if we do so what format
 
205
        # would we want for each:
196
206
        require_stacking = (stacked_on is not None)
197
207
        format = self.cloning_metadir(require_stacking)
198
 
        # Bug: We create a metadir without knowing if it can support stacking,
199
 
        # we should look up the policy needs first.
200
 
        result = format.initialize_on_transport(transport)
201
 
        repository_policy = None
 
208
        
 
209
        # Figure out what objects we want:
202
210
        try:
203
211
            local_repo = self.find_repository()
204
212
        except errors.NoRepositoryPresent:
218
226
                        errors.UnstackableRepositoryFormat,
219
227
                        errors.NotStacked):
220
228
                    pass
221
 
 
 
229
        # Bug: We create a metadir without knowing if it can support stacking,
 
230
        # we should look up the policy needs first, or just use it as a hint,
 
231
        # or something.
222
232
        if local_repo:
223
 
            # may need to copy content in
224
 
            repository_policy = result.determine_repository_policy(
225
 
                force_new_repo, stacked_on, self.root_transport.base,
226
 
                require_stacking=require_stacking)
227
233
            make_working_trees = local_repo.make_working_trees()
228
 
            result_repo, is_new_repo = repository_policy.acquire_repository(
229
 
                make_working_trees, local_repo.is_shared())
230
 
            if not require_stacking and repository_policy._require_stacking:
231
 
                require_stacking = True
232
 
                result._format.require_stacking()
233
 
            if is_new_repo and not require_stacking and revision_id is not None:
234
 
                fetch_spec = graph.PendingAncestryResult(
235
 
                    [revision_id], local_repo)
236
 
                result_repo.fetch(local_repo, fetch_spec=fetch_spec)
237
 
            else:
238
 
                result_repo.fetch(local_repo, revision_id=revision_id)
239
 
        else:
240
 
            result_repo = None
 
234
            want_shared = local_repo.is_shared()
 
235
            repo_format_name = format.repository_format.network_name()
 
236
        else:
 
237
            make_working_trees = False
 
238
            want_shared = False
 
239
            repo_format_name = None
 
240
 
 
241
        result_repo, result, require_stacking, repository_policy = \
 
242
            format.initialize_on_transport_ex(transport,
 
243
            use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
244
            force_new_repo=force_new_repo, stacked_on=stacked_on,
 
245
            stack_on_pwd=self.root_transport.base,
 
246
            repo_format_name=repo_format_name,
 
247
            make_working_trees=make_working_trees, shared_repo=want_shared)
 
248
        if repo_format_name:
 
249
            try:
 
250
                # If the result repository is in the same place as the
 
251
                # resulting bzr dir, it will have no content, further if the
 
252
                # result is not stacked then we know all content should be
 
253
                # copied, and finally if we are copying up to a specific
 
254
                # revision_id then we can use the pending-ancestry-result which
 
255
                # does not require traversing all of history to describe it.
 
256
                if (result_repo.bzrdir.root_transport.base ==
 
257
                    result.root_transport.base and not require_stacking and
 
258
                    revision_id is not None):
 
259
                    fetch_spec = graph.PendingAncestryResult(
 
260
                        [revision_id], local_repo)
 
261
                    result_repo.fetch(local_repo, fetch_spec=fetch_spec)
 
262
                else:
 
263
                    result_repo.fetch(local_repo, revision_id=revision_id)
 
264
            finally:
 
265
                result_repo.unlock()
 
266
        else:
 
267
            if result_repo is not None:
 
268
                raise AssertionError('result_repo not None(%r)' % result_repo)
241
269
        # 1 if there is a branch present
242
270
        #   make sure its content is available in the target repository
243
271
        #   clone it.
408
436
            stack_on_pwd = None
409
437
            config = found_bzrdir.get_config()
410
438
            stop = False
411
 
            if config is not None:
412
 
                stack_on = config.get_default_stack_on()
413
 
                if stack_on is not None:
414
 
                    stack_on_pwd = found_bzrdir.root_transport.base
415
 
                    stop = True
 
439
            stack_on = config.get_default_stack_on()
 
440
            if stack_on is not None:
 
441
                stack_on_pwd = found_bzrdir.root_transport.base
 
442
                stop = True
416
443
            # does it have a repository ?
417
444
            try:
418
445
                repository = found_bzrdir.open_repository()
744
771
        raise NotImplementedError(self.get_workingtree_transport)
745
772
 
746
773
    def get_config(self):
747
 
        if getattr(self, '_get_config', None) is None:
748
 
            return None
749
 
        return self._get_config()
 
774
        """Get configuration for this BzrDir."""
 
775
        return config.BzrDirConfig(self)
 
776
 
 
777
    def _get_config(self):
 
778
        """By default, no configuration is available."""
 
779
        return None
750
780
 
751
781
    def __init__(self, _transport, _format):
752
782
        """Initialize a Bzr control dir object.
1065
1095
        """
1066
1096
        format, repository = self._cloning_metadir()
1067
1097
        if format._workingtree_format is None:
 
1098
            # No tree in self.
1068
1099
            if repository is None:
 
1100
                # No repository either
1069
1101
                return format
 
1102
            # We have a repository, so set a working tree? (Why? This seems to
 
1103
            # contradict the stated return value in the docstring).
1070
1104
            tree_format = repository._format._matchingbzrdir.workingtree_format
1071
1105
            format.workingtree_format = tree_format.__class__()
1072
1106
        if require_stacking:
1696
1730
        return format.open(self, _found=True)
1697
1731
 
1698
1732
    def _get_config(self):
1699
 
        return config.BzrDirConfig(self.transport)
 
1733
        return config.TransportConfig(self.transport, 'control.conf')
1700
1734
 
1701
1735
 
1702
1736
class BzrDirFormat(object):
1797
1831
    def initialize(self, url, possible_transports=None):
1798
1832
        """Create a bzr control dir at this url and return an opened copy.
1799
1833
 
 
1834
        While not deprecated, this method is very specific and its use will
 
1835
        lead to many round trips to setup a working environment. See
 
1836
        initialize_on_transport_ex for a [nearly] all-in-one method.
 
1837
 
1800
1838
        Subclasses should typically override initialize_on_transport
1801
1839
        instead of this method.
1802
1840
        """
1821
1859
            self._supply_sub_formats_to(remote_format)
1822
1860
            return remote_format.initialize_on_transport(transport)
1823
1861
 
 
1862
    def initialize_on_transport_ex(self, transport, use_existing_dir=False,
 
1863
        create_prefix=False, force_new_repo=False, stacked_on=None,
 
1864
        stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
 
1865
        shared_repo=False, vfs_only=False):
 
1866
        """Create this format on transport.
 
1867
 
 
1868
        The directory to initialize will be created.
 
1869
 
 
1870
        :param force_new_repo: Do not use a shared repository for the target,
 
1871
                               even if one is available.
 
1872
        :param create_prefix: Create any missing directories leading up to
 
1873
            to_transport.
 
1874
        :param use_existing_dir: Use an existing directory if one exists.
 
1875
        :param stacked_on: A url to stack any created branch on, None to follow
 
1876
            any target stacking policy.
 
1877
        :param stack_on_pwd: If stack_on is relative, the location it is
 
1878
            relative to.
 
1879
        :param repo_format_name: If non-None, a repository will be
 
1880
            made-or-found. Should none be found, or if force_new_repo is True
 
1881
            the repo_format_name is used to select the format of repository to
 
1882
            create.
 
1883
        :param make_working_trees: Control the setting of make_working_trees
 
1884
            for a new shared repository when one is made. None to use whatever
 
1885
            default the format has.
 
1886
        :param shared_repo: Control whether made repositories are shared or
 
1887
            not.
 
1888
        :param vfs_only: If True do not attempt to use a smart server
 
1889
        :return: repo, bzrdir, require_stacking, repository_policy. repo is
 
1890
            None if none was created or found, bzrdir is always valid.
 
1891
            require_stacking is the result of examining the stacked_on
 
1892
            parameter and any stacking policy found for the target.
 
1893
        """
 
1894
        if not vfs_only:
 
1895
            # Try to hand off to a smart server 
 
1896
            try:
 
1897
                client_medium = transport.get_smart_medium()
 
1898
            except errors.NoSmartMedium:
 
1899
                pass
 
1900
            else:
 
1901
                # TODO: lookup the local format from a server hint.
 
1902
                remote_dir_format = RemoteBzrDirFormat()
 
1903
                remote_dir_format._network_name = self.network_name()
 
1904
                self._supply_sub_formats_to(remote_dir_format)
 
1905
                return remote_dir_format.initialize_on_transport_ex(transport,
 
1906
                    use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
1907
                    force_new_repo=force_new_repo, stacked_on=stacked_on,
 
1908
                    stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
 
1909
                    make_working_trees=make_working_trees, shared_repo=shared_repo)
 
1910
        # XXX: Refactor the create_prefix/no_create_prefix code into a
 
1911
        #      common helper function
 
1912
        # The destination may not exist - if so make it according to policy.
 
1913
        def make_directory(transport):
 
1914
            transport.mkdir('.')
 
1915
            return transport
 
1916
        def redirected(transport, e, redirection_notice):
 
1917
            note(redirection_notice)
 
1918
            return transport._redirected_to(e.source, e.target)
 
1919
        try:
 
1920
            transport = do_catching_redirections(make_directory, transport,
 
1921
                redirected)
 
1922
        except errors.FileExists:
 
1923
            if not use_existing_dir:
 
1924
                raise
 
1925
        except errors.NoSuchFile:
 
1926
            if not create_prefix:
 
1927
                raise
 
1928
            transport.create_prefix()
 
1929
 
 
1930
        require_stacking = (stacked_on is not None)
 
1931
        # Now the target directory exists, but doesn't have a .bzr
 
1932
        # directory. So we need to create it, along with any work to create
 
1933
        # all of the dependent branches, etc.
 
1934
 
 
1935
        result = self.initialize_on_transport(transport)
 
1936
        if repo_format_name:
 
1937
            try:
 
1938
                # use a custom format
 
1939
                result._format.repository_format = \
 
1940
                    repository.network_format_registry.get(repo_format_name)
 
1941
            except AttributeError:
 
1942
                # The format didn't permit it to be set.
 
1943
                pass
 
1944
            # A repository is desired, either in-place or shared.
 
1945
            repository_policy = result.determine_repository_policy(
 
1946
                force_new_repo, stacked_on, stack_on_pwd,
 
1947
                require_stacking=require_stacking)
 
1948
            result_repo, is_new_repo = repository_policy.acquire_repository(
 
1949
                make_working_trees, shared_repo)
 
1950
            if not require_stacking and repository_policy._require_stacking:
 
1951
                require_stacking = True
 
1952
                result._format.require_stacking()
 
1953
            result_repo.lock_write()
 
1954
        else:
 
1955
            result_repo = None
 
1956
            repository_policy = None
 
1957
        return result_repo, result, require_stacking, repository_policy
 
1958
 
1824
1959
    def _initialize_on_transport_vfs(self, transport):
1825
1960
        """Initialize a new bzrdir using VFS calls.
1826
1961
 
2038
2173
    repository_format = property(__return_repository_format)
2039
2174
 
2040
2175
 
2041
 
class BzrDirFormat5(BzrDirFormat):
 
2176
class BzrDirFormatAllInOne(BzrDirFormat):
 
2177
    """Common class for formats before meta-dirs."""
 
2178
 
 
2179
    def initialize_on_transport_ex(self, transport, use_existing_dir=False,
 
2180
        create_prefix=False, force_new_repo=False, stacked_on=None,
 
2181
        stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
 
2182
        shared_repo=False):
 
2183
        """See BzrDirFormat.initialize_on_transport_ex."""
 
2184
        require_stacking = (stacked_on is not None)
 
2185
        # Format 5 cannot stack, but we've been asked to - actually init
 
2186
        # a Meta1Dir
 
2187
        if require_stacking:
 
2188
            format = BzrDirMetaFormat1()
 
2189
            return format.initialize_on_transport_ex(transport,
 
2190
                use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
2191
                force_new_repo=force_new_repo, stacked_on=stacked_on,
 
2192
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
 
2193
                make_working_trees=make_working_trees, shared_repo=shared_repo)
 
2194
        return BzrDirFormat.initialize_on_transport_ex(self, transport,
 
2195
            use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
2196
            force_new_repo=force_new_repo, stacked_on=stacked_on,
 
2197
            stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
 
2198
            make_working_trees=make_working_trees, shared_repo=shared_repo)
 
2199
 
 
2200
 
 
2201
class BzrDirFormat5(BzrDirFormatAllInOne):
2042
2202
    """Bzr control format 5.
2043
2203
 
2044
2204
    This format is a combined format for working tree, branch and repository.
2099
2259
    repository_format = property(__return_repository_format)
2100
2260
 
2101
2261
 
2102
 
class BzrDirFormat6(BzrDirFormat):
 
2262
class BzrDirFormat6(BzrDirFormatAllInOne):
2103
2263
    """Bzr control format 6.
2104
2264
 
2105
2265
    This format is a combined format for working tree, branch and repository.
2241
2401
 
2242
2402
    def _open(self, transport):
2243
2403
        """See BzrDirFormat._open."""
2244
 
        return BzrDirMeta1(transport, self)
 
2404
        # Create a new format instance because otherwise initialisation of new
 
2405
        # metadirs share the global default format object leading to alias
 
2406
        # problems.
 
2407
        format = BzrDirMetaFormat1()
 
2408
        self._supply_sub_formats_to(format)
 
2409
        return BzrDirMeta1(transport, format)
2245
2410
 
2246
2411
    def __return_repository_format(self):
2247
2412
        """Circular import protection."""
2787
2952
            while old != new:
2788
2953
                if (old == _mod_branch.BzrBranchFormat5 and
2789
2954
                    new in (_mod_branch.BzrBranchFormat6,
2790
 
                        _mod_branch.BzrBranchFormat7)):
 
2955
                        _mod_branch.BzrBranchFormat7,
 
2956
                        _mod_branch.BzrBranchFormat8)):
2791
2957
                    branch_converter = _mod_branch.Converter5to6()
2792
2958
                elif (old == _mod_branch.BzrBranchFormat6 and
2793
 
                    new == _mod_branch.BzrBranchFormat7):
 
2959
                    new in (_mod_branch.BzrBranchFormat7,
 
2960
                            _mod_branch.BzrBranchFormat8)):
2794
2961
                    branch_converter = _mod_branch.Converter6to7()
 
2962
                elif (old == _mod_branch.BzrBranchFormat7 and
 
2963
                      new is _mod_branch.BzrBranchFormat8):
 
2964
                    branch_converter = _mod_branch.Converter7to8()
2795
2965
                else:
2796
2966
                    raise errors.BadConversionTarget("No converter", new)
2797
2967
                branch_converter.convert(branch)
2822
2992
        return to_convert
2823
2993
 
2824
2994
 
2825
 
# This is not in remote.py because it's small, and needs to be registered.
2826
 
# Putting it in remote.py creates a circular import problem.
 
2995
# This is not in remote.py because it's relatively small, and needs to be
 
2996
# registered. Putting it in remote.py creates a circular import problem.
2827
2997
# we can make it a lazy object if the control formats is turned into something
2828
2998
# like a registry.
2829
2999
class RemoteBzrDirFormat(BzrDirMetaFormat1):
2886
3056
        self._supply_sub_formats_to(format)
2887
3057
        return remote.RemoteBzrDir(transport, format)
2888
3058
 
 
3059
    def parse_NoneTrueFalse(self, arg):
 
3060
        if not arg:
 
3061
            return None
 
3062
        if arg == 'False':
 
3063
            return False
 
3064
        if arg == 'True':
 
3065
            return True
 
3066
        raise AssertionError("invalid arg %r" % arg)
 
3067
 
 
3068
    def _serialize_NoneTrueFalse(self, arg):
 
3069
        if arg is False:
 
3070
            return 'False'
 
3071
        if arg:
 
3072
            return 'True'
 
3073
        return ''
 
3074
 
 
3075
    def _serialize_NoneString(self, arg):
 
3076
        return arg or ''
 
3077
 
 
3078
    def initialize_on_transport_ex(self, transport, use_existing_dir=False,
 
3079
        create_prefix=False, force_new_repo=False, stacked_on=None,
 
3080
        stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
 
3081
        shared_repo=False):
 
3082
        try:
 
3083
            # hand off the request to the smart server
 
3084
            client_medium = transport.get_smart_medium()
 
3085
        except errors.NoSmartMedium:
 
3086
            do_vfs = True
 
3087
        else:
 
3088
            # Decline to open it if the server doesn't support our required
 
3089
            # version (3) so that the VFS-based transport will do it.
 
3090
            if client_medium.should_probe():
 
3091
                try:
 
3092
                    server_version = client_medium.protocol_version()
 
3093
                    if server_version != '2':
 
3094
                        do_vfs = True
 
3095
                    else:
 
3096
                        do_vfs = False
 
3097
                except errors.SmartProtocolError:
 
3098
                    # Apparently there's no usable smart server there, even though
 
3099
                    # the medium supports the smart protocol.
 
3100
                    do_vfs = True
 
3101
            else:
 
3102
                do_vfs = False
 
3103
        if not do_vfs:
 
3104
            client = _SmartClient(client_medium)
 
3105
            path = client.remote_path_from_transport(transport)
 
3106
            if client_medium._is_remote_before((1, 15)):
 
3107
                do_vfs = True
 
3108
        if do_vfs:
 
3109
            # TODO: lookup the local format from a server hint.
 
3110
            local_dir_format = BzrDirMetaFormat1()
 
3111
            self._supply_sub_formats_to(local_dir_format)
 
3112
            return local_dir_format.initialize_on_transport_ex(transport,
 
3113
                use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
3114
                force_new_repo=force_new_repo, stacked_on=stacked_on,
 
3115
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
 
3116
                make_working_trees=make_working_trees, shared_repo=shared_repo,
 
3117
                vfs_only=True)
 
3118
        args = []
 
3119
        args.append(self._serialize_NoneTrueFalse(use_existing_dir))
 
3120
        args.append(self._serialize_NoneTrueFalse(create_prefix))
 
3121
        args.append(self._serialize_NoneTrueFalse(force_new_repo))
 
3122
        args.append(self._serialize_NoneString(stacked_on))
 
3123
        # stack_on_pwd is often/usually our transport
 
3124
        if stack_on_pwd:
 
3125
            try:
 
3126
                stack_on_pwd = transport.relpath(stack_on_pwd)
 
3127
                if not stack_on_pwd:
 
3128
                    stack_on_pwd = '.'
 
3129
            except errors.PathNotChild:
 
3130
                pass
 
3131
        args.append(self._serialize_NoneString(stack_on_pwd))
 
3132
        args.append(self._serialize_NoneString(repo_format_name))
 
3133
        args.append(self._serialize_NoneTrueFalse(make_working_trees))
 
3134
        args.append(self._serialize_NoneTrueFalse(shared_repo))
 
3135
        if self._network_name is None:
 
3136
            self._network_name = \
 
3137
            BzrDirFormat.get_default_format().network_name()
 
3138
        try:
 
3139
            response = client.call('BzrDirFormat.initialize_ex',
 
3140
                self.network_name(), path, *args)
 
3141
        except errors.UnknownSmartMethod:
 
3142
            local_dir_format = BzrDirMetaFormat1()
 
3143
            self._supply_sub_formats_to(local_dir_format)
 
3144
            return local_dir_format.initialize_on_transport_ex(transport,
 
3145
                use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
3146
                force_new_repo=force_new_repo, stacked_on=stacked_on,
 
3147
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
 
3148
                make_working_trees=make_working_trees, shared_repo=shared_repo,
 
3149
                vfs_only=True)
 
3150
        repo_path = response[0]
 
3151
        bzrdir_name = response[6]
 
3152
        require_stacking = response[7]
 
3153
        require_stacking = self.parse_NoneTrueFalse(require_stacking)
 
3154
        format = RemoteBzrDirFormat()
 
3155
        format._network_name = bzrdir_name
 
3156
        self._supply_sub_formats_to(format)
 
3157
        bzrdir = remote.RemoteBzrDir(transport, format, _client=client)
 
3158
        if repo_path:
 
3159
            repo_format = remote.response_tuple_to_repo_format(response[1:])
 
3160
            if repo_path == '.':
 
3161
                repo_path = ''
 
3162
            if repo_path:
 
3163
                repo_bzrdir_format = RemoteBzrDirFormat()
 
3164
                repo_bzrdir_format._network_name = response[5]
 
3165
                repo_bzr = remote.RemoteBzrDir(transport.clone(repo_path),
 
3166
                    repo_bzrdir_format)
 
3167
            else:
 
3168
                repo_bzr = bzrdir
 
3169
            final_stack = response[8] or None
 
3170
            final_stack_pwd = response[9] or None
 
3171
            remote_repo = remote.RemoteRepository(repo_bzr, repo_format)
 
3172
            if len(response) > 10:
 
3173
                # Updated server verb that locks remotely.
 
3174
                repo_lock_token = response[10] or None
 
3175
                remote_repo.lock_write(repo_lock_token, _skip_rpc=True)
 
3176
                if repo_lock_token:
 
3177
                    remote_repo.dont_leave_lock_in_place()
 
3178
            else:
 
3179
                remote_repo.lock_write()
 
3180
            policy = UseExistingRepository(remote_repo, final_stack,
 
3181
                final_stack_pwd, require_stacking)
 
3182
            policy.acquire_repository()
 
3183
        else:
 
3184
            remote_repo = None
 
3185
            policy = None
 
3186
        return remote_repo, bzrdir, require_stacking, policy
 
3187
 
2889
3188
    def _open(self, transport):
2890
3189
        return remote.RemoteBzrDir(transport, self)
2891
3190
 
3165
3464
        stack_on = self._get_full_stack_on()
3166
3465
        if stack_on is None:
3167
3466
            return
3168
 
        stacked_dir = BzrDir.open(stack_on,
3169
 
                                  possible_transports=possible_transports)
 
3467
        try:
 
3468
            stacked_dir = BzrDir.open(stack_on,
 
3469
                                      possible_transports=possible_transports)
 
3470
        except errors.JailBreak:
 
3471
            # We keep the stacking details, but we are in the server code so
 
3472
            # actually stacking is not needed.
 
3473
            return
3170
3474
        try:
3171
3475
            stacked_repo = stacked_dir.open_branch().repository
3172
3476
        except errors.NotBranchError:
3227
3531
                # network round trips to check - but we only do this
3228
3532
                # when the source can't stack so it will fade away
3229
3533
                # as people do upgrade.
 
3534
                branch_format = None
 
3535
                repo_format = None
3230
3536
                try:
3231
3537
                    target_dir = BzrDir.open(stack_on,
3232
3538
                        possible_transports=[self._bzrdir.root_transport])
3233
3539
                except errors.NotBranchError:
3234
3540
                    # Nothing there, don't change formats
3235
3541
                    pass
 
3542
                except errors.JailBreak:
 
3543
                    # stack_on is inaccessible, JFDI.
 
3544
                    if format.repository_format.rich_root_data:
 
3545
                        repo_format = pack_repo.RepositoryFormatKnitPack6RichRoot()
 
3546
                    else:
 
3547
                        repo_format = pack_repo.RepositoryFormatKnitPack6()
 
3548
                    branch_format = branch.BzrBranchFormat7()
3236
3549
                else:
3237
3550
                    try:
3238
3551
                        target_branch = target_dir.open_branch()
3245
3558
                        if not (branch_format.supports_stacking()
3246
3559
                            and repo_format.supports_external_lookups):
3247
3560
                            # Doesn't stack itself, don't force an upgrade
3248
 
                            pass
3249
 
                        else:
3250
 
                            # Does support stacking, use its format.
3251
 
                            format.repository_format = repo_format
3252
 
                            format.set_branch_format(branch_format)
3253
 
                            note('Source format does not support stacking, '
3254
 
                                'using format: \'%s\'\n  %s\n',
3255
 
                                branch_format.get_format_description(),
3256
 
                                repo_format.get_format_description())
 
3561
                            branch_format = None
 
3562
                            repo_format = None
 
3563
                if branch_format and repo_format:
 
3564
                    # Does support stacking, use its format.
 
3565
                    format.repository_format = repo_format
 
3566
                    format.set_branch_format(branch_format)
 
3567
                    note('Source format does not support stacking, '
 
3568
                        'using format: \'%s\'\n  %s\n',
 
3569
                        branch_format.get_format_description(),
 
3570
                        repo_format.get_format_description())
3257
3571
            if not self._require_stacking:
3258
3572
                # We have picked up automatic stacking somewhere.
3259
3573
                note('Using default stacking branch %s at %s', self._stack_on,
3426
3740
# The following un-numbered 'development' formats should always just be aliases.
3427
3741
format_registry.register_metadir('development-rich-root',
3428
3742
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK1',
3429
 
    help='Current development format. Can convert data to and from pack-0.92 '
3430
 
        '(and anything compatible with pack-0.92) format repositories. '
3431
 
        'Repositories and branches in this format can only be read by bzr.dev. '
3432
 
        'Please read '
 
3743
    help='Current development format. Supports rich roots. Can convert data '
 
3744
        'to and from rich-root-pack (and anything compatible with '
 
3745
        'rich-root-pack) format repositories. Repositories and branches in '
 
3746
        'this format can only be read by bzr.dev. Please read '
3433
3747
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3434
3748
        'before use.',
3435
3749
    branch_format='bzrlib.branch.BzrBranchFormat7',