bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4597.9.2
by Vincent Ladeuil
Merge bzr.dev into cleanup |
1 |
# Copyright (C) 2007-2010 Canonical Ltd
|
2796.2.1
by Aaron Bentley
Begin work on reconfigure command |
2 |
#
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2796.2.1
by Aaron Bentley
Begin work on reconfigure command |
16 |
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
17 |
"""Reconfigure a controldir into a new tree/branch/repository layout.
|
4509.3.38
by Martin Pool
Move reconfigure --stacked-on core code into reconfigure.py |
18 |
|
19 |
Various types of reconfiguration operation are available either by
|
|
20 |
constructing a class or using a factory method on Reconfigure.
|
|
21 |
"""
|
|
22 |
||
6379.6.7
by Jelmer Vernooij
Move importing from future until after doc string, otherwise the doc string will disappear. |
23 |
from __future__ import absolute_import |
24 |
||
2796.2.1
by Aaron Bentley
Begin work on reconfigure command |
25 |
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
26 |
from . import ( |
2796.2.3
by Aaron Bentley
Implement conversion to tree and checkout |
27 |
branch, |
6207.3.3
by jelmer at samba
Fix tests and the like. |
28 |
controldir, |
2796.2.1
by Aaron Bentley
Begin work on reconfigure command |
29 |
errors, |
4509.3.38
by Martin Pool
Move reconfigure --stacked-on core code into reconfigure.py |
30 |
trace, |
31 |
ui, |
|
32 |
urlutils, |
|
2796.2.1
by Aaron Bentley
Begin work on reconfigure command |
33 |
)
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
34 |
from .i18n import gettext |
4509.3.38
by Martin Pool
Move reconfigure --stacked-on core code into reconfigure.py |
35 |
|
36 |
# TODO: common base class for all reconfigure operations, making no
|
|
37 |
# assumptions about what kind of change will be done.
|
|
38 |
||
39 |
||
6734.1.17
by Jelmer Vernooij
Move format custom errors. |
40 |
class BzrDirError(errors.BzrError): |
6734.1.16
by Jelmer Vernooij
Move reconfigure errors. |
41 |
|
42 |
def __init__(self, controldir): |
|
43 |
display_url = urlutils.unescape_for_display(controldir.user_url, |
|
44 |
'ascii') |
|
6734.1.17
by Jelmer Vernooij
Move format custom errors. |
45 |
errors.BzrError.__init__(self, controldir=controldir, |
46 |
display_url=display_url) |
|
6734.1.16
by Jelmer Vernooij
Move reconfigure errors. |
47 |
|
48 |
||
49 |
class NoBindLocation(BzrDirError): |
|
50 |
||
51 |
_fmt = "No location could be found to bind to at %(display_url)s." |
|
52 |
||
53 |
||
54 |
class UnsyncedBranches(BzrDirError): |
|
55 |
||
56 |
_fmt = ("'%(display_url)s' is not in sync with %(target_url)s. See" |
|
57 |
" brz help sync-for-reconfigure.") |
|
58 |
||
59 |
def __init__(self, controldir, target_branch): |
|
6744
by Jelmer Vernooij
Merge lp:~jelmer/brz/move-errors-knit. |
60 |
errors.BzrError.__init__(self, controldir) |
6734.1.16
by Jelmer Vernooij
Move reconfigure errors. |
61 |
from . import urlutils |
62 |
self.target_url = urlutils.unescape_for_display(target_branch.base, |
|
63 |
'ascii') |
|
64 |
||
65 |
||
66 |
class AlreadyBranch(BzrDirError): |
|
67 |
||
68 |
_fmt = "'%(display_url)s' is already a branch." |
|
69 |
||
70 |
||
71 |
class AlreadyTree(BzrDirError): |
|
72 |
||
73 |
_fmt = "'%(display_url)s' is already a tree." |
|
74 |
||
75 |
||
76 |
class AlreadyCheckout(BzrDirError): |
|
77 |
||
78 |
_fmt = "'%(display_url)s' is already a checkout." |
|
79 |
||
80 |
||
81 |
class AlreadyLightweightCheckout(BzrDirError): |
|
82 |
||
83 |
_fmt = "'%(display_url)s' is already a lightweight checkout." |
|
84 |
||
85 |
||
86 |
class AlreadyUsingShared(BzrDirError): |
|
87 |
||
88 |
_fmt = "'%(display_url)s' is already using a shared repository." |
|
89 |
||
90 |
||
91 |
class AlreadyStandalone(BzrDirError): |
|
92 |
||
93 |
_fmt = "'%(display_url)s' is already standalone." |
|
94 |
||
95 |
||
96 |
class AlreadyWithTrees(BzrDirError): |
|
97 |
||
98 |
_fmt = ("Shared repository '%(display_url)s' already creates " |
|
99 |
"working trees.") |
|
100 |
||
101 |
||
102 |
class AlreadyWithNoTrees(BzrDirError): |
|
103 |
||
104 |
_fmt = ("Shared repository '%(display_url)s' already doesn't create " |
|
105 |
"working trees.") |
|
106 |
||
107 |
||
108 |
class ReconfigurationNotSupported(BzrDirError): |
|
109 |
||
110 |
_fmt = "Requested reconfiguration of '%(display_url)s' is not supported." |
|
111 |
||
112 |
||
4509.3.38
by Martin Pool
Move reconfigure --stacked-on core code into reconfigure.py |
113 |
class ReconfigureStackedOn(object): |
114 |
"""Reconfigures a branch to be stacked on another branch.""" |
|
115 |
||
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
116 |
def apply(self, controldir, stacked_on_url): |
117 |
branch = controldir.open_branch() |
|
4509.3.38
by Martin Pool
Move reconfigure --stacked-on core code into reconfigure.py |
118 |
# it may be a path relative to the cwd or a url; the branch wants
|
119 |
# a path relative to itself...
|
|
120 |
on_url = urlutils.relative_url(branch.base, |
|
121 |
urlutils.normalize_url(stacked_on_url)) |
|
122 |
branch.lock_write() |
|
123 |
try: |
|
124 |
branch.set_stacked_on_url(on_url) |
|
125 |
if not trace.is_quiet(): |
|
6138.3.4
by Jonathan Riddell
add gettext() to uses of trace.note() |
126 |
ui.ui_factory.note(gettext( |
127 |
"{0} is now stacked on {1}\n").format( |
|
128 |
branch.base, branch.get_stacked_on_url())) |
|
4509.3.38
by Martin Pool
Move reconfigure --stacked-on core code into reconfigure.py |
129 |
finally: |
130 |
branch.unlock() |
|
131 |
||
132 |
||
4509.3.39
by Martin Pool
Move reconfigure --unstacked to reconfigure.py |
133 |
class ReconfigureUnstacked(object): |
134 |
||
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
135 |
def apply(self, controldir): |
136 |
branch = controldir.open_branch() |
|
4509.3.39
by Martin Pool
Move reconfigure --unstacked to reconfigure.py |
137 |
branch.lock_write() |
138 |
try: |
|
139 |
branch.set_stacked_on_url(None) |
|
140 |
if not trace.is_quiet(): |
|
6138.3.4
by Jonathan Riddell
add gettext() to uses of trace.note() |
141 |
ui.ui_factory.note(gettext( |
142 |
"%s is now not stacked\n") |
|
4509.3.39
by Martin Pool
Move reconfigure --unstacked to reconfigure.py |
143 |
% (branch.base,)) |
144 |
finally: |
|
145 |
branch.unlock() |
|
146 |
||
147 |
||
2796.2.1
by Aaron Bentley
Begin work on reconfigure command |
148 |
class Reconfigure(object): |
149 |
||
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
150 |
def __init__(self, controldir, new_bound_location=None): |
151 |
self.controldir = controldir |
|
2796.2.3
by Aaron Bentley
Implement conversion to tree and checkout |
152 |
self.new_bound_location = new_bound_location |
4509.1.1
by Jelmer Vernooij
Fix for unbound variable in reconfiguring lightweight checkout |
153 |
self.local_repository = None |
2796.2.1
by Aaron Bentley
Begin work on reconfigure command |
154 |
try: |
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
155 |
self.repository = self.controldir.find_repository() |
2796.2.7
by Aaron Bentley
Implement converting a lightweight checkout to a branch |
156 |
except errors.NoRepositoryPresent: |
157 |
self.repository = None |
|
4324.2.1
by Jelmer Vernooij
Make sure class member local_repository of reconfigure is initialized. |
158 |
self.local_repository = None |
3311.2.2
by Aaron Bentley
Flesh out to_sharing |
159 |
else: |
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
160 |
if (self.repository.user_url == self.controldir.user_url): |
3311.2.2
by Aaron Bentley
Flesh out to_sharing |
161 |
self.local_repository = self.repository |
162 |
else: |
|
163 |
self.local_repository = None |
|
2796.2.7
by Aaron Bentley
Implement converting a lightweight checkout to a branch |
164 |
try: |
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
165 |
branch = self.controldir.open_branch() |
166 |
if branch.user_url == controldir.user_url: |
|
2796.2.3
by Aaron Bentley
Implement conversion to tree and checkout |
167 |
self.local_branch = branch |
168 |
self.referenced_branch = None |
|
169 |
else: |
|
170 |
self.local_branch = None |
|
171 |
self.referenced_branch = branch |
|
2796.2.1
by Aaron Bentley
Begin work on reconfigure command |
172 |
except errors.NotBranchError: |
2796.2.3
by Aaron Bentley
Implement conversion to tree and checkout |
173 |
self.local_branch = None |
2796.2.9
by Aaron Bentley
Ensure conversion from lightweight checkout works |
174 |
self.referenced_branch = None |
2796.2.1
by Aaron Bentley
Begin work on reconfigure command |
175 |
try: |
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
176 |
self.tree = controldir.open_workingtree() |
2796.2.1
by Aaron Bentley
Begin work on reconfigure command |
177 |
except errors.NoWorkingTree: |
2796.2.3
by Aaron Bentley
Implement conversion to tree and checkout |
178 |
self.tree = None |
2796.2.14
by Aaron Bentley
Updates from review |
179 |
self._unbind = False |
180 |
self._bind = False |
|
181 |
self._destroy_reference = False |
|
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
182 |
self._create_reference = False |
183 |
self._destroy_branch = False |
|
2796.2.14
by Aaron Bentley
Updates from review |
184 |
self._create_branch = False |
185 |
self._destroy_tree = False |
|
186 |
self._create_tree = False |
|
187 |
self._create_repository = False |
|
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
188 |
self._destroy_repository = False |
3983.3.7
by Marius Kruger
apply changes in apply again |
189 |
self._repository_trees = None |
2796.2.3
by Aaron Bentley
Implement conversion to tree and checkout |
190 |
|
191 |
@staticmethod
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
192 |
def to_branch(controldir): |
193 |
"""Return a Reconfiguration to convert this controldir into a branch |
|
2796.2.16
by Aaron Bentley
Documentation updates from review |
194 |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
195 |
:param controldir: The controldir to reconfigure
|
6734.1.16
by Jelmer Vernooij
Move reconfigure errors. |
196 |
:raise AlreadyBranch: if controldir is already a branch
|
2796.2.16
by Aaron Bentley
Documentation updates from review |
197 |
"""
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
198 |
reconfiguration = Reconfigure(controldir) |
2796.2.15
by Aaron Bentley
More updates from review |
199 |
reconfiguration._plan_changes(want_tree=False, want_branch=True, |
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
200 |
want_bound=False, want_reference=False) |
2796.2.14
by Aaron Bentley
Updates from review |
201 |
if not reconfiguration.changes_planned(): |
6734.1.16
by Jelmer Vernooij
Move reconfigure errors. |
202 |
raise AlreadyBranch(controldir) |
2796.2.3
by Aaron Bentley
Implement conversion to tree and checkout |
203 |
return reconfiguration |
204 |
||
205 |
@staticmethod
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
206 |
def to_tree(controldir): |
207 |
"""Return a Reconfiguration to convert this controldir into a tree |
|
2796.2.16
by Aaron Bentley
Documentation updates from review |
208 |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
209 |
:param controldir: The controldir to reconfigure
|
6734.1.16
by Jelmer Vernooij
Move reconfigure errors. |
210 |
:raise AlreadyTree: if controldir is already a tree
|
2796.2.16
by Aaron Bentley
Documentation updates from review |
211 |
"""
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
212 |
reconfiguration = Reconfigure(controldir) |
2796.2.15
by Aaron Bentley
More updates from review |
213 |
reconfiguration._plan_changes(want_tree=True, want_branch=True, |
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
214 |
want_bound=False, want_reference=False) |
2796.2.14
by Aaron Bentley
Updates from review |
215 |
if not reconfiguration.changes_planned(): |
6734.1.16
by Jelmer Vernooij
Move reconfigure errors. |
216 |
raise AlreadyTree(controldir) |
2796.2.3
by Aaron Bentley
Implement conversion to tree and checkout |
217 |
return reconfiguration |
218 |
||
219 |
@staticmethod
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
220 |
def to_checkout(controldir, bound_location=None): |
221 |
"""Return a Reconfiguration to convert this controldir into a checkout |
|
2796.2.16
by Aaron Bentley
Documentation updates from review |
222 |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
223 |
:param controldir: The controldir to reconfigure
|
2796.2.16
by Aaron Bentley
Documentation updates from review |
224 |
:param bound_location: The location the checkout should be bound to.
|
6734.1.16
by Jelmer Vernooij
Move reconfigure errors. |
225 |
:raise AlreadyCheckout: if controldir is already a checkout
|
2796.2.16
by Aaron Bentley
Documentation updates from review |
226 |
"""
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
227 |
reconfiguration = Reconfigure(controldir, bound_location) |
2796.2.15
by Aaron Bentley
More updates from review |
228 |
reconfiguration._plan_changes(want_tree=True, want_branch=True, |
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
229 |
want_bound=True, want_reference=False) |
2796.2.14
by Aaron Bentley
Updates from review |
230 |
if not reconfiguration.changes_planned(): |
6734.1.16
by Jelmer Vernooij
Move reconfigure errors. |
231 |
raise AlreadyCheckout(controldir) |
2796.2.3
by Aaron Bentley
Implement conversion to tree and checkout |
232 |
return reconfiguration |
233 |
||
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
234 |
@classmethod
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
235 |
def to_lightweight_checkout(klass, controldir, reference_location=None): |
236 |
"""Make a Reconfiguration to convert controldir into a lightweight checkout |
|
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
237 |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
238 |
:param controldir: The controldir to reconfigure
|
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
239 |
:param bound_location: The location the checkout should be bound to.
|
6734.1.16
by Jelmer Vernooij
Move reconfigure errors. |
240 |
:raise AlreadyLightweightCheckout: if controldir is already a
|
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
241 |
lightweight checkout
|
242 |
"""
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
243 |
reconfiguration = klass(controldir, reference_location) |
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
244 |
reconfiguration._plan_changes(want_tree=True, want_branch=False, |
245 |
want_bound=False, want_reference=True) |
|
246 |
if not reconfiguration.changes_planned(): |
|
6734.1.16
by Jelmer Vernooij
Move reconfigure errors. |
247 |
raise AlreadyLightweightCheckout(controldir) |
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
248 |
return reconfiguration |
249 |
||
3311.2.1
by Aaron Bentley
Initial make-sharing functionality |
250 |
@classmethod
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
251 |
def to_use_shared(klass, controldir): |
3311.2.6
by Aaron Bentley
rename 'sharing' to 'use-shared' |
252 |
"""Convert a standalone branch into a repository branch""" |
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
253 |
reconfiguration = klass(controldir) |
3311.2.6
by Aaron Bentley
rename 'sharing' to 'use-shared' |
254 |
reconfiguration._set_use_shared(use_shared=True) |
3311.2.2
by Aaron Bentley
Flesh out to_sharing |
255 |
if not reconfiguration.changes_planned(): |
6734.1.16
by Jelmer Vernooij
Move reconfigure errors. |
256 |
raise AlreadyUsingShared(controldir) |
3311.2.1
by Aaron Bentley
Initial make-sharing functionality |
257 |
return reconfiguration |
258 |
||
3311.2.4
by Aaron Bentley
Implement conversion to standalone |
259 |
@classmethod
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
260 |
def to_standalone(klass, controldir): |
3311.2.6
by Aaron Bentley
rename 'sharing' to 'use-shared' |
261 |
"""Convert a repository branch into a standalone branch""" |
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
262 |
reconfiguration = klass(controldir) |
3311.2.6
by Aaron Bentley
rename 'sharing' to 'use-shared' |
263 |
reconfiguration._set_use_shared(use_shared=False) |
3311.2.4
by Aaron Bentley
Implement conversion to standalone |
264 |
if not reconfiguration.changes_planned(): |
6734.1.16
by Jelmer Vernooij
Move reconfigure errors. |
265 |
raise AlreadyStandalone(controldir) |
3311.2.4
by Aaron Bentley
Implement conversion to standalone |
266 |
return reconfiguration |
267 |
||
3921.4.2
by Matthew Fuller
Add support in Reconfigure for manipulating the repository setting for |
268 |
@classmethod
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
269 |
def set_repository_trees(klass, controldir, with_trees): |
3983.3.2
by Marius Kruger
make changes directly in set_repository_trees() |
270 |
"""Adjust a repository's working tree presence default""" |
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
271 |
reconfiguration = klass(controldir) |
3921.4.10
by Matthew Fuller
Stop trying to use _plan_changes() wholesale and just move all the |
272 |
if not reconfiguration.repository.is_shared(): |
6734.1.16
by Jelmer Vernooij
Move reconfigure errors. |
273 |
raise ReconfigurationNotSupported(reconfiguration.controldir) |
3983.3.2
by Marius Kruger
make changes directly in set_repository_trees() |
274 |
if with_trees and reconfiguration.repository.make_working_trees(): |
6734.1.16
by Jelmer Vernooij
Move reconfigure errors. |
275 |
raise AlreadyWithTrees(controldir) |
3983.3.11
by Vincent Ladeuil
Fix indentation as per Aaron's review and then some. |
276 |
elif (not with_trees |
277 |
and not reconfiguration.repository.make_working_trees()): |
|
6734.1.16
by Jelmer Vernooij
Move reconfigure errors. |
278 |
raise AlreadyWithNoTrees(controldir) |
3983.3.2
by Marius Kruger
make changes directly in set_repository_trees() |
279 |
else: |
3983.3.7
by Marius Kruger
apply changes in apply again |
280 |
reconfiguration._repository_trees = with_trees |
3921.4.2
by Matthew Fuller
Add support in Reconfigure for manipulating the repository setting for |
281 |
return reconfiguration |
282 |
||
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
283 |
def _plan_changes(self, want_tree, want_branch, want_bound, |
3921.4.9
by Matthew Fuller
Back out _plan_changes() changes for trees frobbing. It's way more |
284 |
want_reference): |
2796.2.10
by Aaron Bentley
Ensure that shared repositories are used where possible |
285 |
"""Determine which changes are needed to assume the configuration""" |
3921.4.9
by Matthew Fuller
Back out _plan_changes() changes for trees frobbing. It's way more |
286 |
if not want_branch and not want_reference: |
6734.1.16
by Jelmer Vernooij
Move reconfigure errors. |
287 |
raise ReconfigurationNotSupported(self.controldir) |
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
288 |
if want_branch and want_reference: |
6734.1.16
by Jelmer Vernooij
Move reconfigure errors. |
289 |
raise ReconfigurationNotSupported(self.controldir) |
2796.2.7
by Aaron Bentley
Implement converting a lightweight checkout to a branch |
290 |
if self.repository is None: |
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
291 |
if not want_reference: |
292 |
self._create_repository = True |
|
293 |
else: |
|
5158.6.9
by Martin Pool
Simplify various code to use user_url |
294 |
if want_reference and ( |
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
295 |
self.repository.user_url == self.controldir.user_url): |
2796.2.25
by Aaron Bentley
Avoid destroying shared repositories |
296 |
if not self.repository.is_shared(): |
297 |
self._destroy_repository = True |
|
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
298 |
if self.referenced_branch is None: |
299 |
if want_reference: |
|
300 |
self._create_reference = True |
|
2796.2.31
by Aaron Bentley
Fetch tags to reference branch when converting to checkout |
301 |
if self.local_branch is not None: |
302 |
self._destroy_branch = True |
|
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
303 |
else: |
304 |
if not want_reference: |
|
305 |
self._destroy_reference = True |
|
2796.2.3
by Aaron Bentley
Implement conversion to tree and checkout |
306 |
if self.local_branch is None: |
2796.2.15
by Aaron Bentley
More updates from review |
307 |
if want_branch is True: |
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
308 |
self._create_branch = True |
309 |
if want_bound: |
|
310 |
self._bind = True |
|
2796.2.3
by Aaron Bentley
Implement conversion to tree and checkout |
311 |
else: |
2796.2.15
by Aaron Bentley
More updates from review |
312 |
if want_bound: |
2796.2.3
by Aaron Bentley
Implement conversion to tree and checkout |
313 |
if self.local_branch.get_bound_location() is None: |
2796.2.14
by Aaron Bentley
Updates from review |
314 |
self._bind = True |
2796.2.3
by Aaron Bentley
Implement conversion to tree and checkout |
315 |
else: |
316 |
if self.local_branch.get_bound_location() is not None: |
|
2796.2.14
by Aaron Bentley
Updates from review |
317 |
self._unbind = True |
2796.2.15
by Aaron Bentley
More updates from review |
318 |
if not want_tree and self.tree is not None: |
2796.2.14
by Aaron Bentley
Updates from review |
319 |
self._destroy_tree = True |
2796.2.15
by Aaron Bentley
More updates from review |
320 |
if want_tree and self.tree is None: |
2796.2.14
by Aaron Bentley
Updates from review |
321 |
self._create_tree = True |
2796.2.3
by Aaron Bentley
Implement conversion to tree and checkout |
322 |
|
3311.2.6
by Aaron Bentley
rename 'sharing' to 'use-shared' |
323 |
def _set_use_shared(self, use_shared=None): |
324 |
if use_shared is None: |
|
3311.2.1
by Aaron Bentley
Initial make-sharing functionality |
325 |
return
|
3311.2.6
by Aaron Bentley
rename 'sharing' to 'use-shared' |
326 |
if use_shared: |
3311.2.2
by Aaron Bentley
Flesh out to_sharing |
327 |
if self.local_repository is not None: |
328 |
self._destroy_repository = True |
|
3311.2.4
by Aaron Bentley
Implement conversion to standalone |
329 |
else: |
330 |
if self.local_repository is None: |
|
331 |
self._create_repository = True |
|
3311.2.1
by Aaron Bentley
Initial make-sharing functionality |
332 |
|
2796.2.14
by Aaron Bentley
Updates from review |
333 |
def changes_planned(self): |
2796.2.11
by Aaron Bentley
Cleanups |
334 |
"""Return True if changes are planned, False otherwise""" |
2796.2.14
by Aaron Bentley
Updates from review |
335 |
return (self._unbind or self._bind or self._destroy_tree |
336 |
or self._create_tree or self._destroy_reference |
|
2796.2.26
by Aaron Bentley
Support converting standalone tree to lightweight checkout |
337 |
or self._create_branch or self._create_repository |
3983.3.5
by Marius Kruger
put bracket back where we found it |
338 |
or self._create_reference or self._destroy_repository) |
2796.2.1
by Aaron Bentley
Begin work on reconfigure command |
339 |
|
340 |
def _check(self): |
|
2796.2.11
by Aaron Bentley
Cleanups |
341 |
"""Raise if reconfiguration would destroy local changes""" |
4721.3.2
by Vincent Ladeuil
Simplify mutable_tree.has_changes() and update call sites. |
342 |
if self._destroy_tree and self.tree.has_changes(): |
2796.2.3
by Aaron Bentley
Implement conversion to tree and checkout |
343 |
raise errors.UncommittedChanges(self.tree) |
3338.1.1
by Aaron Bentley
Raise an error when converting a branch to a lightweight checkout loses data |
344 |
if self._create_reference and self.local_branch is not None: |
345 |
reference_branch = branch.Branch.open(self._select_bind_location()) |
|
346 |
if (reference_branch.last_revision() != |
|
347 |
self.local_branch.last_revision()): |
|
6744
by Jelmer Vernooij
Merge lp:~jelmer/brz/move-errors-knit. |
348 |
raise UnsyncedBranches(self.controldir, reference_branch) |
2796.2.3
by Aaron Bentley
Implement conversion to tree and checkout |
349 |
|
350 |
def _select_bind_location(self): |
|
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
351 |
"""Select a location to bind or create a reference to. |
2796.2.11
by Aaron Bentley
Cleanups |
352 |
|
353 |
Preference is:
|
|
354 |
1. user specified location
|
|
355 |
2. branch reference location (it's a kind of bind location)
|
|
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
356 |
3. current bind location
|
357 |
4. previous bind location (it was a good choice once)
|
|
358 |
5. push location (it's writeable, so committable)
|
|
359 |
6. parent location (it's pullable, so update-from-able)
|
|
2796.2.11
by Aaron Bentley
Cleanups |
360 |
"""
|
361 |
if self.new_bound_location is not None: |
|
362 |
return self.new_bound_location |
|
2796.2.3
by Aaron Bentley
Implement conversion to tree and checkout |
363 |
if self.local_branch is not None: |
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
364 |
bound = self.local_branch.get_bound_location() |
365 |
if bound is not None: |
|
366 |
return bound |
|
2796.2.3
by Aaron Bentley
Implement conversion to tree and checkout |
367 |
old_bound = self.local_branch.get_old_bound_location() |
368 |
if old_bound is not None: |
|
369 |
return old_bound |
|
370 |
push_location = self.local_branch.get_push_location() |
|
371 |
if push_location is not None: |
|
372 |
return push_location |
|
373 |
parent = self.local_branch.get_parent() |
|
374 |
if parent is not None: |
|
375 |
return parent |
|
2796.2.9
by Aaron Bentley
Ensure conversion from lightweight checkout works |
376 |
elif self.referenced_branch is not None: |
377 |
return self.referenced_branch.base |
|
6734.1.16
by Jelmer Vernooij
Move reconfigure errors. |
378 |
raise NoBindLocation(self.controldir) |
2796.2.1
by Aaron Bentley
Begin work on reconfigure command |
379 |
|
380 |
def apply(self, force=False): |
|
2796.2.16
by Aaron Bentley
Documentation updates from review |
381 |
"""Apply the reconfiguration |
382 |
||
383 |
:param force: If true, the reconfiguration is applied even if it will
|
|
384 |
destroy local changes.
|
|
385 |
:raise errors.UncommittedChanges: if the local tree is to be destroyed
|
|
386 |
but contains uncommitted changes.
|
|
6734.1.16
by Jelmer Vernooij
Move reconfigure errors. |
387 |
:raise NoBindLocation: if no bind location was specified and
|
2796.2.16
by Aaron Bentley
Documentation updates from review |
388 |
none could be autodetected.
|
389 |
"""
|
|
2796.2.1
by Aaron Bentley
Begin work on reconfigure command |
390 |
if not force: |
391 |
self._check() |
|
2796.2.14
by Aaron Bentley
Updates from review |
392 |
if self._create_repository: |
4297.4.5
by Martin von Gagern
Use repository format from exactly the same repository we want to fetch from. |
393 |
if self.local_branch and not self._destroy_branch: |
394 |
old_repo = self.local_branch.repository |
|
395 |
elif self._create_branch and self.referenced_branch is not None: |
|
396 |
old_repo = self.referenced_branch.repository |
|
397 |
else: |
|
398 |
old_repo = None |
|
399 |
if old_repo is not None: |
|
400 |
repository_format = old_repo._format |
|
401 |
else: |
|
402 |
repository_format = None |
|
4297.4.3
by Martin von Gagern
Cleaner implementation of reconfigure. |
403 |
if repository_format is not None: |
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
404 |
repo = repository_format.initialize(self.controldir) |
4297.4.3
by Martin von Gagern
Cleaner implementation of reconfigure. |
405 |
else: |
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
406 |
repo = self.controldir.create_repository() |
3311.2.4
by Aaron Bentley
Implement conversion to standalone |
407 |
if self.local_branch and not self._destroy_branch: |
408 |
repo.fetch(self.local_branch.repository, |
|
409 |
self.local_branch.last_revision()) |
|
2796.2.10
by Aaron Bentley
Ensure that shared repositories are used where possible |
410 |
else: |
411 |
repo = self.repository |
|
2796.2.23
by Aaron Bentley
Add support for reconfiguring repositories into branches or trees |
412 |
if self._create_branch and self.referenced_branch is not None: |
2796.2.10
by Aaron Bentley
Ensure that shared repositories are used where possible |
413 |
repo.fetch(self.referenced_branch.repository, |
414 |
self.referenced_branch.last_revision()) |
|
2796.2.30
by Aaron Bentley
Reconfigure can safely be interrupted while fetching (#179316) |
415 |
if self._create_reference: |
416 |
reference_branch = branch.Branch.open(self._select_bind_location()) |
|
417 |
if self._destroy_repository: |
|
418 |
if self._create_reference: |
|
419 |
reference_branch.repository.fetch(self.repository) |
|
3311.2.1
by Aaron Bentley
Initial make-sharing functionality |
420 |
elif self.local_branch is not None and not self._destroy_branch: |
5158.6.10
by Martin Pool
Update more code to use user_transport when it should |
421 |
up = self.local_branch.user_transport.clone('..') |
6681.2.4
by Jelmer Vernooij
More renames. |
422 |
up_controldir = controldir.ControlDir.open_containing_from_transport( |
6207.3.3
by jelmer at samba
Fix tests and the like. |
423 |
up)[0] |
6681.2.4
by Jelmer Vernooij
More renames. |
424 |
new_repo = up_controldir.find_repository() |
3311.2.1
by Aaron Bentley
Initial make-sharing functionality |
425 |
new_repo.fetch(self.repository) |
2796.2.23
by Aaron Bentley
Add support for reconfiguring repositories into branches or trees |
426 |
last_revision_info = None |
2796.2.14
by Aaron Bentley
Updates from review |
427 |
if self._destroy_reference: |
2796.2.23
by Aaron Bentley
Add support for reconfiguring repositories into branches or trees |
428 |
last_revision_info = self.referenced_branch.last_revision_info() |
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
429 |
self.controldir.destroy_branch() |
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
430 |
if self._destroy_branch: |
2796.2.23
by Aaron Bentley
Add support for reconfiguring repositories into branches or trees |
431 |
last_revision_info = self.local_branch.last_revision_info() |
2796.2.31
by Aaron Bentley
Fetch tags to reference branch when converting to checkout |
432 |
if self._create_reference: |
433 |
self.local_branch.tags.merge_to(reference_branch.tags) |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
434 |
self.controldir.destroy_branch() |
2796.2.14
by Aaron Bentley
Updates from review |
435 |
if self._create_branch: |
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
436 |
local_branch = self.controldir.create_branch() |
2796.2.23
by Aaron Bentley
Add support for reconfiguring repositories into branches or trees |
437 |
if last_revision_info is not None: |
438 |
local_branch.set_last_revision_info(*last_revision_info) |
|
2796.2.32
by Aaron Bentley
Preserve tags converting from lightweight checkouts |
439 |
if self._destroy_reference: |
440 |
self.referenced_branch.tags.merge_to(local_branch.tags) |
|
4273.1.18
by Aaron Bentley
Reconfigure preserves reference locations. |
441 |
self.referenced_branch.update_references(local_branch) |
2796.2.9
by Aaron Bentley
Ensure conversion from lightweight checkout works |
442 |
else: |
443 |
local_branch = self.local_branch |
|
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
444 |
if self._create_reference: |
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
445 |
self.controldir.set_branch_reference(reference_branch) |
2796.2.14
by Aaron Bentley
Updates from review |
446 |
if self._destroy_tree: |
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
447 |
self.controldir.destroy_workingtree() |
2796.2.14
by Aaron Bentley
Updates from review |
448 |
if self._create_tree: |
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
449 |
self.controldir.create_workingtree() |
2796.2.14
by Aaron Bentley
Updates from review |
450 |
if self._unbind: |
2796.2.3
by Aaron Bentley
Implement conversion to tree and checkout |
451 |
self.local_branch.unbind() |
2796.2.14
by Aaron Bentley
Updates from review |
452 |
if self._bind: |
2796.2.11
by Aaron Bentley
Cleanups |
453 |
bind_location = self._select_bind_location() |
2796.2.9
by Aaron Bentley
Ensure conversion from lightweight checkout works |
454 |
local_branch.bind(branch.Branch.open(bind_location)) |
2796.2.19
by Aaron Bentley
Support reconfigure --lightweight-checkout |
455 |
if self._destroy_repository: |
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
456 |
self.controldir.destroy_repository() |
3983.3.7
by Marius Kruger
apply changes in apply again |
457 |
if self._repository_trees is not None: |
458 |
repo.set_make_working_trees(self._repository_trees) |