53
55
if not allow_unsupported and not format.is_supported():
54
56
raise errors.UnsupportedFormatError(format)
58
def clone(self, url, revision_id=None, basis=None):
59
"""Clone this bzrdir and its contents to url verbatim.
61
If urls last component does not exist, it will be created.
63
if revision_id is not None, then the clone operation may tune
64
itself to download less data.
67
result = self._format.initialize(url)
68
basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
70
self.open_repository().clone(result, revision_id=revision_id, basis=basis_repo)
71
except errors.NoRepositoryPresent:
74
self.open_branch().clone(result, revision_id=revision_id)
75
except errors.NotBranchError:
78
self.open_workingtree().clone(result, basis=basis_tree)
79
except (errors.NotBranchError, errors.NotLocalUrl):
83
def _get_basis_components(self, basis):
84
"""Retrieve the basis components that are available at basis."""
86
return None, None, None
88
basis_tree = basis.open_workingtree()
89
basis_branch = basis_tree.branch
90
basis_repo = basis_branch.repository
91
except (errors.NoWorkingTree, errors.NotLocalUrl):
94
basis_branch = basis.open_branch()
95
basis_repo = basis_branch.repository
96
except errors.NotBranchError:
99
basis_repo = basis.open_repository()
100
except errors.NoRepositoryPresent:
102
return basis_repo, basis_branch, basis_tree
104
def _make_tail(self, url):
105
segments = url.split('/')
106
if segments and segments[-1] not in ('', '.'):
107
parent = '/'.join(segments[:-1])
108
t = bzrlib.transport.get_transport(parent)
110
t.mkdir(segments[-1])
111
except errors.FileExists:
58
116
"""Create a new BzrDir at the url 'base'.
264
323
raise NotImplementedError(self.open_workingtree)
325
def sprout(self, url, revision_id=None, basis=None):
326
"""Create a copy of this bzrdir prepared for use as a new line of
329
If urls last component does not exist, it will be created.
331
Attributes related to the identity of the source branch like
332
branch nickname will be cleaned, a working tree is created
333
whether one existed before or not; and a local branch is always
336
if revision_id is not None, then the clone operation may tune
337
itself to download less data.
340
result = self._format.initialize(url)
341
basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
343
source_branch = self.open_branch()
344
source_repository = source_branch.repository
345
except errors.NotBranchError:
348
source_repository = self.open_repository()
349
except errors.NoRepositoryPresent:
350
# copy the basis one if there is one
351
source_repository = basis_repo
352
if source_repository is not None:
353
source_repository.clone(result,
354
revision_id=revision_id,
357
# no repo available, make a new one
358
result.create_repository()
359
if source_branch is not None:
360
source_branch.sprout(result, revision_id=revision_id)
362
result.create_branch()
364
self.open_workingtree().clone(result,
365
revision_id=revision_id,
367
except (errors.NotBranchError, errors.NotLocalUrl):
368
result.create_workingtree()
267
372
class BzrDirPreSplitOut(BzrDir):
268
373
"""A common class for the all-in-one formats."""
375
def clone(self, url, revision_id=None, basis=None):
376
"""See BzrDir.clone()."""
377
from bzrlib.workingtree import WorkingTreeFormat2
379
result = self._format.initialize(url, _cloning=True)
380
basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
381
self.open_repository().clone(result, revision_id=revision_id, basis=basis_repo)
382
self.open_branch().clone(result, revision_id=revision_id)
384
self.open_workingtree().clone(result, basis=basis_tree)
385
except errors.NotLocalUrl:
386
# make a new one, this format always has to have one.
387
WorkingTreeFormat2().initialize(result)
270
390
def create_branch(self):
271
391
"""See BzrDir.create_branch."""
272
from bzrlib.branch import BzrBranchFormat4
273
return BzrBranchFormat4().initialize(self)
392
return self.open_branch()
394
def create_repository(self):
395
"""See BzrDir.create_repository."""
396
return self.open_repository()
398
def create_workingtree(self):
399
"""See BzrDir.create_workingtree."""
400
return self.open_workingtree()
275
402
def get_branch_transport(self, branch_format):
276
403
"""See BzrDir.get_branch_transport()."""
309
436
self._check_supported(format, unsupported)
310
437
return format.open(self, _found=True)
439
def sprout(self, url, revision_id=None, basis=None):
440
"""See BzrDir.sprout()."""
441
from bzrlib.workingtree import WorkingTreeFormat2
443
result = self._format.initialize(url, _cloning=True)
444
basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
446
self.open_repository().clone(result, revision_id=revision_id, basis=basis_repo)
447
except errors.NoRepositoryPresent:
450
self.open_branch().sprout(result, revision_id=revision_id)
451
except errors.NotBranchError:
454
self.open_workingtree().clone(result, basis=basis_tree)
455
except (errors.NotBranchError, errors.NotLocalUrl):
456
# we always want a working tree
457
WorkingTreeFormat2().initialize(result)
313
461
class BzrDir4(BzrDirPreSplitOut):
314
462
"""A .bzr version 4 control object."""
327
475
class BzrDir5(BzrDirPreSplitOut):
328
476
"""A .bzr version 5 control object."""
330
def create_repository(self):
331
"""See BzrDir.create_repository."""
332
from bzrlib.repository import RepositoryFormat5
333
return RepositoryFormat5().initialize(self)
335
def create_workingtree(self):
336
"""See BzrDir.create_workingtree."""
337
from bzrlib.workingtree import WorkingTreeFormat2
338
return WorkingTreeFormat2().initialize(self)
340
478
def open_repository(self):
341
479
"""See BzrDir.open_repository."""
342
480
from bzrlib.repository import RepositoryFormat5
351
489
class BzrDir6(BzrDirPreSplitOut):
352
490
"""A .bzr version 6 control object."""
354
def create_repository(self):
355
"""See BzrDir.create_repository."""
356
from bzrlib.repository import RepositoryFormat6
357
return RepositoryFormat6().initialize(self)
359
def create_workingtree(self):
360
"""See BzrDir.create_workingtree."""
361
from bzrlib.workingtree import WorkingTreeFormat2
362
return WorkingTreeFormat2().initialize(self)
364
492
def open_repository(self):
365
493
"""See BzrDir.open_repository."""
366
494
from bzrlib.repository import RepositoryFormat6
614
742
This format is a combined format for working tree, branch and repository.
616
- Format 2 working trees
618
- Format 6 repositories
744
- Format 2 working trees [always]
745
- Format 4 branches [always]
746
- Format 6 repositories [always]
747
Unhashed stores in the repository.
621
750
def get_format_string(self):
622
751
"""See BzrDirFormat.get_format_string()."""
623
752
return "Bazaar-NG branch, format 5\n"
754
def initialize(self, url, _cloning=False):
755
"""Format 5 dirs always have working tree, branch and repository.
757
Except when they are being cloned.
759
from bzrlib.branch import BzrBranchFormat4
760
from bzrlib.repository import RepositoryFormat5
761
from bzrlib.workingtree import WorkingTreeFormat2
762
result = super(BzrDirFormat5, self).initialize(url)
763
RepositoryFormat5().initialize(result, _internal=True)
765
BzrBranchFormat4().initialize(result)
766
WorkingTreeFormat2().initialize(result)
625
769
def _open(self, transport):
626
770
"""See BzrDirFormat._open."""
627
771
return BzrDir5(transport, self)
633
777
This format is a combined format for working tree, branch and repository.
635
- Format 2 working trees
637
- Format 6 repositories
779
- Format 2 working trees [always]
780
- Format 4 branches [always]
781
- Format 6 repositories [always]
640
784
def get_format_string(self):
641
785
"""See BzrDirFormat.get_format_string()."""
642
786
return "Bazaar-NG branch, format 6\n"
788
def initialize(self, url, _cloning=False):
789
"""Format 6 dirs always have working tree, branch and repository.
791
Except when they are being cloned.
793
from bzrlib.branch import BzrBranchFormat4
794
from bzrlib.repository import RepositoryFormat6
795
from bzrlib.workingtree import WorkingTreeFormat2
796
result = super(BzrDirFormat6, self).initialize(url)
797
RepositoryFormat6().initialize(result, _internal=True)
799
BzrBranchFormat4().initialize(result)
801
WorkingTreeFormat2().initialize(result)
802
except errors.NotLocalUrl:
803
# emulate pre-check behaviour for working tree and silently
644
808
def _open(self, transport):
645
809
"""See BzrDirFormat._open."""
646
810
return BzrDir6(transport, self)