/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

merge bzr.dev r4154

Show diffs side-by-side

added added

removed removed

Lines of Context:
217
217
                force_new_repo, stacked_on, self.root_transport.base,
218
218
                require_stacking=require_stacking)
219
219
            make_working_trees = local_repo.make_working_trees()
220
 
            result_repo = repository_policy.acquire_repository(
 
220
            result_repo, is_new_repo = repository_policy.acquire_repository(
221
221
                make_working_trees, local_repo.is_shared())
222
222
            if not require_stacking and repository_policy._require_stacking:
223
223
                require_stacking = True
224
224
                result._format.require_stacking()
225
 
            result_repo.fetch(local_repo, revision_id=revision_id)
 
225
            if is_new_repo and not require_stacking and revision_id is not None:
 
226
                fetch_spec = graph.PendingAncestryResult(
 
227
                    [revision_id], local_repo)
 
228
                result_repo.fetch(local_repo, fetch_spec=fetch_spec)
 
229
            else:
 
230
                result_repo.fetch(local_repo, revision_id=revision_id)
226
231
        else:
227
232
            result_repo = None
228
233
        # 1 if there is a branch present
440
445
    def _find_or_create_repository(self, force_new_repo):
441
446
        """Create a new repository if needed, returning the repository."""
442
447
        policy = self.determine_repository_policy(force_new_repo)
443
 
        return policy.acquire_repository()
 
448
        return policy.acquire_repository()[0]
444
449
 
445
450
    @staticmethod
446
451
    def create_branch_convenience(base, force_new_repo=False,
1114
1119
                    source_repository = None
1115
1120
        repository_policy = result.determine_repository_policy(
1116
1121
            force_new_repo, stacked_branch_url, require_stacking=stacked)
1117
 
        result_repo = repository_policy.acquire_repository()
 
1122
        result_repo, is_new_repo = repository_policy.acquire_repository()
 
1123
        if is_new_repo and revision_id is not None and not stacked:
 
1124
            fetch_spec = graph.PendingAncestryResult(
 
1125
                [revision_id], source_repository)
 
1126
        else:
 
1127
            fetch_spec = None
1118
1128
        if source_repository is not None:
1119
1129
            # Fetch while stacked to prevent unstacked fetch from
1120
1130
            # Branch.sprout.
1121
 
            result_repo.fetch(source_repository, revision_id=revision_id)
 
1131
            if fetch_spec is None:
 
1132
                result_repo.fetch(source_repository, revision_id=revision_id)
 
1133
            else:
 
1134
                result_repo.fetch(source_repository, fetch_spec=fetch_spec)
1122
1135
 
1123
1136
        if source_branch is None:
1124
1137
            # this is for sprouting a bzrdir without a branch; is that
1126
1139
            # Not especially, but it's part of the contract.
1127
1140
            result_branch = result.create_branch()
1128
1141
        else:
1129
 
            # Force NULL revision to avoid using repository before stacking
1130
 
            # is configured.
1131
 
            result_branch = source_branch.sprout(
1132
 
                result, revision_id=_mod_revision.NULL_REVISION)
1133
 
            parent_location = result_branch.get_parent()
 
1142
            result_branch = source_branch.sprout(result,
 
1143
                revision_id=revision_id, repository_policy=repository_policy)
1134
1144
        mutter("created new branch %r" % (result_branch,))
1135
 
        repository_policy.configure_branch(result_branch)
1136
 
        if source_branch is not None:
1137
 
            source_branch.copy_content_into(result_branch, revision_id)
1138
 
            # Override copy_content_into
1139
 
            result_branch.set_parent(parent_location)
1140
1145
 
1141
1146
        # Create/update the result working tree
1142
1147
        if (create_tree_if_local and
1341
1346
 
1342
1347
    def sprout(self, url, revision_id=None, force_new_repo=False,
1343
1348
               possible_transports=None, accelerator_tree=None,
1344
 
               hardlink=False, stacked=False, create_tree_if_local=True):
 
1349
               hardlink=False, stacked=False, create_tree_if_local=True,
 
1350
               source_branch=None):
1345
1351
        """See BzrDir.sprout()."""
 
1352
        if source_branch is not None:
 
1353
            my_branch = self.open_branch()
 
1354
            if source_branch.base != my_branch.base:
 
1355
                raise AssertionError(
 
1356
                    "source branch %r is not within %r with branch %r" %
 
1357
                    (source_branch, self, my_branch))
1346
1358
        if stacked:
1347
1359
            raise errors.UnstackableBranchFormat(
1348
1360
                self._format, self.root_transport.base)
1772
1784
        """
1773
1785
        return True
1774
1786
 
 
1787
    def network_name(self):
 
1788
        """A simple byte string uniquely identifying this format for RPC calls.
 
1789
 
 
1790
        Bzr control formats use thir disk format string to identify the format
 
1791
        over the wire. Its possible that other control formats have more
 
1792
        complex detection requirements, so we permit them to use any unique and
 
1793
        immutable string they desire.
 
1794
        """
 
1795
        raise NotImplementedError(self.network_name)
 
1796
 
1775
1797
    def same_model(self, target_format):
1776
1798
        return (self.repository_format.rich_root_data ==
1777
1799
            target_format.rich_root_data)
1822
1844
    @classmethod
1823
1845
    def register_format(klass, format):
1824
1846
        klass._formats[format.get_format_string()] = format
 
1847
        # bzr native formats have a network name of their format string.
 
1848
        network_format_registry.register(format.get_format_string(), format.__class__)
1825
1849
 
1826
1850
    @classmethod
1827
1851
    def register_control_format(klass, format):
1916
1940
        """
1917
1941
        return False
1918
1942
 
 
1943
    def network_name(self):
 
1944
        return self.get_format_string()
 
1945
 
1919
1946
    def _open(self, transport):
1920
1947
        """See BzrDirFormat._open."""
1921
1948
        return BzrDir4(transport, self)
1974
2001
            result._init_workingtree()
1975
2002
        return result
1976
2003
 
 
2004
    def network_name(self):
 
2005
        return self.get_format_string()
 
2006
 
1977
2007
    def _open(self, transport):
1978
2008
        """See BzrDirFormat._open."""
1979
2009
        return BzrDir5(transport, self)
2031
2061
            result._init_workingtree()
2032
2062
        return result
2033
2063
 
 
2064
    def network_name(self):
 
2065
        return self.get_format_string()
 
2066
 
2034
2067
    def _open(self, transport):
2035
2068
        """See BzrDirFormat._open."""
2036
2069
        return BzrDir6(transport, self)
2058
2091
    def __init__(self):
2059
2092
        self._workingtree_format = None
2060
2093
        self._branch_format = None
 
2094
        self._repository_format = None
2061
2095
 
2062
2096
    def __eq__(self, other):
2063
2097
        if other.__class__ is not self.__class__:
2118
2152
        """See BzrDirFormat.get_format_description()."""
2119
2153
        return "Meta directory format 1"
2120
2154
 
 
2155
    def network_name(self):
 
2156
        return self.get_format_string()
 
2157
 
2121
2158
    def _open(self, transport):
2122
2159
        """See BzrDirFormat._open."""
2123
2160
        return BzrDirMeta1(transport, self)
2124
2161
 
2125
2162
    def __return_repository_format(self):
2126
2163
        """Circular import protection."""
2127
 
        if getattr(self, '_repository_format', None):
 
2164
        if self._repository_format:
2128
2165
            return self._repository_format
2129
2166
        from bzrlib.repository import RepositoryFormat
2130
2167
        return RepositoryFormat.get_default_format()
2167
2204
                                  __set_workingtree_format)
2168
2205
 
2169
2206
 
 
2207
network_format_registry = registry.FormatRegistry()
 
2208
"""Registry of formats indexed by their network name.
 
2209
 
 
2210
The network name for a BzrDirFormat is an identifier that can be used when
 
2211
referring to formats with smart server operations. See
 
2212
BzrDirFormat.network_name() for more detail.
 
2213
"""
 
2214
 
 
2215
 
2170
2216
# Register bzr control format
2171
2217
BzrDirFormat.register_control_format(BzrDirFormat)
2172
2218
 
2699
2745
class RemoteBzrDirFormat(BzrDirMetaFormat1):
2700
2746
    """Format representing bzrdirs accessed via a smart server"""
2701
2747
 
 
2748
    def __init__(self):
 
2749
        BzrDirMetaFormat1.__init__(self)
 
2750
        self._network_name = None
 
2751
 
2702
2752
    def get_format_description(self):
2703
2753
        return 'bzr remote bzrdir'
2704
2754
 
2705
2755
    def get_format_string(self):
2706
2756
        raise NotImplementedError(self.get_format_string)
2707
2757
 
 
2758
    def network_name(self):
 
2759
        if self._network_name:
 
2760
            return self._network_name
 
2761
        else:
 
2762
            raise AssertionError("No network name set.")
 
2763
 
2708
2764
    @classmethod
2709
2765
    def probe_transport(klass, transport):
2710
2766
        """Return a RemoteBzrDirFormat object if it looks possible."""
2767
2823
                result._custom_format = custom_format._custom_format
2768
2824
            else:
2769
2825
                result._custom_format = custom_format
2770
 
            result.rich_root_data = custom_format.rich_root_data
2771
2826
        return result
2772
2827
 
2773
2828
    def get_branch_format(self):
2823
2878
        """Register a metadir subformat.
2824
2879
 
2825
2880
        These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
2826
 
        by the Repository format.
 
2881
        by the Repository/Branch/WorkingTreeformats.
2827
2882
 
2828
2883
        :param repository_format: The fully-qualified repository format class
2829
2884
            name as a string.
3006
3061
                stack_on = self._get_full_stack_on()
3007
3062
        try:
3008
3063
            branch.set_stacked_on_url(stack_on)
3009
 
        except errors.UnstackableBranchFormat:
 
3064
        except (errors.UnstackableBranchFormat,
 
3065
                errors.UnstackableRepositoryFormat):
3010
3066
            if self._require_stacking:
3011
3067
                raise
3012
3068
 
3046
3102
        :param make_working_trees: If creating a repository, set
3047
3103
            make_working_trees to this value (if non-None)
3048
3104
        :param shared: If creating a repository, make it shared if True
3049
 
        :return: A repository
 
3105
        :return: A repository, is_new_flag (True if the repository was
 
3106
            created).
3050
3107
        """
3051
3108
        raise NotImplemented(RepositoryAcquisitionPolicy.acquire_repository)
3052
3109
 
3077
3134
                           possible_transports=[self._bzrdir.transport])
3078
3135
        if make_working_trees is not None:
3079
3136
            repository.set_make_working_trees(make_working_trees)
3080
 
        return repository
 
3137
        return repository, True
3081
3138
 
3082
3139
 
3083
3140
class UseExistingRepository(RepositoryAcquisitionPolicy):
3099
3156
    def acquire_repository(self, make_working_trees=None, shared=False):
3100
3157
        """Implementation of RepositoryAcquisitionPolicy.acquire_repository
3101
3158
 
3102
 
        Returns an existing repository to use
 
3159
        Returns an existing repository to use.
3103
3160
        """
3104
3161
        self._add_fallback(self._repository,
3105
3162
                       possible_transports=[self._repository.bzrdir.transport])
3106
 
        return self._repository
 
3163
        return self._repository, False
3107
3164
 
3108
3165
 
3109
3166
# Please register new formats after old formats so that formats