73
75
class Reconfigure(object):
75
def __init__(self, bzrdir, new_bound_location=None):
77
def __init__(self, controldir, new_bound_location=None):
78
self.controldir = controldir
77
79
self.new_bound_location = new_bound_location
78
80
self.local_repository = None
80
self.repository = self.bzrdir.find_repository()
82
self.repository = self.controldir.find_repository()
81
83
except errors.NoRepositoryPresent:
82
84
self.repository = None
83
85
self.local_repository = None
85
if (self.repository.user_url == self.bzrdir.user_url):
87
if (self.repository.user_url == self.controldir.user_url):
86
88
self.local_repository = self.repository
88
90
self.local_repository = None
90
branch = self.bzrdir.open_branch()
91
if branch.user_url == bzrdir.user_url:
92
branch = self.controldir.open_branch()
93
if branch.user_url == controldir.user_url:
92
94
self.local_branch = branch
93
95
self.referenced_branch = None
114
116
self._repository_trees = None
117
def to_branch(bzrdir):
118
"""Return a Reconfiguration to convert this bzrdir into a branch
119
def to_branch(controldir):
120
"""Return a Reconfiguration to convert this controldir into a branch
120
:param bzrdir: The bzrdir to reconfigure
121
:raise errors.AlreadyBranch: if bzrdir is already a branch
122
:param controldir: The controldir to reconfigure
123
:raise errors.AlreadyBranch: if controldir is already a branch
123
reconfiguration = Reconfigure(bzrdir)
125
reconfiguration = Reconfigure(controldir)
124
126
reconfiguration._plan_changes(want_tree=False, want_branch=True,
125
127
want_bound=False, want_reference=False)
126
128
if not reconfiguration.changes_planned():
127
raise errors.AlreadyBranch(bzrdir)
129
raise errors.AlreadyBranch(controldir)
128
130
return reconfiguration
132
"""Return a Reconfiguration to convert this bzrdir into a tree
133
def to_tree(controldir):
134
"""Return a Reconfiguration to convert this controldir into a tree
134
:param bzrdir: The bzrdir to reconfigure
135
:raise errors.AlreadyTree: if bzrdir is already a tree
136
:param controldir: The controldir to reconfigure
137
:raise errors.AlreadyTree: if controldir is already a tree
137
reconfiguration = Reconfigure(bzrdir)
139
reconfiguration = Reconfigure(controldir)
138
140
reconfiguration._plan_changes(want_tree=True, want_branch=True,
139
141
want_bound=False, want_reference=False)
140
142
if not reconfiguration.changes_planned():
141
raise errors.AlreadyTree(bzrdir)
143
raise errors.AlreadyTree(controldir)
142
144
return reconfiguration
145
def to_checkout(bzrdir, bound_location=None):
146
"""Return a Reconfiguration to convert this bzrdir into a checkout
147
def to_checkout(controldir, bound_location=None):
148
"""Return a Reconfiguration to convert this controldir into a checkout
148
:param bzrdir: The bzrdir to reconfigure
150
:param controldir: The controldir to reconfigure
149
151
:param bound_location: The location the checkout should be bound to.
150
:raise errors.AlreadyCheckout: if bzrdir is already a checkout
152
:raise errors.AlreadyCheckout: if controldir is already a checkout
152
reconfiguration = Reconfigure(bzrdir, bound_location)
154
reconfiguration = Reconfigure(controldir, bound_location)
153
155
reconfiguration._plan_changes(want_tree=True, want_branch=True,
154
156
want_bound=True, want_reference=False)
155
157
if not reconfiguration.changes_planned():
156
raise errors.AlreadyCheckout(bzrdir)
158
raise errors.AlreadyCheckout(controldir)
157
159
return reconfiguration
160
def to_lightweight_checkout(klass, bzrdir, reference_location=None):
161
"""Make a Reconfiguration to convert bzrdir into a lightweight checkout
162
def to_lightweight_checkout(klass, controldir, reference_location=None):
163
"""Make a Reconfiguration to convert controldir into a lightweight checkout
163
:param bzrdir: The bzrdir to reconfigure
165
:param controldir: The controldir to reconfigure
164
166
:param bound_location: The location the checkout should be bound to.
165
:raise errors.AlreadyLightweightCheckout: if bzrdir is already a
167
:raise errors.AlreadyLightweightCheckout: if controldir is already a
166
168
lightweight checkout
168
reconfiguration = klass(bzrdir, reference_location)
170
reconfiguration = klass(controldir, reference_location)
169
171
reconfiguration._plan_changes(want_tree=True, want_branch=False,
170
172
want_bound=False, want_reference=True)
171
173
if not reconfiguration.changes_planned():
172
raise errors.AlreadyLightweightCheckout(bzrdir)
174
raise errors.AlreadyLightweightCheckout(controldir)
173
175
return reconfiguration
176
def to_use_shared(klass, bzrdir):
178
def to_use_shared(klass, controldir):
177
179
"""Convert a standalone branch into a repository branch"""
178
reconfiguration = klass(bzrdir)
180
reconfiguration = klass(controldir)
179
181
reconfiguration._set_use_shared(use_shared=True)
180
182
if not reconfiguration.changes_planned():
181
raise errors.AlreadyUsingShared(bzrdir)
183
raise errors.AlreadyUsingShared(controldir)
182
184
return reconfiguration
185
def to_standalone(klass, bzrdir):
187
def to_standalone(klass, controldir):
186
188
"""Convert a repository branch into a standalone branch"""
187
reconfiguration = klass(bzrdir)
189
reconfiguration = klass(controldir)
188
190
reconfiguration._set_use_shared(use_shared=False)
189
191
if not reconfiguration.changes_planned():
190
raise errors.AlreadyStandalone(bzrdir)
192
raise errors.AlreadyStandalone(controldir)
191
193
return reconfiguration
194
def set_repository_trees(klass, bzrdir, with_trees):
196
def set_repository_trees(klass, controldir, with_trees):
195
197
"""Adjust a repository's working tree presence default"""
196
reconfiguration = klass(bzrdir)
198
reconfiguration = klass(controldir)
197
199
if not reconfiguration.repository.is_shared():
198
raise errors.ReconfigurationNotSupported(reconfiguration.bzrdir)
200
raise errors.ReconfigurationNotSupported(reconfiguration.controldir)
199
201
if with_trees and reconfiguration.repository.make_working_trees():
200
raise errors.AlreadyWithTrees(bzrdir)
202
raise errors.AlreadyWithTrees(controldir)
201
203
elif (not with_trees
202
204
and not reconfiguration.repository.make_working_trees()):
203
raise errors.AlreadyWithNoTrees(bzrdir)
205
raise errors.AlreadyWithNoTrees(controldir)
205
207
reconfiguration._repository_trees = with_trees
206
208
return reconfiguration
344
346
reference_branch.repository.fetch(self.repository)
345
347
elif self.local_branch is not None and not self._destroy_branch:
346
348
up = self.local_branch.user_transport.clone('..')
347
up_bzrdir = bzrdir.BzrDir.open_containing_from_transport(up)[0]
348
new_repo = up_bzrdir.find_repository()
349
up_controldir = controldir.ControlDir.open_containing_from_transport(
351
new_repo = up_controldir.find_repository()
349
352
new_repo.fetch(self.repository)
350
353
last_revision_info = None
351
354
if self._destroy_reference:
352
355
last_revision_info = self.referenced_branch.last_revision_info()
353
self.bzrdir.destroy_branch()
356
self.controldir.destroy_branch()
354
357
if self._destroy_branch:
355
358
last_revision_info = self.local_branch.last_revision_info()
356
359
if self._create_reference:
357
360
self.local_branch.tags.merge_to(reference_branch.tags)
358
self.bzrdir.destroy_branch()
361
self.controldir.destroy_branch()
359
362
if self._create_branch:
360
local_branch = self.bzrdir.create_branch()
363
local_branch = self.controldir.create_branch()
361
364
if last_revision_info is not None:
362
365
local_branch.set_last_revision_info(*last_revision_info)
363
366
if self._destroy_reference: