477
490
def initialize(self, a_bzrdir):
478
491
"""Create a branch of this format in a_bzrdir."""
479
mutter('creating branch in %s', a_bzrdir.transport.base)
480
utf8_files = [('revision-history', ''),
484
control_files = LockableFiles(a_bzrdir.transport, 'branch-lock')
485
control_files.lock_write()
487
for file, content in utf8_files:
488
control_files.put_utf8(file, content)
490
control_files.unlock()
491
return self.open(a_bzrdir, _found=True)
492
raise NotImplementedError(self.initialized)
493
494
def is_supported(self):
494
495
"""Is this format supported?
531
529
- a revision-history file.
530
- a branch-lock lock file [ to be shared with the bzrdir ]
533
def initialize(self, a_bzrdir):
534
"""Create a branch of this format in a_bzrdir."""
535
mutter('creating branch in %s', a_bzrdir.transport.base)
536
branch_transport = a_bzrdir.get_branch_transport(self)
537
utf8_files = [('revision-history', ''),
540
control_files = LockableFiles(branch_transport, 'branch-lock')
541
control_files.lock_write()
543
for file, content in utf8_files:
544
control_files.put_utf8(file, content)
546
control_files.unlock()
547
return self.open(a_bzrdir, _found=True)
534
549
def __init__(self):
535
550
super(BzrBranchFormat4, self).__init__()
536
551
self._matchingbzrdir = bzrdir.BzrDirFormat6()
553
def open(self, a_bzrdir, _found=False):
554
"""Return the branch object for a_bzrdir
556
_found is a private parameter, do not use it. It is used to indicate
557
if format probing has already be done.
560
# we are being called directly and must probe.
561
raise NotImplementedError
562
transport = a_bzrdir.get_branch_transport(self)
563
control_files = LockableFiles(transport, 'branch-lock')
564
return BzrBranch(_format=self,
565
_control_files=control_files,
569
class BzrBranchFormat5(BranchFormat):
570
"""Bzr branch format 5.
573
- a revision-history file.
578
def get_format_string(self):
579
"""See BranchFormat.get_format_string()."""
580
return "Bazaar-NG branch format 5\n"
582
def initialize(self, a_bzrdir):
583
"""Create a branch of this format in a_bzrdir."""
584
mutter('creating branch in %s', a_bzrdir.transport.base)
585
branch_transport = a_bzrdir.get_branch_transport(self)
587
utf8_files = [('revision-history', ''),
591
branch_transport.put(lock_file, StringIO()) # TODO get the file mode from the bzrdir lock files., mode=file_mode)
592
control_files = LockableFiles(branch_transport, 'lock')
593
control_files.lock_write()
594
control_files.put_utf8('format', self.get_format_string())
596
for file, content in utf8_files:
597
control_files.put_utf8(file, content)
599
control_files.unlock()
600
return self.open(a_bzrdir, _found=True, )
603
super(BzrBranchFormat5, self).__init__()
604
self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
606
def open(self, a_bzrdir, _found=False):
607
"""Return the branch object for a_bzrdir
609
_found is a private parameter, do not use it. It is used to indicate
610
if format probing has already be done.
613
format = BranchFormat.find_format(a_bzrdir)
614
assert format.__class__ == self.__class__
615
transport = a_bzrdir.get_branch_transport(None)
616
control_files = LockableFiles(transport, 'lock')
617
return BzrBranch(_format=self,
618
_control_files=control_files,
538
622
# formats which have no format string are not discoverable
539
623
# and not independently creatable, so are not registered.
540
# __default_format = BranchFormatXXX()
541
# BranchFormat.register_format(__default_format)
542
# BranchFormat.set_default_format(__default_format)
624
__default_format = BzrBranchFormat5()
625
BranchFormat.register_format(__default_format)
626
BranchFormat.set_default_format(__default_format)
543
627
_legacy_formats = [BzrBranchFormat4(),
578
662
upgrade/recovery type use; it's not guaranteed that
579
663
all operations will work on old format branches.
581
self.bzrdir = a_bzrdir
582
self._transport = transport
666
self.bzrdir = bzrdir.BzrDir.open(transport.base)
668
self.bzrdir = a_bzrdir
669
self._transport = self.bzrdir.transport.clone('..')
583
670
self._base = self._transport.base
584
671
self._format = _format
585
672
if _control_files is None:
586
_control_files = LockableFiles(self._transport.clone(bzrlib.BZRDIR),
673
raise BzrBadParameterMissing('_control_files')
588
674
self.control_files = _control_files
589
675
if deprecated_passed(init):
590
676
warn("BzrBranch.__init__(..., init=XXX): The init parameter is "
599
685
if deprecated_passed(relax_version_check):
600
686
warn("BzrBranch.__init__(..., relax_version_check=XXX_: The "
601
687
"relax_version_check parameter is deprecated as of bzr 0.8. "
602
"Please use Branch.open_downlevel, or a BzrBranchFormat's "
688
"Please use BzrDir.open_downlevel, or a BzrBranchFormat's "
603
689
"open() method.",
604
690
DeprecationWarning,
606
692
if (not relax_version_check
607
and not self._branch_format.is_supported()):
693
and not self._format.is_supported()):
608
694
raise errors.UnsupportedFormatError(
609
695
'sorry, branch format %r not supported' % fmt,
610
696
['use a different bzr version',
611
697
'or remove the .bzr directory'
612
698
' and "bzr init" again'])
699
if deprecated_passed(transport):
700
warn("BzrBranch.__init__(transport=XXX...): The transport "
701
"parameter is deprecated as of bzr 0.8. "
702
"Please use Branch.open, or bzrdir.open_branch().",
613
705
self.repository = self.bzrdir.open_repository()
615
707
def __str__(self):
668
760
"""Identify the branch format if needed.
670
762
The format is stored as a reference to the format object in
671
self._branch_format for code that needs to check it later.
763
self._format for code that needs to check it later.
673
765
The format parameter is either None or the branch format class
674
766
used to open this branch.
768
FIXME: DELETE THIS METHOD when pre 0.8 support is removed.
676
770
if format is None:
677
format = BzrBranchFormat.find_format(self._transport)
678
self._branch_format = format
679
mutter("got branch format %s", self._branch_format)
771
format = BzrBranchFormat.find_format(self.bzrdir)
772
self._format = format
773
mutter("got branch format %s", self._format)
682
776
def get_root_id(self):