/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: Robert Collins
  • Date: 2006-02-14 04:07:06 UTC
  • mto: (1534.5.2 bzr-dir)
  • mto: This revision was merged to the branch mainline in revision 1554.
  • Revision ID: robertc@robertcollins.net-20060214040706-ab43d8450989c555
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
        if not allow_unsupported and not format.is_supported():
56
56
            raise errors.UnsupportedFormatError(format)
57
57
 
58
 
    def clone(self, url, revision_id=None, basis=None):
 
58
    def clone(self, url, revision_id=None, basis=None, force_new_repo=False):
59
59
        """Clone this bzrdir and its contents to url verbatim.
60
60
 
61
61
        If urls last component does not exist, it will be created.
62
62
 
63
63
        if revision_id is not None, then the clone operation may tune
64
64
            itself to download less data.
 
65
        :param force_new_repo: Do not use a shared repository for the target 
 
66
                               even if one is available.
65
67
        """
66
68
        self._make_tail(url)
 
69
        basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
67
70
        result = self._format.initialize(url)
68
 
        basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
69
71
        try:
70
 
            self.open_repository().clone(result, revision_id=revision_id, basis=basis_repo)
 
72
            local_repo = self.find_repository()
71
73
        except errors.NoRepositoryPresent:
72
 
            pass
 
74
            local_repo = None
 
75
        if local_repo:
 
76
            # may need to copy content in
 
77
            if force_new_repo:
 
78
                local_repo.clone(result, revision_id=revision_id, basis=basis_repo)
 
79
            else:
 
80
                try:
 
81
                    result_repo = result.find_repository()
 
82
                    # fetch content this dir needs.
 
83
                    if basis_repo:
 
84
                        # XXX FIXME RBC 20060214 need tests for this when the basis
 
85
                        # is incomplete
 
86
                        result_repo.fetch(basis_repo, revision_id=revision_id)
 
87
                    result_repo.fetch(local_repo, revision_id=revision_id)
 
88
                except errors.NoRepositoryPresent:
 
89
                    # needed to make one anyway.
 
90
                    local_repo.clone(result, revision_id=revision_id, basis=basis_repo)
 
91
        # 1 if there is a branch present
 
92
        #   make sure its content is available in the target repository
 
93
        #   clone it.
73
94
        try:
74
95
            self.open_branch().clone(result, revision_id=revision_id)
75
96
        except errors.NotBranchError:
140
161
        raise NotImplementedError(self.create_branch)
141
162
 
142
163
    @staticmethod
143
 
    def create_branch_and_repo(base):
 
164
    def create_branch_and_repo(base, force_new_repo=False):
144
165
        """Create a new BzrDir, Branch and Repository at the url 'base'.
145
166
 
146
167
        This will use the current default BzrDirFormat, and use whatever 
147
168
        repository format that that uses via bzrdir.create_branch and
148
 
        create_repository.
 
169
        create_repository. If a shared repository is available that is used
 
170
        preferentially.
149
171
 
150
172
        The created Branch object is returned.
 
173
 
 
174
        :param base: The URL to create the branch at.
 
175
        :param force_new_repo: If True a new repository is always created.
151
176
        """
152
177
        bzrdir = BzrDir.create(base)
153
 
        bzrdir.create_repository()
 
178
        if force_new_repo:
 
179
            bzrdir.create_repository()
 
180
        try:
 
181
            repo = bzrdir.find_repository()
 
182
        except errors.NoRepositoryPresent:
 
183
            bzrdir.create_repository()
154
184
        return bzrdir.create_branch()
155
185
        
156
186
    @staticmethod
193
223
        """Create a working tree at this BzrDir"""
194
224
        raise NotImplementedError(self.create_workingtree)
195
225
 
 
226
    def find_repository(self):
 
227
        """Find the repository that should be used for a_bzrdir.
 
228
 
 
229
        This does not require a branch as we use it to find the repo for
 
230
        new branches as well as to hook existing branches up to their
 
231
        repository.
 
232
        """
 
233
        try:
 
234
            return self.open_repository()
 
235
        except errors.NoRepositoryPresent:
 
236
            pass
 
237
        next_transport = self.root_transport.clone('..')
 
238
        while True:
 
239
            try:
 
240
                found_bzrdir = BzrDir.open_containing_transport(
 
241
                    next_transport)[0]
 
242
            except errors.NotBranchError:
 
243
                raise errors.NoRepositoryPresent(self)
 
244
            try:
 
245
                repository = found_bzrdir.open_repository()
 
246
            except errors.NoRepositoryPresent:
 
247
                next_transport = found_bzrdir.root_transport.clone('..')
 
248
                continue
 
249
            if ((found_bzrdir.root_transport.base == 
 
250
                 self.root_transport.base) or repository.is_shared()):
 
251
                return repository
 
252
            else:
 
253
                raise errors.NoRepositoryPresent(self)
 
254
        raise errors.NoRepositoryPresent(self)
 
255
 
196
256
    def get_branch_transport(self, branch_format):
197
257
        """Get the transport for use by branch format in this BzrDir.
198
258