~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/reconfigure.py

  • Committer: John Arbash Meinel
  • Date: 2008-08-25 21:50:11 UTC
  • mfrom: (0.11.3 tools)
  • mto: This revision was merged to the branch mainline in revision 3659.
  • Revision ID: john@arbash-meinel.com-20080825215011-de9esmzgkue3e522
Merge in Lukáš's helper scripts.
Update the packaging documents to describe how to do the releases
using bzr-builddeb to package all distro platforms
simultaneously.

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:
48
55
        self._unbind = False
49
56
        self._bind = False
50
57
        self._destroy_reference = False
 
58
        self._create_reference = False
 
59
        self._destroy_branch = False
51
60
        self._create_branch = False
52
61
        self._destroy_tree = False
53
62
        self._create_tree = False
54
63
        self._create_repository = False
 
64
        self._destroy_repository = False
55
65
 
56
66
    @staticmethod
57
67
    def to_branch(bzrdir):
59
69
 
60
70
        :param bzrdir: The bzrdir to reconfigure
61
71
        :raise errors.AlreadyBranch: if bzrdir is already a branch
62
 
        :raise errors.ReconfigurationNotSupported: if bzrdir does not contain
63
 
            a branch or branch reference
64
72
        """
65
73
        reconfiguration = Reconfigure(bzrdir)
66
74
        reconfiguration._plan_changes(want_tree=False, want_branch=True,
67
 
                                      want_bound=False)
 
75
                                      want_bound=False, want_reference=False)
68
76
        if not reconfiguration.changes_planned():
69
77
            raise errors.AlreadyBranch(bzrdir)
70
78
        return reconfiguration
75
83
 
76
84
        :param bzrdir: The bzrdir to reconfigure
77
85
        :raise errors.AlreadyTree: if bzrdir is already a tree
78
 
        :raise errors.ReconfigurationNotSupported: if bzrdir does not contain
79
 
            a branch or branch reference
80
86
        """
81
87
        reconfiguration = Reconfigure(bzrdir)
82
88
        reconfiguration._plan_changes(want_tree=True, want_branch=True,
83
 
                                      want_bound=False)
 
89
                                      want_bound=False, want_reference=False)
84
90
        if not reconfiguration.changes_planned():
85
91
            raise errors.AlreadyTree(bzrdir)
86
92
        return reconfiguration
92
98
        :param bzrdir: The bzrdir to reconfigure
93
99
        :param bound_location: The location the checkout should be bound to.
94
100
        :raise errors.AlreadyCheckout: if bzrdir is already a checkout
95
 
        :raise errors.ReconfigurationNotSupported: if bzrdir does not contain
96
 
            a branch or branch reference
97
101
        """
98
102
        reconfiguration = Reconfigure(bzrdir, bound_location)
99
103
        reconfiguration._plan_changes(want_tree=True, want_branch=True,
100
 
                                      want_bound=True)
 
104
                                      want_bound=True, want_reference=False)
101
105
        if not reconfiguration.changes_planned():
102
106
            raise errors.AlreadyCheckout(bzrdir)
103
107
        return reconfiguration
104
108
 
105
 
    def _plan_changes(self, want_tree, want_branch, want_bound):
 
109
    @classmethod
 
110
    def to_lightweight_checkout(klass, bzrdir, reference_location=None):
 
111
        """Make a Reconfiguration to convert bzrdir into a lightweight checkout
 
112
 
 
113
        :param bzrdir: The bzrdir to reconfigure
 
114
        :param bound_location: The location the checkout should be bound to.
 
115
        :raise errors.AlreadyLightweightCheckout: if bzrdir is already a
 
116
            lightweight checkout
 
117
        """
 
118
        reconfiguration = klass(bzrdir, reference_location)
 
119
        reconfiguration._plan_changes(want_tree=True, want_branch=False,
 
120
                                      want_bound=False, want_reference=True)
 
121
        if not reconfiguration.changes_planned():
 
122
            raise errors.AlreadyLightweightCheckout(bzrdir)
 
123
        return reconfiguration
 
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
 
 
143
    def _plan_changes(self, want_tree, want_branch, want_bound,
 
144
                      want_reference):
106
145
        """Determine which changes are needed to assume the configuration"""
 
146
        if not want_branch and not want_reference:
 
147
            raise errors.ReconfigurationNotSupported(self.bzrdir)
 
148
        if want_branch and want_reference:
 
149
            raise errors.ReconfigurationNotSupported(self.bzrdir)
107
150
        if self.repository is None:
108
 
            self._create_repository = True
 
151
            if not want_reference:
 
152
                self._create_repository = True
 
153
        else:
 
154
            if want_reference and (self.repository.bzrdir.root_transport.base
 
155
                                   == self.bzrdir.root_transport.base):
 
156
                if not self.repository.is_shared():
 
157
                    self._destroy_repository = True
 
158
        if self.referenced_branch is None:
 
159
            if want_reference:
 
160
                self._create_reference = True
 
161
                if self.local_branch is not None:
 
162
                    self._destroy_branch = True
 
163
        else:
 
164
            if not want_reference:
 
165
                self._destroy_reference = True
109
166
        if self.local_branch is None:
110
167
            if want_branch is True:
111
 
                if self.referenced_branch is not None:
112
 
                    self._destroy_reference = True
113
 
                    self._create_branch = True
114
 
                    if want_bound:
115
 
                        self._bind = True
116
 
                else:
117
 
                    raise errors.ReconfigurationNotSupported(self.bzrdir)
 
168
                self._create_branch = True
 
169
                if want_bound:
 
170
                    self._bind = True
118
171
        else:
119
172
            if want_bound:
120
173
                if self.local_branch.get_bound_location() is None:
127
180
        if want_tree and self.tree is None:
128
181
            self._create_tree = True
129
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
 
130
193
    def changes_planned(self):
131
194
        """Return True if changes are planned, False otherwise"""
132
195
        return (self._unbind or self._bind or self._destroy_tree
133
196
                or self._create_tree or self._destroy_reference
134
 
                or self._create_branch or self._create_repository)
 
197
                or self._create_branch or self._create_repository
 
198
                or self._create_reference or self._destroy_repository)
135
199
 
136
200
    def _check(self):
137
201
        """Raise if reconfiguration would destroy local changes"""
139
203
            changes = self.tree.changes_from(self.tree.basis_tree())
140
204
            if changes.has_changed():
141
205
                raise errors.UncommittedChanges(self.tree)
 
206
        if self._create_reference and self.local_branch is not None:
 
207
            reference_branch = branch.Branch.open(self._select_bind_location())
 
208
            if (reference_branch.last_revision() !=
 
209
                self.local_branch.last_revision()):
 
210
                raise errors.UnsyncedBranches(self.bzrdir, reference_branch)
142
211
 
143
212
    def _select_bind_location(self):
144
 
        """Select a location to bind to.
 
213
        """Select a location to bind or create a reference to.
145
214
 
146
215
        Preference is:
147
216
        1. user specified location
148
217
        2. branch reference location (it's a kind of bind location)
149
 
        3. previous bind location (it was a good choice once)
150
 
        4. push location (it's writeable, so committable)
151
 
        5. parent location (it's pullable, so update-from-able)
 
218
        3. current bind location
 
219
        4. previous bind location (it was a good choice once)
 
220
        5. push location (it's writeable, so committable)
 
221
        6. parent location (it's pullable, so update-from-able)
152
222
        """
153
223
        if self.new_bound_location is not None:
154
224
            return self.new_bound_location
155
225
        if self.local_branch is not None:
 
226
            bound = self.local_branch.get_bound_location()
 
227
            if bound is not None:
 
228
                return bound
156
229
            old_bound = self.local_branch.get_old_bound_location()
157
230
            if old_bound is not None:
158
231
                return old_bound
180
253
            self._check()
181
254
        if self._create_repository:
182
255
            repo = self.bzrdir.create_repository()
 
256
            if self.local_branch and not self._destroy_branch:
 
257
                repo.fetch(self.local_branch.repository,
 
258
                           self.local_branch.last_revision())
183
259
        else:
184
260
            repo = self.repository
185
 
        if self._create_branch:
 
261
        if self._create_branch and self.referenced_branch is not None:
186
262
            repo.fetch(self.referenced_branch.repository,
187
263
                       self.referenced_branch.last_revision())
 
264
        if self._create_reference:
 
265
            reference_branch = branch.Branch.open(self._select_bind_location())
 
266
        if self._destroy_repository:
 
267
            if self._create_reference:
 
268
                reference_branch.repository.fetch(self.repository)
 
269
            elif self.local_branch is not None and not self._destroy_branch:
 
270
                up = self.local_branch.bzrdir.root_transport.clone('..')
 
271
                up_bzrdir = bzrdir.BzrDir.open_containing_from_transport(up)[0]
 
272
                new_repo = up_bzrdir.find_repository()
 
273
                new_repo.fetch(self.repository)
 
274
        last_revision_info = None
188
275
        if self._destroy_reference:
189
 
            reference_info = self.referenced_branch.last_revision_info()
 
276
            last_revision_info = self.referenced_branch.last_revision_info()
 
277
            self.bzrdir.destroy_branch()
 
278
        if self._destroy_branch:
 
279
            last_revision_info = self.local_branch.last_revision_info()
 
280
            if self._create_reference:
 
281
                self.local_branch.tags.merge_to(reference_branch.tags)
190
282
            self.bzrdir.destroy_branch()
191
283
        if self._create_branch:
192
284
            local_branch = self.bzrdir.create_branch()
193
 
            local_branch.set_last_revision_info(*reference_info)
 
285
            if last_revision_info is not None:
 
286
                local_branch.set_last_revision_info(*last_revision_info)
 
287
            if self._destroy_reference:
 
288
                self.referenced_branch.tags.merge_to(local_branch.tags)
194
289
        else:
195
290
            local_branch = self.local_branch
 
291
        if self._create_reference:
 
292
            format = branch.BranchReferenceFormat().initialize(self.bzrdir,
 
293
                reference_branch)
196
294
        if self._destroy_tree:
197
295
            self.bzrdir.destroy_workingtree()
198
296
        if self._create_tree:
202
300
        if self._bind:
203
301
            bind_location = self._select_bind_location()
204
302
            local_branch.bind(branch.Branch.open(bind_location))
 
303
        if self._destroy_repository:
 
304
            self.bzrdir.destroy_repository()