1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# Copyright (C) 2010 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""Weave-era branch implementations."""
from bzrlib import (
errors,
lockable_files,
)
from bzrlib.trace import mutter
from bzrlib.branch import (
BranchFormat,
FullHistoryBzrBranch,
)
class BzrBranch4(FullHistoryBzrBranch):
"""Branch format 4."""
def _get_checkout_format(self):
"""Return the most suitable metadir for a checkout of this branch.
"""
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7
from bzrlib.bzrdir import BzrDirMetaFormat1
format = BzrDirMetaFormat1()
format.repository_format = RepositoryFormat7()
return format
def unbind(self):
raise errors.UpgradeRequired(self.user_url)
def bind(self, other):
raise errors.UpgradeRequired(self.user_url)
def set_bound_location(self, location):
raise NotImplementedError(self.set_bound_location)
def get_bound_location(self):
return None
def update(self):
return None
def get_master_branch(self, possible_transports=None):
return None
class BzrBranchFormat4(BranchFormat):
"""Bzr branch format 4.
This format has:
- a revision-history file.
- a branch-lock lock file [ to be shared with the bzrdir ]
It does not support binding.
"""
def initialize(self, a_bzrdir, name=None, repository=None):
"""Create a branch of this format in a_bzrdir.
:param a_bzrdir: The bzrdir to initialize the branch in
:param name: Name of colocated branch to create, if any
:param repository: Repository for this branch (unused)
"""
if repository is not None:
raise NotImplementedError(
"initialize(repository=<not None>) on %r" % (self,))
if not [isinstance(a_bzrdir._format, format) for format in
self._compatible_bzrdirs]:
raise errors.IncompatibleFormat(self, a_bzrdir._format)
utf8_files = [('revision-history', ''),
('branch-name', ''),
]
mutter('creating branch %r in %s', self, a_bzrdir.user_url)
branch_transport = a_bzrdir.get_branch_transport(self, name=name)
control_files = lockable_files.LockableFiles(branch_transport,
'branch-lock', lockable_files.TransportLock)
control_files.create_lock()
try:
control_files.lock_write()
except errors.LockContention:
lock_taken = False
else:
lock_taken = True
try:
for (filename, content) in utf8_files:
branch_transport.put_bytes(
filename, content,
mode=a_bzrdir._get_file_mode())
finally:
if lock_taken:
control_files.unlock()
branch = self.open(a_bzrdir, name, _found=True,
found_repository=None)
self._run_post_branch_init_hooks(a_bzrdir, name, branch)
return branch
def __init__(self):
super(BzrBranchFormat4, self).__init__()
from bzrlib.plugins.weave_fmt.bzrdir import (
BzrDirFormat4, BzrDirFormat5, BzrDirFormat6,
)
self._matchingbzrdir = BzrDirFormat6()
self._compatible_bzrdirs = [BzrDirFormat4, BzrDirFormat5,
BzrDirFormat6]
def network_name(self):
"""The network name for this format is the control dirs disk label."""
return self._matchingbzrdir.get_format_string()
def get_format_description(self):
return "Branch format 4"
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
found_repository=None):
"""See BranchFormat.open()."""
if name is not None:
raise errors.NoColocatedBranchSupport(self)
if not _found:
# we are being called directly and must probe.
raise NotImplementedError
if found_repository is None:
found_repository = a_bzrdir.open_repository()
return BzrBranch4(_format=self,
_control_files=a_bzrdir._control_files,
a_bzrdir=a_bzrdir,
name=name,
_repository=found_repository)
def __str__(self):
return "Bazaar-NG branch format 4"
def supports_leaving_lock(self):
return False
|