1
# Copyright (C) 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 branch implementations."""
24
from bzrlib.trace import mutter
26
from bzrlib.branch import (
32
class PreSplitOutBzrBranch(BzrBranch):
34
def _get_checkout_format(self):
35
"""Return the most suitable metadir for a checkout of this branch.
37
from bzrlib.repofmt.weaverepo import RepositoryFormat7
38
from bzrlib.bzrdir import BzrDirMetaFormat1
39
format = BzrDirMetaFormat1()
40
format.repository_format = RepositoryFormat7()
44
class BzrBranchFormat4(BranchFormat):
45
"""Bzr branch format 4.
48
- a revision-history file.
49
- a branch-lock lock file [ to be shared with the bzrdir ]
52
def get_format_description(self):
53
"""See BranchFormat.get_format_description()."""
54
return "Branch format 4"
56
def _initialize_helper(self, a_bzrdir, utf8_files, name=None):
57
"""Initialize a branch in a bzrdir, with specified files
59
:param a_bzrdir: The bzrdir to initialize the branch in
60
:param utf8_files: The files to create as a list of
61
(filename, content) tuples
62
:param name: Name of colocated branch to create, if any
63
:return: a branch in this format
65
mutter('creating branch %r in %s', self, a_bzrdir.user_url)
66
branch_transport = a_bzrdir.get_branch_transport(self, name=name)
67
control_files = lockable_files.LockableFiles(branch_transport,
68
'branch-lock', lockable_files.TransportLock)
69
control_files.create_lock()
71
control_files.lock_write()
72
except errors.LockContention:
77
for (filename, content) in utf8_files:
78
branch_transport.put_bytes(
80
mode=a_bzrdir._get_file_mode())
83
control_files.unlock()
84
branch = self.open(a_bzrdir, name, _found=True,
85
found_repository=None)
86
self._run_post_branch_init_hooks(a_bzrdir, name, branch)
89
def initialize(self, a_bzrdir, name=None, repository=None):
90
"""Create a branch of this format in a_bzrdir."""
91
if repository is not None:
92
raise NotImplementedError(
93
"initialize(repository=<not None>) on %r" % (self,))
94
utf8_files = [('revision-history', ''),
97
return self._initialize_helper(a_bzrdir, utf8_files, name=name)
100
super(BzrBranchFormat4, self).__init__()
101
from bzrlib.bzrdir import BzrDirFormat6
102
self._matchingbzrdir = BzrDirFormat6()
104
def network_name(self):
105
"""The network name for this format is the control dirs disk label."""
106
return self._matchingbzrdir.get_format_string()
108
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
109
found_repository=None):
110
"""See BranchFormat.open()."""
112
# we are being called directly and must probe.
113
raise NotImplementedError
114
if found_repository is None:
115
found_repository = a_bzrdir.open_repository()
116
return PreSplitOutBzrBranch(_format=self,
117
_control_files=a_bzrdir._control_files,
120
_repository=found_repository)
123
return "Bazaar-NG branch format 4"
125
def supports_leaving_lock(self):