~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/reconfigure.py

  • Committer: Ian Clatworthy
  • Date: 2008-04-01 04:19:06 UTC
  • mfrom: (3302.6.1 xma-mailmode)
  • mto: This revision was merged to the branch mainline in revision 3323.
  • Revision ID: ian.clatworthy@canonical.com-20080401041906-s7ekpfpo0tnyfkbz
Add mail-mode GNU Emacs mail package as a mail client option (Xavier Maillard)

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Reconfigure a bzrdir into a new tree/branch/repository layout"""
18
18
 
19
19
from bzrlib import (
20
20
    branch,
21
 
    bzrdir,
22
21
    errors,
23
22
    )
24
23
 
31
30
            self.repository = self.bzrdir.find_repository()
32
31
        except errors.NoRepositoryPresent:
33
32
            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
40
33
        try:
41
34
            branch = self.bzrdir.open_branch()
42
35
            if branch.bzrdir.root_transport.base == bzrdir.root_transport.base:
62
55
        self._create_tree = False
63
56
        self._create_repository = False
64
57
        self._destroy_repository = False
65
 
        self._repository_trees = None
66
58
 
67
59
    @staticmethod
68
60
    def to_branch(bzrdir):
123
115
            raise errors.AlreadyLightweightCheckout(bzrdir)
124
116
        return reconfiguration
125
117
 
126
 
    @classmethod
127
 
    def to_use_shared(klass, bzrdir):
128
 
        """Convert a standalone branch into a repository branch"""
129
 
        reconfiguration = klass(bzrdir)
130
 
        reconfiguration._set_use_shared(use_shared=True)
131
 
        if not reconfiguration.changes_planned():
132
 
            raise errors.AlreadyUsingShared(bzrdir)
133
 
        return reconfiguration
134
 
 
135
 
    @classmethod
136
 
    def to_standalone(klass, bzrdir):
137
 
        """Convert a repository branch into a standalone branch"""
138
 
        reconfiguration = klass(bzrdir)
139
 
        reconfiguration._set_use_shared(use_shared=False)
140
 
        if not reconfiguration.changes_planned():
141
 
            raise errors.AlreadyStandalone(bzrdir)
142
 
        return reconfiguration
143
 
 
144
 
    @classmethod
145
 
    def set_repository_trees(klass, bzrdir, with_trees):
146
 
        """Adjust a repository's working tree presence default"""
147
 
        reconfiguration = klass(bzrdir)
148
 
        if not reconfiguration.repository.is_shared():
149
 
            raise errors.ReconfigurationNotSupported(reconfiguration.bzrdir)
150
 
        if with_trees and reconfiguration.repository.make_working_trees():
151
 
            raise errors.AlreadyWithTrees(bzrdir)
152
 
        elif (not with_trees
153
 
              and not reconfiguration.repository.make_working_trees()):
154
 
            raise errors.AlreadyWithNoTrees(bzrdir)
155
 
        else:
156
 
            reconfiguration._repository_trees = with_trees
157
 
        return reconfiguration
158
 
 
159
118
    def _plan_changes(self, want_tree, want_branch, want_bound,
160
119
                      want_reference):
161
120
        """Determine which changes are needed to assume the configuration"""
196
155
        if want_tree and self.tree is None:
197
156
            self._create_tree = True
198
157
 
199
 
    def _set_use_shared(self, use_shared=None):
200
 
        if use_shared is None:
201
 
            return
202
 
        if use_shared:
203
 
            if self.local_repository is not None:
204
 
                self._destroy_repository = True
205
 
        else:
206
 
            if self.local_repository is None:
207
 
                self._create_repository = True
208
 
 
209
158
    def changes_planned(self):
210
159
        """Return True if changes are planned, False otherwise"""
211
160
        return (self._unbind or self._bind or self._destroy_tree
212
161
                or self._create_tree or self._destroy_reference
213
162
                or self._create_branch or self._create_repository
214
 
                or self._create_reference or self._destroy_repository)
 
163
                or self._create_reference)
215
164
 
216
165
    def _check(self):
217
166
        """Raise if reconfiguration would destroy local changes"""
219
168
            changes = self.tree.changes_from(self.tree.basis_tree())
220
169
            if changes.has_changed():
221
170
                raise errors.UncommittedChanges(self.tree)
222
 
        if self._create_reference and self.local_branch is not None:
223
 
            reference_branch = branch.Branch.open(self._select_bind_location())
224
 
            if (reference_branch.last_revision() !=
225
 
                self.local_branch.last_revision()):
226
 
                raise errors.UnsyncedBranches(self.bzrdir, reference_branch)
227
171
 
228
172
    def _select_bind_location(self):
229
173
        """Select a location to bind or create a reference to.
269
213
            self._check()
270
214
        if self._create_repository:
271
215
            repo = self.bzrdir.create_repository()
272
 
            if self.local_branch and not self._destroy_branch:
273
 
                repo.fetch(self.local_branch.repository,
274
 
                           self.local_branch.last_revision())
275
216
        else:
276
217
            repo = self.repository
277
218
        if self._create_branch and self.referenced_branch is not None:
282
223
        if self._destroy_repository:
283
224
            if self._create_reference:
284
225
                reference_branch.repository.fetch(self.repository)
285
 
            elif self.local_branch is not None and not self._destroy_branch:
286
 
                up = self.local_branch.bzrdir.root_transport.clone('..')
287
 
                up_bzrdir = bzrdir.BzrDir.open_containing_from_transport(up)[0]
288
 
                new_repo = up_bzrdir.find_repository()
289
 
                new_repo.fetch(self.repository)
290
226
        last_revision_info = None
291
227
        if self._destroy_reference:
292
228
            last_revision_info = self.referenced_branch.last_revision_info()
318
254
            local_branch.bind(branch.Branch.open(bind_location))
319
255
        if self._destroy_repository:
320
256
            self.bzrdir.destroy_repository()
321
 
        if self._repository_trees is not None:
322
 
            repo.set_make_working_trees(self._repository_trees)