~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/reconfigure.py

  • Committer: Aaron Bentley
  • Date: 2007-12-09 23:53:50 UTC
  • mto: This revision was merged to the branch mainline in revision 3133.
  • Revision ID: aaron.bentley@utoronto.ca-20071209235350-qp39yk0xzx7a4f6p
Don't use the base if not cherrypicking

Show diffs side-by-side

added added

removed removed

Lines of Context:
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):
70
62
 
71
63
        :param bzrdir: The bzrdir to reconfigure
72
64
        :raise errors.AlreadyBranch: if bzrdir is already a branch
 
65
        :raise errors.ReconfigurationNotSupported: if bzrdir does not contain
 
66
            a branch or branch reference
73
67
        """
74
68
        reconfiguration = Reconfigure(bzrdir)
75
69
        reconfiguration._plan_changes(want_tree=False, want_branch=True,
84
78
 
85
79
        :param bzrdir: The bzrdir to reconfigure
86
80
        :raise errors.AlreadyTree: if bzrdir is already a tree
 
81
        :raise errors.ReconfigurationNotSupported: if bzrdir does not contain
 
82
            a branch or branch reference
87
83
        """
88
84
        reconfiguration = Reconfigure(bzrdir)
89
85
        reconfiguration._plan_changes(want_tree=True, want_branch=True,
99
95
        :param bzrdir: The bzrdir to reconfigure
100
96
        :param bound_location: The location the checkout should be bound to.
101
97
        :raise errors.AlreadyCheckout: if bzrdir is already a checkout
 
98
        :raise errors.ReconfigurationNotSupported: if bzrdir does not contain
 
99
            a branch or branch reference
102
100
        """
103
101
        reconfiguration = Reconfigure(bzrdir, bound_location)
104
102
        reconfiguration._plan_changes(want_tree=True, want_branch=True,
115
113
        :param bound_location: The location the checkout should be bound to.
116
114
        :raise errors.AlreadyLightweightCheckout: if bzrdir is already a
117
115
            lightweight checkout
 
116
        :raise errors.ReconfigurationNotSupported: if bzrdir does not contain
 
117
            a branch or branch reference
118
118
        """
119
119
        reconfiguration = klass(bzrdir, reference_location)
120
120
        reconfiguration._plan_changes(want_tree=True, want_branch=False,
123
123
            raise errors.AlreadyLightweightCheckout(bzrdir)
124
124
        return reconfiguration
125
125
 
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
126
    def _plan_changes(self, want_tree, want_branch, want_bound,
160
127
                      want_reference):
161
128
        """Determine which changes are needed to assume the configuration"""
163
130
            raise errors.ReconfigurationNotSupported(self.bzrdir)
164
131
        if want_branch and want_reference:
165
132
            raise errors.ReconfigurationNotSupported(self.bzrdir)
 
133
        if (want_branch or want_reference) and (self.local_branch is None and
 
134
                                                self.referenced_branch
 
135
                                                is None):
 
136
            raise errors.ReconfigurationNotSupported(self.bzrdir)
166
137
        if self.repository is None:
167
138
            if not want_reference:
168
139
                self._create_repository = True
169
140
        else:
170
141
            if want_reference and (self.repository.bzrdir.root_transport.base
171
142
                                   == self.bzrdir.root_transport.base):
172
 
                if not self.repository.is_shared():
173
 
                    self._destroy_repository = True
 
143
                self._destroy_repository = True
174
144
        if self.referenced_branch is None:
175
145
            if want_reference:
176
146
                self._create_reference = True
177
 
                if self.local_branch is not None:
178
 
                    self._destroy_branch = True
179
147
        else:
180
148
            if not want_reference:
181
149
                self._destroy_reference = True
196
164
        if want_tree and self.tree is None:
197
165
            self._create_tree = True
198
166
 
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
167
    def changes_planned(self):
210
168
        """Return True if changes are planned, False otherwise"""
211
169
        return (self._unbind or self._bind or self._destroy_tree
212
170
                or self._create_tree or self._destroy_reference
213
 
                or self._create_branch or self._create_repository
214
 
                or self._create_reference or self._destroy_repository)
 
171
                or self._create_branch or self._create_repository)
215
172
 
216
173
    def _check(self):
217
174
        """Raise if reconfiguration would destroy local changes"""
219
176
            changes = self.tree.changes_from(self.tree.basis_tree())
220
177
            if changes.has_changed():
221
178
                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
179
 
228
180
    def _select_bind_location(self):
229
181
        """Select a location to bind or create a reference to.
269
221
            self._check()
270
222
        if self._create_repository:
271
223
            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
224
        else:
276
225
            repo = self.repository
277
 
        if self._create_branch and self.referenced_branch is not None:
 
226
        if self._create_branch:
278
227
            repo.fetch(self.referenced_branch.repository,
279
228
                       self.referenced_branch.last_revision())
280
 
        if self._create_reference:
281
 
            reference_branch = branch.Branch.open(self._select_bind_location())
282
 
        if self._destroy_repository:
283
 
            if self._create_reference:
284
 
                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
 
        last_revision_info = None
291
229
        if self._destroy_reference:
292
 
            last_revision_info = self.referenced_branch.last_revision_info()
 
230
            reference_info = self.referenced_branch.last_revision_info()
293
231
            self.bzrdir.destroy_branch()
294
232
        if self._destroy_branch:
295
 
            last_revision_info = self.local_branch.last_revision_info()
296
 
            if self._create_reference:
297
 
                self.local_branch.tags.merge_to(reference_branch.tags)
 
233
            reference_info = self.local_branch.last_revision_info()
298
234
            self.bzrdir.destroy_branch()
299
235
        if self._create_branch:
300
236
            local_branch = self.bzrdir.create_branch()
301
 
            if last_revision_info is not None:
302
 
                local_branch.set_last_revision_info(*last_revision_info)
303
 
            if self._destroy_reference:
304
 
                self.referenced_branch.tags.merge_to(local_branch.tags)
 
237
            local_branch.set_last_revision_info(*reference_info)
305
238
        else:
306
239
            local_branch = self.local_branch
307
240
        if self._create_reference:
 
241
            reference_branch = branch.Branch.open(self._select_bind_location())
308
242
            format = branch.BranchReferenceFormat().initialize(self.bzrdir,
309
243
                reference_branch)
310
244
        if self._destroy_tree:
317
251
            bind_location = self._select_bind_location()
318
252
            local_branch.bind(branch.Branch.open(bind_location))
319
253
        if self._destroy_repository:
 
254
            if self._create_reference:
 
255
                reference_branch.repository.fetch(self.repository)
320
256
            self.bzrdir.destroy_repository()
321
 
        if self._repository_trees is not None:
322
 
            repo.set_make_working_trees(self._repository_trees)