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 (
31
from ...lazy_import import lazy_import
32
lazy_import(globals(), """
42
revision as _mod_revision,
47
from breezy.bzr import (
52
from breezy.i18n import gettext
53
from breezy.plugins.weave_fmt.store.versioned import VersionedFileStore
54
from breezy.transactions import WriteTransaction
55
from breezy.transport import (
59
from breezy.plugins.weave_fmt import xml4
63
class BzrDirFormatAllInOne(BzrDirFormat):
64
"""Common class for formats before meta-dirs."""
66
fixed_components = True
68
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
69
create_prefix=False, force_new_repo=False, stacked_on=None,
70
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
72
"""See ControlDir.initialize_on_transport_ex."""
73
require_stacking = (stacked_on is not None)
74
# Format 5 cannot stack, but we've been asked to - actually init
77
format = BzrDirMetaFormat1()
78
return format.initialize_on_transport_ex(transport,
79
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
80
force_new_repo=force_new_repo, stacked_on=stacked_on,
81
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
82
make_working_trees=make_working_trees, shared_repo=shared_repo)
83
return BzrDirFormat.initialize_on_transport_ex(self, transport,
84
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
85
force_new_repo=force_new_repo, stacked_on=stacked_on,
86
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
87
make_working_trees=make_working_trees, shared_repo=shared_repo)
90
def from_string(cls, format_string):
91
if format_string != cls.get_format_string():
92
raise AssertionError("unexpected format string %r" % format_string)
96
class BzrDirFormat5(BzrDirFormatAllInOne):
97
"""Bzr control format 5.
99
This format is a combined format for working tree, branch and repository.
101
- Format 2 working trees [always]
102
- Format 4 branches [always]
103
- Format 5 repositories [always]
104
Unhashed stores in the repository.
107
_lock_class = lockable_files.TransportLock
109
def __eq__(self, other):
110
return isinstance(self, type(other))
113
def get_format_string(cls):
114
"""See BzrDirFormat.get_format_string()."""
115
return "Bazaar-NG branch, format 5\n"
117
def get_branch_format(self):
118
from .branch import BzrBranchFormat4
119
return BzrBranchFormat4()
121
def get_format_description(self):
122
"""See ControlDirFormat.get_format_description()."""
123
return "All-in-one format 5"
125
def get_converter(self, format=None):
126
"""See ControlDirFormat.get_converter()."""
127
# there is one and only one upgrade path here.
128
return ConvertBzrDir5To6()
130
def _initialize_for_clone(self, url):
131
return self.initialize_on_transport(get_transport(url), _cloning=True)
133
def initialize_on_transport(self, transport, _cloning=False):
134
"""Format 5 dirs always have working tree, branch and repository.
136
Except when they are being cloned.
138
from .branch import BzrBranchFormat4
139
from .repository import RepositoryFormat5
140
result = (super(BzrDirFormat5, self).initialize_on_transport(transport))
141
RepositoryFormat5().initialize(result, _internal=True)
143
branch = BzrBranchFormat4().initialize(result)
144
result._init_workingtree()
147
def network_name(self):
148
return self.get_format_string()
150
def _open(self, transport):
151
"""See BzrDirFormat._open."""
152
return BzrDir5(transport, self)
154
def __return_repository_format(self):
155
"""Circular import protection."""
156
from .repository import RepositoryFormat5
157
return RepositoryFormat5()
158
repository_format = property(__return_repository_format)
161
class BzrDirFormat6(BzrDirFormatAllInOne):
162
"""Bzr control format 6.
164
This format is a combined format for working tree, branch and repository.
166
- Format 2 working trees [always]
167
- Format 4 branches [always]
168
- Format 6 repositories [always]
171
_lock_class = lockable_files.TransportLock
173
def __eq__(self, other):
174
return isinstance(self, type(other))
177
def get_format_string(cls):
178
"""See BzrDirFormat.get_format_string()."""
179
return "Bazaar-NG branch, format 6\n"
181
def get_format_description(self):
182
"""See ControlDirFormat.get_format_description()."""
183
return "All-in-one format 6"
185
def get_branch_format(self):
186
from .branch import BzrBranchFormat4
187
return BzrBranchFormat4()
189
def get_converter(self, format=None):
190
"""See ControlDirFormat.get_converter()."""
191
# there is one and only one upgrade path here.
192
return ConvertBzrDir6ToMeta()
194
def _initialize_for_clone(self, url):
195
return self.initialize_on_transport(get_transport(url), _cloning=True)
197
def initialize_on_transport(self, transport, _cloning=False):
198
"""Format 6 dirs always have working tree, branch and repository.
200
Except when they are being cloned.
202
from .branch import BzrBranchFormat4
203
from .repository import RepositoryFormat6
204
result = super(BzrDirFormat6, self).initialize_on_transport(transport)
205
RepositoryFormat6().initialize(result, _internal=True)
207
branch = BzrBranchFormat4().initialize(result)
208
result._init_workingtree()
211
def network_name(self):
212
return self.get_format_string()
214
def _open(self, transport):
215
"""See BzrDirFormat._open."""
216
return BzrDir6(transport, self)
218
def __return_repository_format(self):
219
"""Circular import protection."""
220
from .repository import RepositoryFormat6
221
return RepositoryFormat6()
222
repository_format = property(__return_repository_format)
225
class ConvertBzrDir4To5(Converter):
226
"""Converts format 4 bzr dirs to format 5."""
229
super(ConvertBzrDir4To5, self).__init__()
230
self.converted_revs = set()
231
self.absent_revisions = set()
235
def convert(self, to_convert, pb):
236
"""See Converter.convert()."""
237
self.controldir = to_convert
239
warnings.warn(gettext("pb parameter to convert() is deprecated"))
240
self.pb = ui.ui_factory.nested_progress_bar()
242
ui.ui_factory.note(gettext('starting upgrade from format 4 to 5'))
243
if isinstance(self.controldir.transport, local.LocalTransport):
244
self.controldir.get_workingtree_transport(None).delete('stat-cache')
245
self._convert_to_weaves()
246
return ControlDir.open(self.controldir.user_url)
250
def _convert_to_weaves(self):
251
ui.ui_factory.note(gettext(
252
'note: upgrade may be faster if all store files are ungzipped first'))
255
stat = self.controldir.transport.stat('weaves')
256
if not S_ISDIR(stat.st_mode):
257
self.controldir.transport.delete('weaves')
258
self.controldir.transport.mkdir('weaves')
259
except errors.NoSuchFile:
260
self.controldir.transport.mkdir('weaves')
261
# deliberately not a WeaveFile as we want to build it up slowly.
262
self.inv_weave = weave.Weave('inventory')
263
# holds in-memory weaves for all files
264
self.text_weaves = {}
265
self.controldir.transport.delete('branch-format')
266
self.branch = self.controldir.open_branch()
267
self._convert_working_inv()
268
rev_history = self.branch._revision_history()
269
# to_read is a stack holding the revisions we still need to process;
270
# appending to it adds new highest-priority revisions
271
self.known_revisions = set(rev_history)
272
self.to_read = rev_history[-1:]
274
rev_id = self.to_read.pop()
275
if (rev_id not in self.revisions
276
and rev_id not in self.absent_revisions):
277
self._load_one_rev(rev_id)
279
to_import = self._make_order()
280
for i, rev_id in enumerate(to_import):
281
self.pb.update(gettext('converting revision'), i, len(to_import))
282
self._convert_one_rev(rev_id)
284
self._write_all_weaves()
285
self._write_all_revs()
286
ui.ui_factory.note(gettext('upgraded to weaves:'))
287
ui.ui_factory.note(' ' + gettext('%6d revisions and inventories') %
289
ui.ui_factory.note(' ' + gettext('%6d revisions not present') %
290
len(self.absent_revisions))
291
ui.ui_factory.note(' ' + gettext('%6d texts') % self.text_count)
292
self._cleanup_spare_files_after_format4()
293
self.branch._transport.put_bytes(
295
BzrDirFormat5().get_format_string(),
296
mode=self.controldir._get_file_mode())
298
def _cleanup_spare_files_after_format4(self):
299
# FIXME working tree upgrade foo.
300
for n in 'merged-patches', 'pending-merged-patches':
302
## assert os.path.getsize(p) == 0
303
self.controldir.transport.delete(n)
304
except errors.NoSuchFile:
306
self.controldir.transport.delete_tree('inventory-store')
307
self.controldir.transport.delete_tree('text-store')
309
def _convert_working_inv(self):
310
inv = xml4.serializer_v4.read_inventory(
311
self.branch._transport.get('inventory'))
312
new_inv_xml = xml5.serializer_v5.write_inventory_to_string(inv, working=True)
313
self.branch._transport.put_bytes('inventory', new_inv_xml,
314
mode=self.controldir._get_file_mode())
316
def _write_all_weaves(self):
317
controlweaves = VersionedFileStore(self.controldir.transport, prefixed=False,
318
versionedfile_class=weave.WeaveFile)
319
weave_transport = self.controldir.transport.clone('weaves')
320
weaves = VersionedFileStore(weave_transport, prefixed=False,
321
versionedfile_class=weave.WeaveFile)
322
transaction = WriteTransaction()
326
for file_id, file_weave in self.text_weaves.items():
327
self.pb.update(gettext('writing weave'), i,
328
len(self.text_weaves))
329
weaves._put_weave(file_id, file_weave, transaction)
331
self.pb.update(gettext('inventory'), 0, 1)
332
controlweaves._put_weave('inventory', self.inv_weave, transaction)
333
self.pb.update(gettext('inventory'), 1, 1)
337
def _write_all_revs(self):
338
"""Write all revisions out in new form."""
339
self.controldir.transport.delete_tree('revision-store')
340
self.controldir.transport.mkdir('revision-store')
341
revision_transport = self.controldir.transport.clone('revision-store')
343
from ...bzr.xml5 import serializer_v5
344
from .repository import RevisionTextStore
345
revision_store = RevisionTextStore(revision_transport,
346
serializer_v5, False, versionedfile.PrefixMapper(),
347
lambda:True, lambda:True)
349
for i, rev_id in enumerate(self.converted_revs):
350
self.pb.update(gettext('write revision'), i,
351
len(self.converted_revs))
352
text = serializer_v5.write_revision_to_string(
353
self.revisions[rev_id])
355
revision_store.add_lines(key, None, osutils.split_lines(text))
359
def _load_one_rev(self, rev_id):
360
"""Load a revision object into memory.
362
Any parents not either loaded or abandoned get queued to be
364
self.pb.update(gettext('loading revision'),
366
len(self.known_revisions))
367
if not self.branch.repository.has_revision(rev_id):
369
ui.ui_factory.note(gettext('revision {%s} not present in branch; '
370
'will be converted as a ghost') %
372
self.absent_revisions.add(rev_id)
374
rev = self.branch.repository.get_revision(rev_id)
375
for parent_id in rev.parent_ids:
376
self.known_revisions.add(parent_id)
377
self.to_read.append(parent_id)
378
self.revisions[rev_id] = rev
380
def _load_old_inventory(self, rev_id):
381
f = self.branch.repository.inventory_store.get(rev_id)
383
old_inv_xml = f.read()
386
inv = xml4.serializer_v4.read_inventory_from_string(old_inv_xml)
387
inv.revision_id = rev_id
388
rev = self.revisions[rev_id]
391
def _load_updated_inventory(self, rev_id):
392
inv_xml = self.inv_weave.get_text(rev_id)
393
inv = xml5.serializer_v5.read_inventory_from_string(inv_xml, rev_id)
396
def _convert_one_rev(self, rev_id):
397
"""Convert revision and all referenced objects to new format."""
398
rev = self.revisions[rev_id]
399
inv = self._load_old_inventory(rev_id)
400
present_parents = [p for p in rev.parent_ids
401
if p not in self.absent_revisions]
402
self._convert_revision_contents(rev, inv, present_parents)
403
self._store_new_inv(rev, inv, present_parents)
404
self.converted_revs.add(rev_id)
406
def _store_new_inv(self, rev, inv, present_parents):
407
new_inv_xml = xml5.serializer_v5.write_inventory_to_string(inv)
408
new_inv_sha1 = osutils.sha_string(new_inv_xml)
409
self.inv_weave.add_lines(rev.revision_id,
411
new_inv_xml.splitlines(True))
412
rev.inventory_sha1 = new_inv_sha1
414
def _convert_revision_contents(self, rev, inv, present_parents):
415
"""Convert all the files within a revision.
417
Also upgrade the inventory to refer to the text revision ids."""
418
rev_id = rev.revision_id
419
trace.mutter('converting texts of revision {%s}', rev_id)
420
parent_invs = list(map(self._load_updated_inventory, present_parents))
421
entries = inv.iter_entries()
423
for path, ie in entries:
424
self._convert_file_version(rev, ie, parent_invs)
426
def _convert_file_version(self, rev, ie, parent_invs):
427
"""Convert one version of one file.
429
The file needs to be added into the weave if it is a merge
430
of >=2 parents or if it's changed from its parent.
433
rev_id = rev.revision_id
434
w = self.text_weaves.get(file_id)
436
w = weave.Weave(file_id)
437
self.text_weaves[file_id] = w
439
parent_candiate_entries = ie.parent_candidates(parent_invs)
440
heads = graph.Graph(self).heads(parent_candiate_entries)
441
# XXX: Note that this is unordered - and this is tolerable because
442
# the previous code was also unordered.
443
previous_entries = dict((head, parent_candiate_entries[head]) for head
445
self.snapshot_ie(previous_entries, ie, w, rev_id)
447
def get_parent_map(self, revision_ids):
448
"""See graph.StackedParentsProvider.get_parent_map"""
449
return dict((revision_id, self.revisions[revision_id])
450
for revision_id in revision_ids
451
if revision_id in self.revisions)
453
def snapshot_ie(self, previous_revisions, ie, w, rev_id):
454
# TODO: convert this logic, which is ~= snapshot to
455
# a call to:. This needs the path figured out. rather than a work_tree
456
# a v4 revision_tree can be given, or something that looks enough like
457
# one to give the file content to the entry if it needs it.
458
# and we need something that looks like a weave store for snapshot to
460
#ie.snapshot(rev, PATH, previous_revisions, REVISION_TREE, InMemoryWeaveStore(self.text_weaves))
461
if len(previous_revisions) == 1:
462
previous_ie = next(iter(previous_revisions.values()))
463
if ie._unchanged(previous_ie):
464
ie.revision = previous_ie.revision
467
f = self.branch.repository._text_store.get(ie.text_id)
469
file_lines = f.readlines()
472
w.add_lines(rev_id, previous_revisions, file_lines)
475
w.add_lines(rev_id, previous_revisions, [])
478
def _make_order(self):
479
"""Return a suitable order for importing revisions.
481
The order must be such that an revision is imported after all
482
its (present) parents.
484
todo = set(self.revisions)
485
done = self.absent_revisions.copy()
488
# scan through looking for a revision whose parents
490
for rev_id in sorted(list(todo)):
491
rev = self.revisions[rev_id]
492
parent_ids = set(rev.parent_ids)
493
if parent_ids.issubset(done):
494
# can take this one now
501
class ConvertBzrDir5To6(Converter):
502
"""Converts format 5 bzr dirs to format 6."""
504
def convert(self, to_convert, pb):
505
"""See Converter.convert()."""
506
self.controldir = to_convert
507
pb = ui.ui_factory.nested_progress_bar()
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)
515
def _convert_to_prefixed(self):
516
from .store import TransportStore
517
self.controldir.transport.delete('branch-format')
518
for store_name in ["weaves", "revision-store"]:
519
ui.ui_factory.note(gettext("adding prefixes to %s") % store_name)
520
store_transport = self.controldir.transport.clone(store_name)
521
store = TransportStore(store_transport, prefixed=True)
522
for urlfilename in store_transport.list_dir('.'):
523
filename = urlutils.unescape(urlfilename)
524
if (filename.endswith(".weave") or
525
filename.endswith(".gz") or
526
filename.endswith(".sig")):
527
file_id, suffix = os.path.splitext(filename)
531
new_name = store._mapper.map((file_id,)) + suffix
532
# FIXME keep track of the dirs made RBC 20060121
534
store_transport.move(filename, new_name)
535
except errors.NoSuchFile: # catches missing dirs strangely enough
536
store_transport.mkdir(osutils.dirname(new_name))
537
store_transport.move(filename, new_name)
538
self.controldir.transport.put_bytes(
540
BzrDirFormat6().get_format_string(),
541
mode=self.controldir._get_file_mode())
544
class ConvertBzrDir6ToMeta(Converter):
545
"""Converts format 6 bzr dirs to metadirs."""
547
def convert(self, to_convert, pb):
548
"""See Converter.convert()."""
549
from .repository import RepositoryFormat7
550
from ...bzr.fullhistory import BzrBranchFormat5
551
self.controldir = to_convert
552
self.pb = ui.ui_factory.nested_progress_bar()
554
self.total = 20 # the steps we know about
555
self.garbage_inventories = []
556
self.dir_mode = self.controldir._get_dir_mode()
557
self.file_mode = self.controldir._get_file_mode()
559
ui.ui_factory.note(gettext('starting upgrade from format 6 to metadir'))
560
self.controldir.transport.put_bytes(
562
"Converting to format 6",
564
# its faster to move specific files around than to open and use the apis...
565
# first off, nuke ancestry.weave, it was never used.
567
self.step(gettext('Removing ancestry.weave'))
568
self.controldir.transport.delete('ancestry.weave')
569
except errors.NoSuchFile:
571
# find out whats there
572
self.step(gettext('Finding branch files'))
573
last_revision = self.controldir.open_branch().last_revision()
574
bzrcontents = self.controldir.transport.list_dir('.')
575
for name in bzrcontents:
576
if name.startswith('basis-inventory.'):
577
self.garbage_inventories.append(name)
578
# create new directories for repository, working tree and branch
579
repository_names = [('inventory.weave', True),
580
('revision-store', True),
582
self.step(gettext('Upgrading repository') + ' ')
583
self.controldir.transport.mkdir('repository', mode=self.dir_mode)
584
self.make_lock('repository')
585
# we hard code the formats here because we are converting into
586
# the meta format. The meta format upgrader can take this to a
587
# future format within each component.
588
self.put_format('repository', RepositoryFormat7())
589
for entry in repository_names:
590
self.move_entry('repository', entry)
592
self.step(gettext('Upgrading branch') + ' ')
593
self.controldir.transport.mkdir('branch', mode=self.dir_mode)
594
self.make_lock('branch')
595
self.put_format('branch', BzrBranchFormat5())
596
branch_files = [('revision-history', True),
597
('branch-name', True),
599
for entry in branch_files:
600
self.move_entry('branch', entry)
602
checkout_files = [('pending-merges', True),
604
('stat-cache', False)]
605
# If a mandatory checkout file is not present, the branch does not have
606
# a functional checkout. Do not create a checkout in the converted
608
for name, mandatory in checkout_files:
609
if mandatory and name not in bzrcontents:
615
ui.ui_factory.note(gettext('No working tree.'))
616
# If some checkout files are there, we may as well get rid of them.
617
for name, mandatory in checkout_files:
618
if name in bzrcontents:
619
self.controldir.transport.delete(name)
621
from ...bzr.workingtree_3 import WorkingTreeFormat3
622
self.step(gettext('Upgrading working tree'))
623
self.controldir.transport.mkdir('checkout', mode=self.dir_mode)
624
self.make_lock('checkout')
626
'checkout', WorkingTreeFormat3())
627
self.controldir.transport.delete_multi(
628
self.garbage_inventories, self.pb)
629
for entry in checkout_files:
630
self.move_entry('checkout', entry)
631
if last_revision is not None:
632
self.controldir.transport.put_bytes(
633
'checkout/last-revision', last_revision)
634
self.controldir.transport.put_bytes(
636
BzrDirMetaFormat1().get_format_string(),
639
return ControlDir.open(self.controldir.user_url)
641
def make_lock(self, name):
642
"""Make a lock for the new control dir name."""
643
self.step(gettext('Make %s lock') % name)
644
ld = lockdir.LockDir(self.controldir.transport,
646
file_modebits=self.file_mode,
647
dir_modebits=self.dir_mode)
650
def move_entry(self, new_dir, entry):
651
"""Move then entry name into new_dir."""
654
self.step(gettext('Moving %s') % name)
656
self.controldir.transport.move(name, '%s/%s' % (new_dir, name))
657
except errors.NoSuchFile:
661
def put_format(self, dirname, format):
662
self.controldir.transport.put_bytes('%s/format' % dirname,
663
format.get_format_string(),
667
class BzrDirFormat4(BzrDirFormat):
670
This format is a combined format for working tree, branch and repository.
672
- Format 1 working trees [always]
673
- Format 4 branches [always]
674
- Format 4 repositories [always]
676
This format is deprecated: it indexes texts using a text it which is
677
removed in format 5; write support for this format has been removed.
680
_lock_class = lockable_files.TransportLock
682
def __eq__(self, other):
683
return isinstance(self, type(other))
686
def get_format_string(cls):
687
"""See BzrDirFormat.get_format_string()."""
688
return "Bazaar-NG branch, format 0.0.4\n"
690
def get_format_description(self):
691
"""See ControlDirFormat.get_format_description()."""
692
return "All-in-one format 4"
694
def get_converter(self, format=None):
695
"""See ControlDirFormat.get_converter()."""
696
# there is one and only one upgrade path here.
697
return ConvertBzrDir4To5()
699
def initialize_on_transport(self, transport):
700
"""Format 4 branches cannot be created."""
701
raise errors.UninitializableFormat(self)
703
def is_supported(self):
704
"""Format 4 is not supported.
706
It is not supported because the model changed from 4 to 5 and the
707
conversion logic is expensive - so doing it on the fly was not
712
def network_name(self):
713
return self.get_format_string()
715
def _open(self, transport):
716
"""See BzrDirFormat._open."""
717
return BzrDir4(transport, self)
719
def __return_repository_format(self):
720
"""Circular import protection."""
721
from .repository import RepositoryFormat4
722
return RepositoryFormat4()
723
repository_format = property(__return_repository_format)
726
def from_string(cls, format_string):
727
if format_string != cls.get_format_string():
728
raise AssertionError("unexpected format string %r" % format_string)
732
class BzrDirPreSplitOut(BzrDir):
733
"""A common class for the all-in-one formats."""
735
def __init__(self, _transport, _format):
736
"""See ControlDir.__init__."""
737
super(BzrDirPreSplitOut, self).__init__(_transport, _format)
738
self._control_files = lockable_files.LockableFiles(
739
self.get_branch_transport(None),
740
self._format._lock_file_name,
741
self._format._lock_class)
743
def break_lock(self):
744
"""Pre-splitout bzrdirs do not suffer from stale locks."""
745
raise NotImplementedError(self.break_lock)
747
def cloning_metadir(self, require_stacking=False):
748
"""Produce a metadir suitable for cloning with."""
750
return format_registry.make_controldir('1.6')
751
return self._format.__class__()
753
def clone(self, url, revision_id=None, force_new_repo=False,
754
preserve_stacking=False):
755
"""See ControlDir.clone().
757
force_new_repo has no effect, since this family of formats always
758
require a new repository.
759
preserve_stacking has no effect, since no source branch using this
760
family of formats can be stacked, so there is no stacking to preserve.
763
result = self._format._initialize_for_clone(url)
764
self.open_repository().clone(result, revision_id=revision_id)
765
from_branch = self.open_branch()
766
from_branch.clone(result, revision_id=revision_id)
768
tree = self.open_workingtree()
769
except errors.NotLocalUrl:
770
# make a new one, this format always has to have one.
771
result._init_workingtree()
776
def create_branch(self, name=None, repository=None,
777
append_revisions_only=None):
778
"""See ControlDir.create_branch."""
779
if repository is not None:
780
raise NotImplementedError(
781
"create_branch(repository=<not None>) on %r" % (self,))
782
return self._format.get_branch_format().initialize(self, name=name,
783
append_revisions_only=append_revisions_only)
785
def destroy_branch(self, name=None):
786
"""See ControlDir.destroy_branch."""
787
raise errors.UnsupportedOperation(self.destroy_branch, self)
789
def create_repository(self, shared=False):
790
"""See ControlDir.create_repository."""
792
raise errors.IncompatibleFormat('shared repository', self._format)
793
return self.open_repository()
795
def destroy_repository(self):
796
"""See ControlDir.destroy_repository."""
797
raise errors.UnsupportedOperation(self.destroy_repository, self)
799
def create_workingtree(self, revision_id=None, from_branch=None,
800
accelerator_tree=None, hardlink=False):
801
"""See ControlDir.create_workingtree."""
802
# The workingtree is sometimes created when the bzrdir is created,
803
# but not when cloning.
805
# this looks buggy but is not -really-
806
# because this format creates the workingtree when the bzrdir is
808
# clone and sprout will have set the revision_id
809
# and that will have set it for us, its only
810
# specific uses of create_workingtree in isolation
811
# that can do wonky stuff here, and that only
812
# happens for creating checkouts, which cannot be
813
# done on this format anyway. So - acceptable wart.
815
warning("can't support hardlinked working trees in %r"
818
result = self.open_workingtree(recommend_upgrade=False)
819
except errors.NoSuchFile:
820
result = self._init_workingtree()
821
if revision_id is not None:
822
if revision_id == _mod_revision.NULL_REVISION:
823
result.set_parent_ids([])
825
result.set_parent_ids([revision_id])
828
def _init_workingtree(self):
829
from .workingtree import WorkingTreeFormat2
831
return WorkingTreeFormat2().initialize(self)
832
except errors.NotLocalUrl:
833
# Even though we can't access the working tree, we need to
834
# create its control files.
835
return WorkingTreeFormat2()._stub_initialize_on_transport(
836
self.transport, self._control_files._file_mode)
838
def destroy_workingtree(self):
839
"""See ControlDir.destroy_workingtree."""
840
raise errors.UnsupportedOperation(self.destroy_workingtree, self)
842
def destroy_workingtree_metadata(self):
843
"""See ControlDir.destroy_workingtree_metadata."""
844
raise errors.UnsupportedOperation(self.destroy_workingtree_metadata,
847
def get_branch_transport(self, branch_format, name=None):
848
"""See BzrDir.get_branch_transport()."""
850
raise errors.NoColocatedBranchSupport(self)
851
if branch_format is None:
852
return self.transport
854
branch_format.get_format_string()
855
except NotImplementedError:
856
return self.transport
857
raise errors.IncompatibleFormat(branch_format, self._format)
859
def get_repository_transport(self, repository_format):
860
"""See BzrDir.get_repository_transport()."""
861
if repository_format is None:
862
return self.transport
864
repository_format.get_format_string()
865
except NotImplementedError:
866
return self.transport
867
raise errors.IncompatibleFormat(repository_format, self._format)
869
def get_workingtree_transport(self, workingtree_format):
870
"""See BzrDir.get_workingtree_transport()."""
871
if workingtree_format is None:
872
return self.transport
874
workingtree_format.get_format_string()
875
except NotImplementedError:
876
return self.transport
877
raise errors.IncompatibleFormat(workingtree_format, self._format)
879
def needs_format_conversion(self, format):
880
"""See ControlDir.needs_format_conversion()."""
881
# if the format is not the same as the system default,
882
# an upgrade is needed.
883
return not isinstance(self._format, format.__class__)
885
def open_branch(self, name=None, unsupported=False,
886
ignore_fallbacks=False, possible_transports=None):
887
"""See ControlDir.open_branch."""
888
from .branch import BzrBranchFormat4
889
format = BzrBranchFormat4()
890
format.check_support_status(unsupported)
891
return format.open(self, name, _found=True,
892
possible_transports=possible_transports)
894
def sprout(self, url, revision_id=None, force_new_repo=False,
895
possible_transports=None, accelerator_tree=None,
896
hardlink=False, stacked=False, create_tree_if_local=True,
898
"""See ControlDir.sprout()."""
899
if source_branch is not None:
900
my_branch = self.open_branch()
901
if source_branch.base != my_branch.base:
902
raise AssertionError(
903
"source branch %r is not within %r with branch %r" %
904
(source_branch, self, my_branch))
906
raise errors.UnstackableBranchFormat(
907
self._format, self.root_transport.base)
908
if not create_tree_if_local:
909
raise errors.MustHaveWorkingTree(
910
self._format, self.root_transport.base)
911
from .workingtree import WorkingTreeFormat2
913
result = self._format._initialize_for_clone(url)
915
self.open_repository().clone(result, revision_id=revision_id)
916
except errors.NoRepositoryPresent:
919
self.open_branch().sprout(result, revision_id=revision_id)
920
except errors.NotBranchError:
923
# we always want a working tree
924
WorkingTreeFormat2().initialize(result,
925
accelerator_tree=accelerator_tree,
929
def set_branch_reference(self, target_branch, name=None):
930
from ...bzr.branch import BranchReferenceFormat
932
raise errors.NoColocatedBranchSupport(self)
933
raise errors.IncompatibleFormat(BranchReferenceFormat, self._format)
936
class BzrDir4(BzrDirPreSplitOut):
937
"""A .bzr version 4 control object.
939
This is a deprecated format and may be removed after sept 2006.
942
def create_repository(self, shared=False):
943
"""See ControlDir.create_repository."""
944
return self._format.repository_format.initialize(self, shared)
946
def needs_format_conversion(self, format):
947
"""Format 4 dirs are always in need of conversion."""
950
def open_repository(self):
951
"""See ControlDir.open_repository."""
952
from .repository import RepositoryFormat4
953
return RepositoryFormat4().open(self, _found=True)
956
class BzrDir5(BzrDirPreSplitOut):
957
"""A .bzr version 5 control object.
959
This is a deprecated format and may be removed after sept 2006.
962
def has_workingtree(self):
963
"""See ControlDir.has_workingtree."""
966
def open_repository(self):
967
"""See ControlDir.open_repository."""
968
from .repository import RepositoryFormat5
969
return RepositoryFormat5().open(self, _found=True)
971
def open_workingtree(self, unsupported=False,
972
recommend_upgrade=True):
973
"""See ControlDir.create_workingtree."""
974
from .workingtree import WorkingTreeFormat2
975
wt_format = WorkingTreeFormat2()
976
# we don't warn here about upgrades; that ought to be handled for the
978
return wt_format.open(self, _found=True)
981
class BzrDir6(BzrDirPreSplitOut):
982
"""A .bzr version 6 control object.
984
This is a deprecated format and may be removed after sept 2006.
987
def has_workingtree(self):
988
"""See ControlDir.has_workingtree."""
991
def open_repository(self):
992
"""See ControlDir.open_repository."""
993
from .repository import RepositoryFormat6
994
return RepositoryFormat6().open(self, _found=True)
996
def open_workingtree(self, unsupported=False, recommend_upgrade=True):
997
"""See ControlDir.create_workingtree."""
998
# we don't warn here about upgrades; that ought to be handled for the
1000
from .workingtree import WorkingTreeFormat2
1001
return WorkingTreeFormat2().open(self, _found=True)