/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/reconfigure.py

  • Committer: Lukáš Lalinský
  • Date: 2007-12-17 17:28:25 UTC
  • mfrom: (3120 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3123.
  • Revision ID: lalinsky@gmail.com-20071217172825-tr3pqm1mhvs3gwnn
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
        self._unbind = False
49
49
        self._bind = False
50
50
        self._destroy_reference = False
 
51
        self._create_reference = False
 
52
        self._destroy_branch = False
51
53
        self._create_branch = False
52
54
        self._destroy_tree = False
53
55
        self._create_tree = False
54
56
        self._create_repository = False
 
57
        self._destroy_repository = False
55
58
 
56
59
    @staticmethod
57
60
    def to_branch(bzrdir):
59
62
 
60
63
        :param bzrdir: The bzrdir to reconfigure
61
64
        :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
65
        """
65
66
        reconfiguration = Reconfigure(bzrdir)
66
67
        reconfiguration._plan_changes(want_tree=False, want_branch=True,
67
 
                                      want_bound=False)
 
68
                                      want_bound=False, want_reference=False)
68
69
        if not reconfiguration.changes_planned():
69
70
            raise errors.AlreadyBranch(bzrdir)
70
71
        return reconfiguration
75
76
 
76
77
        :param bzrdir: The bzrdir to reconfigure
77
78
        :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
79
        """
81
80
        reconfiguration = Reconfigure(bzrdir)
82
81
        reconfiguration._plan_changes(want_tree=True, want_branch=True,
83
 
                                      want_bound=False)
 
82
                                      want_bound=False, want_reference=False)
84
83
        if not reconfiguration.changes_planned():
85
84
            raise errors.AlreadyTree(bzrdir)
86
85
        return reconfiguration
92
91
        :param bzrdir: The bzrdir to reconfigure
93
92
        :param bound_location: The location the checkout should be bound to.
94
93
        :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
94
        """
98
95
        reconfiguration = Reconfigure(bzrdir, bound_location)
99
96
        reconfiguration._plan_changes(want_tree=True, want_branch=True,
100
 
                                      want_bound=True)
 
97
                                      want_bound=True, want_reference=False)
101
98
        if not reconfiguration.changes_planned():
102
99
            raise errors.AlreadyCheckout(bzrdir)
103
100
        return reconfiguration
104
101
 
105
 
    def _plan_changes(self, want_tree, want_branch, want_bound):
 
102
    @classmethod
 
103
    def to_lightweight_checkout(klass, bzrdir, reference_location=None):
 
104
        """Make a Reconfiguration to convert bzrdir into a lightweight checkout
 
105
 
 
106
        :param bzrdir: The bzrdir to reconfigure
 
107
        :param bound_location: The location the checkout should be bound to.
 
108
        :raise errors.AlreadyLightweightCheckout: if bzrdir is already a
 
109
            lightweight checkout
 
110
        """
 
111
        reconfiguration = klass(bzrdir, reference_location)
 
112
        reconfiguration._plan_changes(want_tree=True, want_branch=False,
 
113
                                      want_bound=False, want_reference=True)
 
114
        if not reconfiguration.changes_planned():
 
115
            raise errors.AlreadyLightweightCheckout(bzrdir)
 
116
        return reconfiguration
 
117
 
 
118
    def _plan_changes(self, want_tree, want_branch, want_bound,
 
119
                      want_reference):
106
120
        """Determine which changes are needed to assume the configuration"""
 
121
        if not want_branch and not want_reference:
 
122
            raise errors.ReconfigurationNotSupported(self.bzrdir)
 
123
        if want_branch and want_reference:
 
124
            raise errors.ReconfigurationNotSupported(self.bzrdir)
107
125
        if self.repository is None:
108
 
            self._create_repository = True
 
126
            if not want_reference:
 
127
                self._create_repository = True
 
128
        else:
 
129
            if want_reference and (self.repository.bzrdir.root_transport.base
 
130
                                   == self.bzrdir.root_transport.base):
 
131
                if not self.repository.is_shared():
 
132
                    self._destroy_repository = True
 
133
        if self.referenced_branch is None:
 
134
            if want_reference:
 
135
                self._create_reference = True
 
136
        else:
 
137
            if not want_reference:
 
138
                self._destroy_reference = True
109
139
        if self.local_branch is None:
110
140
            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)
 
141
                self._create_branch = True
 
142
                if want_bound:
 
143
                    self._bind = True
118
144
        else:
119
145
            if want_bound:
120
146
                if self.local_branch.get_bound_location() is None:
131
157
        """Return True if changes are planned, False otherwise"""
132
158
        return (self._unbind or self._bind or self._destroy_tree
133
159
                or self._create_tree or self._destroy_reference
134
 
                or self._create_branch or self._create_repository)
 
160
                or self._create_branch or self._create_repository
 
161
                or self._create_reference)
135
162
 
136
163
    def _check(self):
137
164
        """Raise if reconfiguration would destroy local changes"""
141
168
                raise errors.UncommittedChanges(self.tree)
142
169
 
143
170
    def _select_bind_location(self):
144
 
        """Select a location to bind to.
 
171
        """Select a location to bind or create a reference to.
145
172
 
146
173
        Preference is:
147
174
        1. user specified location
148
175
        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)
 
176
        3. current bind location
 
177
        4. previous bind location (it was a good choice once)
 
178
        5. push location (it's writeable, so committable)
 
179
        6. parent location (it's pullable, so update-from-able)
152
180
        """
153
181
        if self.new_bound_location is not None:
154
182
            return self.new_bound_location
155
183
        if self.local_branch is not None:
 
184
            bound = self.local_branch.get_bound_location()
 
185
            if bound is not None:
 
186
                return bound
156
187
            old_bound = self.local_branch.get_old_bound_location()
157
188
            if old_bound is not None:
158
189
                return old_bound
182
213
            repo = self.bzrdir.create_repository()
183
214
        else:
184
215
            repo = self.repository
185
 
        if self._create_branch:
 
216
        if self._create_branch and self.referenced_branch is not None:
186
217
            repo.fetch(self.referenced_branch.repository,
187
218
                       self.referenced_branch.last_revision())
 
219
        last_revision_info = None
188
220
        if self._destroy_reference:
189
 
            reference_info = self.referenced_branch.last_revision_info()
 
221
            last_revision_info = self.referenced_branch.last_revision_info()
 
222
            self.bzrdir.destroy_branch()
 
223
        if self._destroy_branch:
 
224
            last_revision_info = self.local_branch.last_revision_info()
190
225
            self.bzrdir.destroy_branch()
191
226
        if self._create_branch:
192
227
            local_branch = self.bzrdir.create_branch()
193
 
            local_branch.set_last_revision_info(*reference_info)
 
228
            if last_revision_info is not None:
 
229
                local_branch.set_last_revision_info(*last_revision_info)
194
230
        else:
195
231
            local_branch = self.local_branch
 
232
        if self._create_reference:
 
233
            reference_branch = branch.Branch.open(self._select_bind_location())
 
234
            format = branch.BranchReferenceFormat().initialize(self.bzrdir,
 
235
                reference_branch)
196
236
        if self._destroy_tree:
197
237
            self.bzrdir.destroy_workingtree()
198
238
        if self._create_tree:
202
242
        if self._bind:
203
243
            bind_location = self._select_bind_location()
204
244
            local_branch.bind(branch.Branch.open(bind_location))
 
245
        if self._destroy_repository:
 
246
            if self._create_reference:
 
247
                reference_branch.repository.fetch(self.repository)
 
248
            self.bzrdir.destroy_repository()