1
# Copyright (C) 2006-2010 Canonical Ltd
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.
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.
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
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Weave-era BzrDir formats."""
19
from __future__ import absolute_import
21
from ...bzr.bzrdir import (
26
from ...controldir import (
35
from ...lazy_import import lazy_import
36
lazy_import(globals(), """
41
branch as _mod_branch,,
46
revision as _mod_revision,
51
from breezy.bzr import (
56
from breezy.i18n import gettext
57
from breezy.plugins.weave_fmt.store.versioned import VersionedFileStore
58
from breezy.transactions import WriteTransaction
59
from breezy.transport import (
63
from breezy.plugins.weave_fmt import xml4
67
class BzrDirFormatAllInOne(BzrDirFormat):
68
"""Common class for formats before meta-dirs."""
70
fixed_components = True
72
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
73
create_prefix=False, force_new_repo=False, stacked_on=None,
74
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
76
"""See ControlDir.initialize_on_transport_ex."""
77
require_stacking = (stacked_on is not None)
78
# Format 5 cannot stack, but we've been asked to - actually init
81
format = BzrDirMetaFormat1()
82
return format.initialize_on_transport_ex(transport,
83
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
84
force_new_repo=force_new_repo, stacked_on=stacked_on,
85
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
86
make_working_trees=make_working_trees, shared_repo=shared_repo)
87
return BzrDirFormat.initialize_on_transport_ex(self, transport,
88
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
89
force_new_repo=force_new_repo, stacked_on=stacked_on,
90
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
91
make_working_trees=make_working_trees, shared_repo=shared_repo)
94
def from_string(cls, format_string):
95
if format_string != cls.get_format_string():
96
raise AssertionError("unexpected format string %r" % format_string)
100
class BzrDirFormat5(BzrDirFormatAllInOne):
101
"""Bzr control format 5.
103
This format is a combined format for working tree, branch and repository.
105
- Format 2 working trees [always]
106
- Format 4 branches [always]
107
- Format 5 repositories [always]
108
Unhashed stores in the repository.
111
_lock_class = lockable_files.TransportLock
113
def __eq__(self, other):
114
return isinstance(self, type(other))
117
def get_format_string(cls):
118
"""See BzrDirFormat.get_format_string()."""
119
return b"Bazaar-NG branch, format 5\n"
121
def get_branch_format(self):
122
from .branch import BzrBranchFormat4
123
return BzrBranchFormat4()
125
def get_format_description(self):
126
"""See ControlDirFormat.get_format_description()."""
127
return "All-in-one format 5"
129
def get_converter(self, format=None):
130
"""See ControlDirFormat.get_converter()."""
131
# there is one and only one upgrade path here.
132
return ConvertBzrDir5To6()
134
def _initialize_for_clone(self, url):
135
return self.initialize_on_transport(get_transport(url), _cloning=True)
137
def initialize_on_transport(self, transport, _cloning=False):
138
"""Format 5 dirs always have working tree, branch and repository.
140
Except when they are being cloned.
142
from .branch import BzrBranchFormat4
143
from .repository import RepositoryFormat5
144
result = (super(BzrDirFormat5, self).initialize_on_transport(transport))
145
RepositoryFormat5().initialize(result, _internal=True)
147
branch = BzrBranchFormat4().initialize(result)
148
result._init_workingtree()
151
def network_name(self):
152
return self.get_format_string()
154
def _open(self, transport):
155
"""See BzrDirFormat._open."""
156
return BzrDir5(transport, self)
158
def __return_repository_format(self):
159
"""Circular import protection."""
160
from .repository import RepositoryFormat5
161
return RepositoryFormat5()
162
repository_format = property(__return_repository_format)
165
class BzrDirFormat6(BzrDirFormatAllInOne):
166
"""Bzr control format 6.
168
This format is a combined format for working tree, branch and repository.
170
- Format 2 working trees [always]
171
- Format 4 branches [always]
172
- Format 6 repositories [always]
175
_lock_class = lockable_files.TransportLock
177
def __eq__(self, other):
178
return isinstance(self, type(other))
181
def get_format_string(cls):
182
"""See BzrDirFormat.get_format_string()."""
183
return b"Bazaar-NG branch, format 6\n"
185
def get_format_description(self):
186
"""See ControlDirFormat.get_format_description()."""
187
return "All-in-one format 6"
189
def get_branch_format(self):
190
from .branch import BzrBranchFormat4
191
return BzrBranchFormat4()
193
def get_converter(self, format=None):
194
"""See ControlDirFormat.get_converter()."""
195
# there is one and only one upgrade path here.
196
return ConvertBzrDir6ToMeta()
198
def _initialize_for_clone(self, url):
199
return self.initialize_on_transport(get_transport(url), _cloning=True)
201
def initialize_on_transport(self, transport, _cloning=False):
202
"""Format 6 dirs always have working tree, branch and repository.
204
Except when they are being cloned.
206
from .branch import BzrBranchFormat4
207
from .repository import RepositoryFormat6
208
result = super(BzrDirFormat6, self).initialize_on_transport(transport)
209
RepositoryFormat6().initialize(result, _internal=True)
211
branch = BzrBranchFormat4().initialize(result)
212
result._init_workingtree()
215
def network_name(self):
216
return self.get_format_string()
218
def _open(self, transport):
219
"""See BzrDirFormat._open."""
220
return BzrDir6(transport, self)
222
def __return_repository_format(self):
223
"""Circular import protection."""
224
from .repository import RepositoryFormat6
225
return RepositoryFormat6()
226
repository_format = property(__return_repository_format)
229
class ConvertBzrDir4To5(Converter):
230
"""Converts format 4 bzr dirs to format 5."""
233
super(ConvertBzrDir4To5, self).__init__()
234
self.converted_revs = set()
235
self.absent_revisions = set()
239
def convert(self, to_convert, pb):
240
"""See Converter.convert()."""
241
self.controldir = to_convert
243
warnings.warn(gettext("pb parameter to convert() is deprecated"))
244
with ui.ui_factory.nested_progress_bar() as self.pb:
245
ui.ui_factory.note(gettext('starting upgrade from format 4 to 5'))
246
if isinstance(self.controldir.transport, local.LocalTransport):
247
self.controldir.get_workingtree_transport(None).delete('stat-cache')
248
self._convert_to_weaves()
249
return ControlDir.open(self.controldir.user_url)
251
def _convert_to_weaves(self):
252
ui.ui_factory.note(gettext(
253
'note: upgrade may be faster if all store files are ungzipped first'))
256
stat = self.controldir.transport.stat('weaves')
257
if not S_ISDIR(stat.st_mode):
258
self.controldir.transport.delete('weaves')
259
self.controldir.transport.mkdir('weaves')
260
except errors.NoSuchFile:
261
self.controldir.transport.mkdir('weaves')
262
# deliberately not a WeaveFile as we want to build it up slowly.
263
self.inv_weave = weave.Weave('inventory')
264
# holds in-memory weaves for all files
265
self.text_weaves = {}
266
self.controldir.transport.delete('branch-format')
267
self.branch = self.controldir.open_branch()
268
self._convert_working_inv()
269
rev_history = self.branch._revision_history()
270
# to_read is a stack holding the revisions we still need to process;
271
# appending to it adds new highest-priority revisions
272
self.known_revisions = set(rev_history)
273
self.to_read = rev_history[-1:]
275
rev_id = self.to_read.pop()
276
if (rev_id not in self.revisions
277
and rev_id not in self.absent_revisions):
278
self._load_one_rev(rev_id)
280
to_import = self._make_order()
281
for i, rev_id in enumerate(to_import):
282
self.pb.update(gettext('converting revision'), i, len(to_import))
283
self._convert_one_rev(rev_id)
285
self._write_all_weaves()
286
self._write_all_revs()
287
ui.ui_factory.note(gettext('upgraded to weaves:'))
288
ui.ui_factory.note(' ' + gettext('%6d revisions and inventories') %
290
ui.ui_factory.note(' ' + gettext('%6d revisions not present') %
291
len(self.absent_revisions))
292
ui.ui_factory.note(' ' + gettext('%6d texts') % self.text_count)
293
self._cleanup_spare_files_after_format4()
294
self.branch._transport.put_bytes(
296
BzrDirFormat5().get_format_string(),
297
mode=self.controldir._get_file_mode())
299
def _cleanup_spare_files_after_format4(self):
300
# FIXME working tree upgrade foo.
301
for n in 'merged-patches', 'pending-merged-patches':
303
## assert os.path.getsize(p) == 0
304
self.controldir.transport.delete(n)
305
except errors.NoSuchFile:
307
self.controldir.transport.delete_tree('inventory-store')
308
self.controldir.transport.delete_tree('text-store')
310
def _convert_working_inv(self):
311
inv = xml4.serializer_v4.read_inventory(
312
self.branch._transport.get('inventory'))
313
new_inv_xml = xml5.serializer_v5.write_inventory_to_string(inv, working=True)
314
self.branch._transport.put_bytes('inventory', new_inv_xml,
315
mode=self.controldir._get_file_mode())
317
def _write_all_weaves(self):
318
controlweaves = VersionedFileStore(self.controldir.transport, prefixed=False,
319
versionedfile_class=weave.WeaveFile)
320
weave_transport = self.controldir.transport.clone('weaves')
321
weaves = VersionedFileStore(weave_transport, prefixed=False,
322
versionedfile_class=weave.WeaveFile)
323
transaction = WriteTransaction()
327
for file_id, file_weave in self.text_weaves.items():
328
self.pb.update(gettext('writing weave'), i,
329
len(self.text_weaves))
330
weaves._put_weave(file_id, file_weave, transaction)
332
self.pb.update(gettext('inventory'), 0, 1)
333
controlweaves._put_weave('inventory', self.inv_weave, transaction)
334
self.pb.update(gettext('inventory'), 1, 1)
338
def _write_all_revs(self):
339
"""Write all revisions out in new form."""
340
self.controldir.transport.delete_tree('revision-store')
341
self.controldir.transport.mkdir('revision-store')
342
revision_transport = self.controldir.transport.clone('revision-store')
344
from ...bzr.xml5 import serializer_v5
345
from .repository import RevisionTextStore
346
revision_store = RevisionTextStore(revision_transport,
347
serializer_v5, False, versionedfile.PrefixMapper(),
348
lambda:True, lambda:True)
350
for i, rev_id in enumerate(self.converted_revs):
351
self.pb.update(gettext('write revision'), i,
352
len(self.converted_revs))
353
text = serializer_v5.write_revision_to_string(
354
self.revisions[rev_id])
356
revision_store.add_lines(key, None, osutils.split_lines(text))
360
def _load_one_rev(self, rev_id):
361
"""Load a revision object into memory.
363
Any parents not either loaded or abandoned get queued to be
365
self.pb.update(gettext('loading revision'),
367
len(self.known_revisions))
368
if not self.branch.repository.has_revision(rev_id):
370
ui.ui_factory.note(gettext('revision {%s} not present in branch; '
371
'will be converted as a ghost') %
373
self.absent_revisions.add(rev_id)
375
rev = self.branch.repository.get_revision(rev_id)
376
for parent_id in rev.parent_ids:
377
self.known_revisions.add(parent_id)
378
self.to_read.append(parent_id)
379
self.revisions[rev_id] = rev
381
def _load_old_inventory(self, rev_id):
382
f = self.branch.repository.inventory_store.get(rev_id)
384
old_inv_xml = f.read()
387
inv = xml4.serializer_v4.read_inventory_from_string(old_inv_xml)
388
inv.revision_id = rev_id
389
rev = self.revisions[rev_id]
392
def _load_updated_inventory(self, rev_id):
393
inv_xml = self.inv_weave.get_text(rev_id)
394
inv = xml5.serializer_v5.read_inventory_from_string(inv_xml, rev_id)
397
def _convert_one_rev(self, rev_id):
398
"""Convert revision and all referenced objects to new format."""
399
rev = self.revisions[rev_id]
400
inv = self._load_old_inventory(rev_id)
401
present_parents = [p for p in rev.parent_ids
402
if p not in self.absent_revisions]
403
self._convert_revision_contents(rev, inv, present_parents)
404
self._store_new_inv(rev, inv, present_parents)
405
self.converted_revs.add(rev_id)
407
def _store_new_inv(self, rev, inv, present_parents):
408
new_inv_xml = xml5.serializer_v5.write_inventory_to_string(inv)
409
new_inv_sha1 = osutils.sha_string(new_inv_xml)
410
self.inv_weave.add_lines(rev.revision_id,
412
new_inv_xml.splitlines(True))
413
rev.inventory_sha1 = new_inv_sha1
415
def _convert_revision_contents(self, rev, inv, present_parents):
416
"""Convert all the files within a revision.
418
Also upgrade the inventory to refer to the text revision ids."""
419
rev_id = rev.revision_id
420
trace.mutter('converting texts of revision {%s}', rev_id)
421
parent_invs = list(map(self._load_updated_inventory, present_parents))
422
entries = inv.iter_entries()
424
for path, ie in entries:
425
self._convert_file_version(rev, ie, parent_invs)
427
def _convert_file_version(self, rev, ie, parent_invs):
428
"""Convert one version of one file.
430
The file needs to be added into the weave if it is a merge
431
of >=2 parents or if it's changed from its parent.
434
rev_id = rev.revision_id
435
w = self.text_weaves.get(file_id)
437
w = weave.Weave(file_id)
438
self.text_weaves[file_id] = w
440
parent_candiate_entries = ie.parent_candidates(parent_invs)
441
heads = graph.Graph(self).heads(parent_candiate_entries)
442
# XXX: Note that this is unordered - and this is tolerable because
443
# the previous code was also unordered.
444
previous_entries = dict((head, parent_candiate_entries[head]) for head
446
self.snapshot_ie(previous_entries, ie, w, rev_id)
448
def get_parent_map(self, revision_ids):
449
"""See graph.StackedParentsProvider.get_parent_map"""
450
return dict((revision_id, self.revisions[revision_id])
451
for revision_id in revision_ids
452
if revision_id in self.revisions)
454
def snapshot_ie(self, previous_revisions, ie, w, rev_id):
455
# TODO: convert this logic, which is ~= snapshot to
456
# a call to:. This needs the path figured out. rather than a work_tree
457
# a v4 revision_tree can be given, or something that looks enough like
458
# one to give the file content to the entry if it needs it.
459
# and we need something that looks like a weave store for snapshot to
461
#ie.snapshot(rev, PATH, previous_revisions, REVISION_TREE, InMemoryWeaveStore(self.text_weaves))
462
if len(previous_revisions) == 1:
463
previous_ie = next(iter(previous_revisions.values()))
464
if ie._unchanged(previous_ie):
465
ie.revision = previous_ie.revision
468
f = self.branch.repository._text_store.get(ie.text_id)
470
file_lines = f.readlines()
473
w.add_lines(rev_id, previous_revisions, file_lines)
476
w.add_lines(rev_id, previous_revisions, [])
479
def _make_order(self):
480
"""Return a suitable order for importing revisions.
482
The order must be such that an revision is imported after all
483
its (present) parents.
485
todo = set(self.revisions)
486
done = self.absent_revisions.copy()
489
# scan through looking for a revision whose parents
491
for rev_id in sorted(list(todo)):
492
rev = self.revisions[rev_id]
493
parent_ids = set(rev.parent_ids)
494
if parent_ids.issubset(done):
495
# can take this one now
502
class ConvertBzrDir5To6(Converter):
503
"""Converts format 5 bzr dirs to format 6."""
505
def convert(self, to_convert, pb):
506
"""See Converter.convert()."""
507
self.controldir = to_convert
508
with ui.ui_factory.nested_progress_bar() as pb:
509
ui.ui_factory.note(gettext('starting upgrade from format 5 to 6'))
510
self._convert_to_prefixed()
511
return ControlDir.open(self.controldir.user_url)
513
def _convert_to_prefixed(self):
514
from .store import TransportStore
515
self.controldir.transport.delete('branch-format')
516
for store_name in ["weaves", "revision-store"]:
517
ui.ui_factory.note(gettext("adding prefixes to %s") % store_name)
518
store_transport = self.controldir.transport.clone(store_name)
519
store = TransportStore(store_transport, prefixed=True)
520
for urlfilename in store_transport.list_dir('.'):
521
filename = urlutils.unescape(urlfilename)
522
if (filename.endswith(".weave") or
523
filename.endswith(".gz") or
524
filename.endswith(".sig")):
525
file_id, suffix = os.path.splitext(filename)
529
new_name = store._mapper.map((file_id,)) + suffix
530
# FIXME keep track of the dirs made RBC 20060121
532
store_transport.move(filename, new_name)
533
except errors.NoSuchFile: # catches missing dirs strangely enough
534
store_transport.mkdir(osutils.dirname(new_name))
535
store_transport.move(filename, new_name)
536
self.controldir.transport.put_bytes(
538
BzrDirFormat6().get_format_string(),
539
mode=self.controldir._get_file_mode())
542
class ConvertBzrDir6ToMeta(Converter):
543
"""Converts format 6 bzr dirs to metadirs."""
545
def convert(self, to_convert, pb):
546
"""See Converter.convert()."""
547
from .repository import RepositoryFormat7
548
from ...bzr.fullhistory import BzrBranchFormat5
549
self.controldir = to_convert
550
self.pb = ui.ui_factory.nested_progress_bar()
552
self.total = 20 # the steps we know about
553
self.garbage_inventories = []
554
self.dir_mode = self.controldir._get_dir_mode()
555
self.file_mode = self.controldir._get_file_mode()
557
ui.ui_factory.note(gettext('starting upgrade from format 6 to metadir'))
558
self.controldir.transport.put_bytes(
560
"Converting to format 6",
562
# its faster to move specific files around than to open and use the apis...
563
# first off, nuke ancestry.weave, it was never used.
565
self.step(gettext('Removing ancestry.weave'))
566
self.controldir.transport.delete('ancestry.weave')
567
except errors.NoSuchFile:
569
# find out whats there
570
self.step(gettext('Finding branch files'))
571
last_revision = self.controldir.open_branch().last_revision()
572
bzrcontents = self.controldir.transport.list_dir('.')
573
for name in bzrcontents:
574
if name.startswith('basis-inventory.'):
575
self.garbage_inventories.append(name)
576
# create new directories for repository, working tree and branch
577
repository_names = [('inventory.weave', True),
578
('revision-store', True),
580
self.step(gettext('Upgrading repository') + ' ')
581
self.controldir.transport.mkdir('repository', mode=self.dir_mode)
582
self.make_lock('repository')
583
# we hard code the formats here because we are converting into
584
# the meta format. The meta format upgrader can take this to a
585
# future format within each component.
586
self.put_format('repository', RepositoryFormat7())
587
for entry in repository_names:
588
self.move_entry('repository', entry)
590
self.step(gettext('Upgrading branch') + ' ')
591
self.controldir.transport.mkdir('branch', mode=self.dir_mode)
592
self.make_lock('branch')
593
self.put_format('branch', BzrBranchFormat5())
594
branch_files = [('revision-history', True),
595
('branch-name', True),
597
for entry in branch_files:
598
self.move_entry('branch', entry)
600
checkout_files = [('pending-merges', True),
602
('stat-cache', False)]
603
# If a mandatory checkout file is not present, the branch does not have
604
# a functional checkout. Do not create a checkout in the converted
606
for name, mandatory in checkout_files:
607
if mandatory and name not in bzrcontents:
613
ui.ui_factory.note(gettext('No working tree.'))
614
# If some checkout files are there, we may as well get rid of them.
615
for name, mandatory in checkout_files:
616
if name in bzrcontents:
617
self.controldir.transport.delete(name)
619
from ...bzr.workingtree_3 import WorkingTreeFormat3
620
self.step(gettext('Upgrading working tree'))
621
self.controldir.transport.mkdir('checkout', mode=self.dir_mode)
622
self.make_lock('checkout')
623
self.put_format('checkout', WorkingTreeFormat3())
624
for path in self.garbage_inventories:
625
self.controldir.transport.delete(path)
626
for entry in checkout_files:
627
self.move_entry('checkout', entry)
628
if last_revision is not None:
629
self.controldir.transport.put_bytes(
630
'checkout/last-revision', last_revision)
631
self.controldir.transport.put_bytes(
633
BzrDirMetaFormat1().get_format_string(),
636
return ControlDir.open(self.controldir.user_url)
638
def make_lock(self, name):
639
"""Make a lock for the new control dir name."""
640
self.step(gettext('Make %s lock') % name)
641
ld = lockdir.LockDir(self.controldir.transport,
643
file_modebits=self.file_mode,
644
dir_modebits=self.dir_mode)
647
def move_entry(self, new_dir, entry):
648
"""Move then entry name into new_dir."""
651
self.step(gettext('Moving %s') % name)
653
self.controldir.transport.move(name, '%s/%s' % (new_dir, name))
654
except errors.NoSuchFile:
658
def put_format(self, dirname, format):
659
self.controldir.transport.put_bytes('%s/format' % dirname,
660
format.get_format_string(),
664
class BzrDirFormat4(BzrDirFormat):
667
This format is a combined format for working tree, branch and repository.
669
- Format 1 working trees [always]
670
- Format 4 branches [always]
671
- Format 4 repositories [always]
673
This format is deprecated: it indexes texts using a text it which is
674
removed in format 5; write support for this format has been removed.
677
_lock_class = lockable_files.TransportLock
679
def __eq__(self, other):
680
return isinstance(self, type(other))
683
def get_format_string(cls):
684
"""See BzrDirFormat.get_format_string()."""
685
return b"Bazaar-NG branch, format 0.0.4\n"
687
def get_format_description(self):
688
"""See ControlDirFormat.get_format_description()."""
689
return "All-in-one format 4"
691
def get_converter(self, format=None):
692
"""See ControlDirFormat.get_converter()."""
693
# there is one and only one upgrade path here.
694
return ConvertBzrDir4To5()
696
def initialize_on_transport(self, transport):
697
"""Format 4 branches cannot be created."""
698
raise errors.UninitializableFormat(self)
700
def is_supported(self):
701
"""Format 4 is not supported.
703
It is not supported because the model changed from 4 to 5 and the
704
conversion logic is expensive - so doing it on the fly was not
709
def network_name(self):
710
return self.get_format_string()
712
def _open(self, transport):
713
"""See BzrDirFormat._open."""
714
return BzrDir4(transport, self)
716
def __return_repository_format(self):
717
"""Circular import protection."""
718
from .repository import RepositoryFormat4
719
return RepositoryFormat4()
720
repository_format = property(__return_repository_format)
723
def from_string(cls, format_string):
724
if format_string != cls.get_format_string():
725
raise AssertionError("unexpected format string %r" % format_string)
729
class BzrDirPreSplitOut(BzrDir):
730
"""A common class for the all-in-one formats."""
732
def __init__(self, _transport, _format):
733
"""See ControlDir.__init__."""
734
super(BzrDirPreSplitOut, self).__init__(_transport, _format)
735
self._control_files = lockable_files.LockableFiles(
736
self.get_branch_transport(None),
737
self._format._lock_file_name,
738
self._format._lock_class)
740
def break_lock(self):
741
"""Pre-splitout bzrdirs do not suffer from stale locks."""
742
raise NotImplementedError(self.break_lock)
744
def cloning_metadir(self, require_stacking=False):
745
"""Produce a metadir suitable for cloning with."""
747
return format_registry.make_controldir('1.6')
748
return self._format.__class__()
750
def clone(self, url, revision_id=None, force_new_repo=False,
751
preserve_stacking=False):
752
"""See ControlDir.clone().
754
force_new_repo has no effect, since this family of formats always
755
require a new repository.
756
preserve_stacking has no effect, since no source branch using this
757
family of formats can be stacked, so there is no stacking to preserve.
760
result = self._format._initialize_for_clone(url)
761
self.open_repository().clone(result, revision_id=revision_id)
762
from_branch = self.open_branch()
763
from_branch.clone(result, revision_id=revision_id)
765
tree = self.open_workingtree()
766
except errors.NotLocalUrl:
767
# make a new one, this format always has to have one.
768
result._init_workingtree()
773
def create_branch(self, name=None, repository=None,
774
append_revisions_only=None):
775
"""See ControlDir.create_branch."""
776
if repository is not None:
777
raise NotImplementedError(
778
"create_branch(repository=<not None>) on %r" % (self,))
779
return self._format.get_branch_format().initialize(self, name=name,
780
append_revisions_only=append_revisions_only)
782
def destroy_branch(self, name=None):
783
"""See ControlDir.destroy_branch."""
784
raise errors.UnsupportedOperation(self.destroy_branch, self)
786
def create_repository(self, shared=False):
787
"""See ControlDir.create_repository."""
789
raise errors.IncompatibleFormat('shared repository', self._format)
790
return self.open_repository()
792
def destroy_repository(self):
793
"""See ControlDir.destroy_repository."""
794
raise errors.UnsupportedOperation(self.destroy_repository, self)
796
def create_workingtree(self, revision_id=None, from_branch=None,
797
accelerator_tree=None, hardlink=False):
798
"""See ControlDir.create_workingtree."""
799
# The workingtree is sometimes created when the bzrdir is created,
800
# but not when cloning.
802
# this looks buggy but is not -really-
803
# because this format creates the workingtree when the bzrdir is
805
# clone and sprout will have set the revision_id
806
# and that will have set it for us, its only
807
# specific uses of create_workingtree in isolation
808
# that can do wonky stuff here, and that only
809
# happens for creating checkouts, which cannot be
810
# done on this format anyway. So - acceptable wart.
812
warning("can't support hardlinked working trees in %r"
815
result = self.open_workingtree(recommend_upgrade=False)
816
except errors.NoSuchFile:
817
result = self._init_workingtree()
818
if revision_id is not None:
819
if revision_id == _mod_revision.NULL_REVISION:
820
result.set_parent_ids([])
822
result.set_parent_ids([revision_id])
825
def _init_workingtree(self):
826
from .workingtree import WorkingTreeFormat2
828
return WorkingTreeFormat2().initialize(self)
829
except errors.NotLocalUrl:
830
# Even though we can't access the working tree, we need to
831
# create its control files.
832
return WorkingTreeFormat2()._stub_initialize_on_transport(
833
self.transport, self._control_files._file_mode)
835
def destroy_workingtree(self):
836
"""See ControlDir.destroy_workingtree."""
837
raise errors.UnsupportedOperation(self.destroy_workingtree, self)
839
def destroy_workingtree_metadata(self):
840
"""See ControlDir.destroy_workingtree_metadata."""
841
raise errors.UnsupportedOperation(self.destroy_workingtree_metadata,
844
def get_branch_transport(self, branch_format, name=None):
845
"""See BzrDir.get_branch_transport()."""
847
raise errors.NoColocatedBranchSupport(self)
848
if branch_format is None:
849
return self.transport
851
branch_format.get_format_string()
852
except NotImplementedError:
853
return self.transport
854
raise errors.IncompatibleFormat(branch_format, self._format)
856
def get_repository_transport(self, repository_format):
857
"""See BzrDir.get_repository_transport()."""
858
if repository_format is None:
859
return self.transport
861
repository_format.get_format_string()
862
except NotImplementedError:
863
return self.transport
864
raise errors.IncompatibleFormat(repository_format, self._format)
866
def get_workingtree_transport(self, workingtree_format):
867
"""See BzrDir.get_workingtree_transport()."""
868
if workingtree_format is None:
869
return self.transport
871
workingtree_format.get_format_string()
872
except NotImplementedError:
873
return self.transport
874
raise errors.IncompatibleFormat(workingtree_format, self._format)
876
def needs_format_conversion(self, format):
877
"""See ControlDir.needs_format_conversion()."""
878
# if the format is not the same as the system default,
879
# an upgrade is needed.
880
return not isinstance(self._format, format.__class__)
882
def open_branch(self, name=None, unsupported=False,
883
ignore_fallbacks=False, possible_transports=None):
884
"""See ControlDir.open_branch."""
885
from .branch import BzrBranchFormat4
886
format = BzrBranchFormat4()
887
format.check_support_status(unsupported)
888
return format.open(self, name, _found=True,
889
possible_transports=possible_transports)
891
def sprout(self, url, revision_id=None, force_new_repo=False,
892
possible_transports=None, accelerator_tree=None,
893
hardlink=False, stacked=False, create_tree_if_local=True,
895
"""See ControlDir.sprout()."""
896
if source_branch is not None:
897
my_branch = self.open_branch()
898
if source_branch.base != my_branch.base:
899
raise AssertionError(
900
"source branch %r is not within %r with branch %r" %
901
(source_branch, self, my_branch))
903
raise _mod_branch.UnstackableBranchFormat(
904
self._format, self.root_transport.base)
905
if not create_tree_if_local:
906
raise MustHaveWorkingTree(
907
self._format, self.root_transport.base)
908
from .workingtree import WorkingTreeFormat2
910
result = self._format._initialize_for_clone(url)
912
self.open_repository().clone(result, revision_id=revision_id)
913
except errors.NoRepositoryPresent:
916
self.open_branch().sprout(result, revision_id=revision_id)
917
except errors.NotBranchError:
920
# we always want a working tree
921
WorkingTreeFormat2().initialize(result,
922
accelerator_tree=accelerator_tree,
926
def set_branch_reference(self, target_branch, name=None):
927
from ...bzr.branch import BranchReferenceFormat
929
raise errors.NoColocatedBranchSupport(self)
930
raise errors.IncompatibleFormat(BranchReferenceFormat, self._format)
933
class BzrDir4(BzrDirPreSplitOut):
934
"""A .bzr version 4 control object.
936
This is a deprecated format and may be removed after sept 2006.
939
def create_repository(self, shared=False):
940
"""See ControlDir.create_repository."""
941
return self._format.repository_format.initialize(self, shared)
943
def needs_format_conversion(self, format):
944
"""Format 4 dirs are always in need of conversion."""
947
def open_repository(self):
948
"""See ControlDir.open_repository."""
949
from .repository import RepositoryFormat4
950
return RepositoryFormat4().open(self, _found=True)
953
class BzrDir5(BzrDirPreSplitOut):
954
"""A .bzr version 5 control object.
956
This is a deprecated format and may be removed after sept 2006.
959
def has_workingtree(self):
960
"""See ControlDir.has_workingtree."""
963
def open_repository(self):
964
"""See ControlDir.open_repository."""
965
from .repository import RepositoryFormat5
966
return RepositoryFormat5().open(self, _found=True)
968
def open_workingtree(self, unsupported=False,
969
recommend_upgrade=True):
970
"""See ControlDir.create_workingtree."""
971
from .workingtree import WorkingTreeFormat2
972
wt_format = WorkingTreeFormat2()
973
# we don't warn here about upgrades; that ought to be handled for the
975
return wt_format.open(self, _found=True)
978
class BzrDir6(BzrDirPreSplitOut):
979
"""A .bzr version 6 control object.
981
This is a deprecated format and may be removed after sept 2006.
984
def has_workingtree(self):
985
"""See ControlDir.has_workingtree."""
988
def open_repository(self):
989
"""See ControlDir.open_repository."""
990
from .repository import RepositoryFormat6
991
return RepositoryFormat6().open(self, _found=True)
993
def open_workingtree(self, unsupported=False, recommend_upgrade=True):
994
"""See ControlDir.create_workingtree."""
995
# we don't warn here about upgrades; that ought to be handled for the
997
from .workingtree import WorkingTreeFormat2
998
return WorkingTreeFormat2().open(self, _found=True)