~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/reconfigure.py

Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from bzrlib import (
20
20
    branch,
 
21
    bzrdir,
21
22
    errors,
22
23
    )
23
24
 
30
31
            self.repository = self.bzrdir.find_repository()
31
32
        except errors.NoRepositoryPresent:
32
33
            self.repository = None
 
34
        else:
 
35
            if (self.repository.bzrdir.root_transport.base ==
 
36
                self.bzrdir.root_transport.base):
 
37
                self.local_repository = self.repository
 
38
            else:
 
39
                self.local_repository = None
33
40
        try:
34
41
            branch = self.bzrdir.open_branch()
35
42
            if branch.bzrdir.root_transport.base == bzrdir.root_transport.base:
115
122
            raise errors.AlreadyLightweightCheckout(bzrdir)
116
123
        return reconfiguration
117
124
 
 
125
    @classmethod
 
126
    def to_use_shared(klass, bzrdir):
 
127
        """Convert a standalone branch into a repository branch"""
 
128
        reconfiguration = klass(bzrdir)
 
129
        reconfiguration._set_use_shared(use_shared=True)
 
130
        if not reconfiguration.changes_planned():
 
131
            raise errors.AlreadyUsingShared(bzrdir)
 
132
        return reconfiguration
 
133
 
 
134
    @classmethod
 
135
    def to_standalone(klass, bzrdir):
 
136
        """Convert a repository branch into a standalone branch"""
 
137
        reconfiguration = klass(bzrdir)
 
138
        reconfiguration._set_use_shared(use_shared=False)
 
139
        if not reconfiguration.changes_planned():
 
140
            raise errors.AlreadyStandalone(bzrdir)
 
141
        return reconfiguration
 
142
 
118
143
    def _plan_changes(self, want_tree, want_branch, want_bound,
119
144
                      want_reference):
120
145
        """Determine which changes are needed to assume the configuration"""
155
180
        if want_tree and self.tree is None:
156
181
            self._create_tree = True
157
182
 
 
183
    def _set_use_shared(self, use_shared=None):
 
184
        if use_shared is None:
 
185
            return
 
186
        if use_shared:
 
187
            if self.local_repository is not None:
 
188
                self._destroy_repository = True
 
189
        else:
 
190
            if self.local_repository is None:
 
191
                self._create_repository = True
 
192
 
158
193
    def changes_planned(self):
159
194
        """Return True if changes are planned, False otherwise"""
160
195
        return (self._unbind or self._bind or self._destroy_tree
161
196
                or self._create_tree or self._destroy_reference
162
197
                or self._create_branch or self._create_repository
163
 
                or self._create_reference)
 
198
                or self._create_reference or self._destroy_repository)
164
199
 
165
200
    def _check(self):
166
201
        """Raise if reconfiguration would destroy local changes"""
213
248
            self._check()
214
249
        if self._create_repository:
215
250
            repo = self.bzrdir.create_repository()
 
251
            if self.local_branch and not self._destroy_branch:
 
252
                repo.fetch(self.local_branch.repository,
 
253
                           self.local_branch.last_revision())
216
254
        else:
217
255
            repo = self.repository
218
256
        if self._create_branch and self.referenced_branch is not None:
223
261
        if self._destroy_repository:
224
262
            if self._create_reference:
225
263
                reference_branch.repository.fetch(self.repository)
 
264
            elif self.local_branch is not None and not self._destroy_branch:
 
265
                up = self.local_branch.bzrdir.root_transport.clone('..')
 
266
                up_bzrdir = bzrdir.BzrDir.open_containing_from_transport(up)[0]
 
267
                new_repo = up_bzrdir.find_repository()
 
268
                new_repo.fetch(self.repository)
226
269
        last_revision_info = None
227
270
        if self._destroy_reference:
228
271
            last_revision_info = self.referenced_branch.last_revision_info()