~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/reconfigure.py

  • Committer: Aaron Bentley
  • Date: 2007-11-27 19:37:36 UTC
  • mto: This revision was merged to the branch mainline in revision 3052.
  • Revision ID: abentley@panoramicfeedback.com-20071127193736-fjqqz482w0a6400o
SupportĀ reconfigureĀ --lightweight-checkout

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):
64
67
        """
65
68
        reconfiguration = Reconfigure(bzrdir)
66
69
        reconfiguration._plan_changes(want_tree=False, want_branch=True,
67
 
                                      want_bound=False)
 
70
                                      want_bound=False, want_reference=False)
68
71
        if not reconfiguration.changes_planned():
69
72
            raise errors.AlreadyBranch(bzrdir)
70
73
        return reconfiguration
80
83
        """
81
84
        reconfiguration = Reconfigure(bzrdir)
82
85
        reconfiguration._plan_changes(want_tree=True, want_branch=True,
83
 
                                      want_bound=False)
 
86
                                      want_bound=False, want_reference=False)
84
87
        if not reconfiguration.changes_planned():
85
88
            raise errors.AlreadyTree(bzrdir)
86
89
        return reconfiguration
97
100
        """
98
101
        reconfiguration = Reconfigure(bzrdir, bound_location)
99
102
        reconfiguration._plan_changes(want_tree=True, want_branch=True,
100
 
                                      want_bound=True)
 
103
                                      want_bound=True, want_reference=False)
101
104
        if not reconfiguration.changes_planned():
102
105
            raise errors.AlreadyCheckout(bzrdir)
103
106
        return reconfiguration
104
107
 
105
 
    def _plan_changes(self, want_tree, want_branch, want_bound):
 
108
    @classmethod
 
109
    def to_lightweight_checkout(klass, bzrdir, reference_location=None):
 
110
        """Make a Reconfiguration to convert bzrdir into a lightweight checkout
 
111
 
 
112
        :param bzrdir: The bzrdir to reconfigure
 
113
        :param bound_location: The location the checkout should be bound to.
 
114
        :raise errors.AlreadyLightweightCheckout: if bzrdir is already a
 
115
            lightweight checkout
 
116
        :raise errors.ReconfigurationNotSupported: if bzrdir does not contain
 
117
            a branch or branch reference
 
118
        """
 
119
        reconfiguration = klass(bzrdir, reference_location)
 
120
        reconfiguration._plan_changes(want_tree=True, want_branch=False,
 
121
                                      want_bound=False, want_reference=True)
 
122
        if not reconfiguration.changes_planned():
 
123
            raise errors.AlreadyLightweightCheckout(bzrdir)
 
124
        return reconfiguration
 
125
 
 
126
    def _plan_changes(self, want_tree, want_branch, want_bound,
 
127
                      want_reference):
106
128
        """Determine which changes are needed to assume the configuration"""
 
129
        if not want_branch and not want_reference:
 
130
            raise errors.ReconfigurationNotSupported(self.bzrdir)
 
131
        if want_branch and want_reference:
 
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)
107
137
        if self.repository is None:
108
 
            self._create_repository = True
 
138
            if not want_reference:
 
139
                self._create_repository = True
 
140
        else:
 
141
            if want_reference and (self.repository.bzrdir.root_transport.base
 
142
                                   == self.bzrdir.root_transport.base):
 
143
                self._destroy_repository = True
 
144
        if self.referenced_branch is None:
 
145
            if want_reference:
 
146
                self._create_reference = True
 
147
        else:
 
148
            if not want_reference:
 
149
                self._destroy_reference = True
109
150
        if self.local_branch is None:
110
151
            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)
 
152
                self._create_branch = True
 
153
                if want_bound:
 
154
                    self._bind = True
118
155
        else:
119
156
            if want_bound:
120
157
                if self.local_branch.get_bound_location() is None:
141
178
                raise errors.UncommittedChanges(self.tree)
142
179
 
143
180
    def _select_bind_location(self):
144
 
        """Select a location to bind to.
 
181
        """Select a location to bind or create a reference to.
145
182
 
146
183
        Preference is:
147
184
        1. user specified location
148
185
        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)
 
186
        3. current bind location
 
187
        4. previous bind location (it was a good choice once)
 
188
        5. push location (it's writeable, so committable)
 
189
        6. parent location (it's pullable, so update-from-able)
152
190
        """
153
191
        if self.new_bound_location is not None:
154
192
            return self.new_bound_location
155
193
        if self.local_branch is not None:
 
194
            bound = self.local_branch.get_bound_location()
 
195
            if bound is not None:
 
196
                return bound
156
197
            old_bound = self.local_branch.get_old_bound_location()
157
198
            if old_bound is not None:
158
199
                return old_bound
188
229
        if self._destroy_reference:
189
230
            reference_info = self.referenced_branch.last_revision_info()
190
231
            self.bzrdir.destroy_branch()
 
232
        if self._destroy_branch:
 
233
            reference_info = self.local_branch.last_revision_info()
 
234
            self.bzrdir.destroy_branch()
191
235
        if self._create_branch:
192
236
            local_branch = self.bzrdir.create_branch()
193
237
            local_branch.set_last_revision_info(*reference_info)
194
238
        else:
195
239
            local_branch = self.local_branch
 
240
        if self._create_reference:
 
241
            reference_branch = branch.Branch.open(self._select_bind_location())
 
242
            format = branch.BranchReferenceFormat().initialize(self.bzrdir,
 
243
                reference_branch)
196
244
        if self._destroy_tree:
197
245
            self.bzrdir.destroy_workingtree()
198
246
        if self._create_tree:
202
250
        if self._bind:
203
251
            bind_location = self._select_bind_location()
204
252
            local_branch.bind(branch.Branch.open(bind_location))
 
253
        if self._destroy_repository:
 
254
            if self._create_reference:
 
255
                reference_branch.repository.fetch(self.repository)
 
256
            self.bzrdir.destroy_repository()