bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
1 |
# Copyright (C) 2010 Canonical Ltd
|
2 |
#
|
|
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.
|
|
7 |
#
|
|
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.
|
|
12 |
#
|
|
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
|
|
16 |
||
|
6379.6.7
by Jelmer Vernooij
Move importing from future until after doc string, otherwise the doc string will disappear. |
17 |
"""Weave-era branch implementations."""
|
18 |
||
|
6379.6.3
by Jelmer Vernooij
Use absolute_import. |
19 |
from __future__ import absolute_import |
20 |
||
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
21 |
from ... import ( |
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
22 |
errors, |
23 |
lockable_files, |
|
24 |
)
|
|
25 |
||
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
26 |
from ...decorators import ( |
|
6531.2.1
by Vincent Ladeuil
Add a failing test and a brain-dead fix (duplicating the existing code). |
27 |
only_raises, |
28 |
)
|
|
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
29 |
from ...lock import LogicalLockResult |
30 |
from ...trace import mutter |
|
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
31 |
|
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
32 |
from ...branch import ( |
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
33 |
BranchFormat, |
|
6531.2.1
by Vincent Ladeuil
Add a failing test and a brain-dead fix (duplicating the existing code). |
34 |
BranchWriteLockResult, |
|
6517.1.2
by Jelmer Vernooij
Move BzrBranchFormat5 into a separate file. |
35 |
)
|
|
6670.4.1
by Jelmer Vernooij
Update imports. |
36 |
from ...bzr.fullhistory import ( |
|
5718.8.1
by Jelmer Vernooij
Add FullHistoryBzrBranch. |
37 |
FullHistoryBzrBranch, |
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
38 |
)
|
39 |
||
40 |
||
|
5718.8.1
by Jelmer Vernooij
Add FullHistoryBzrBranch. |
41 |
class BzrBranch4(FullHistoryBzrBranch): |
|
5718.8.2
by Jelmer Vernooij
Split out full history branch code. |
42 |
"""Branch format 4.""" |
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
43 |
|
|
6531.2.1
by Vincent Ladeuil
Add a failing test and a brain-dead fix (duplicating the existing code). |
44 |
def lock_write(self, token=None): |
45 |
"""Lock the branch for write operations. |
|
46 |
||
47 |
:param token: A token to permit reacquiring a previously held and
|
|
48 |
preserved lock.
|
|
49 |
:return: A BranchWriteLockResult.
|
|
50 |
"""
|
|
51 |
if not self.is_locked(): |
|
52 |
self._note_lock('w') |
|
|
6531.2.4
by Vincent Ladeuil
Always means always. Full test suite revealed a possible further simplication. |
53 |
# All-in-one needs to always unlock/lock.
|
54 |
self.repository._warn_if_deprecated(self) |
|
55 |
self.repository.lock_write() |
|
|
6531.2.1
by Vincent Ladeuil
Add a failing test and a brain-dead fix (duplicating the existing code). |
56 |
try: |
57 |
return BranchWriteLockResult(self.unlock, |
|
58 |
self.control_files.lock_write(token=token)) |
|
59 |
except: |
|
|
6531.2.4
by Vincent Ladeuil
Always means always. Full test suite revealed a possible further simplication. |
60 |
self.repository.unlock() |
|
6531.2.1
by Vincent Ladeuil
Add a failing test and a brain-dead fix (duplicating the existing code). |
61 |
raise
|
62 |
||
63 |
def lock_read(self): |
|
64 |
"""Lock the branch for read operations. |
|
65 |
||
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
66 |
:return: A breezy.lock.LogicalLockResult.
|
|
6531.2.1
by Vincent Ladeuil
Add a failing test and a brain-dead fix (duplicating the existing code). |
67 |
"""
|
68 |
if not self.is_locked(): |
|
69 |
self._note_lock('r') |
|
|
6531.2.4
by Vincent Ladeuil
Always means always. Full test suite revealed a possible further simplication. |
70 |
# All-in-one needs to always unlock/lock.
|
71 |
self.repository._warn_if_deprecated(self) |
|
72 |
self.repository.lock_read() |
|
|
6531.2.1
by Vincent Ladeuil
Add a failing test and a brain-dead fix (duplicating the existing code). |
73 |
try: |
74 |
self.control_files.lock_read() |
|
75 |
return LogicalLockResult(self.unlock) |
|
76 |
except: |
|
|
6531.2.4
by Vincent Ladeuil
Always means always. Full test suite revealed a possible further simplication. |
77 |
self.repository.unlock() |
|
6531.2.1
by Vincent Ladeuil
Add a failing test and a brain-dead fix (duplicating the existing code). |
78 |
raise
|
79 |
||
80 |
@only_raises(errors.LockNotHeld, errors.LockBroken) |
|
81 |
def unlock(self): |
|
82 |
if self.control_files._lock_count == 2 and self.conf_store is not None: |
|
83 |
self.conf_store.save_changes() |
|
84 |
try: |
|
85 |
self.control_files.unlock() |
|
86 |
finally: |
|
87 |
# All-in-one needs to always unlock/lock.
|
|
|
6531.2.2
by Vincent Ladeuil
Better version separating the lock methods between branch and branch format 4 and removing the duplication. |
88 |
self.repository.unlock() |
|
6531.2.1
by Vincent Ladeuil
Add a failing test and a brain-dead fix (duplicating the existing code). |
89 |
if not self.control_files.is_locked(): |
90 |
# we just released the lock
|
|
91 |
self._clear_cached_state() |
|
92 |
||
|
6127.1.9
by Jelmer Vernooij
Add lightweight option to _get_checkout_format(). |
93 |
def _get_checkout_format(self, lightweight=False): |
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
94 |
"""Return the most suitable metadir for a checkout of this branch. |
95 |
"""
|
|
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
96 |
from .repository import RepositoryFormat7 |
|
6670.4.3
by Jelmer Vernooij
Fix more imports. |
97 |
from ...bzr.bzrdir import BzrDirMetaFormat1 |
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
98 |
format = BzrDirMetaFormat1() |
|
6127.1.11
by Jelmer Vernooij
Fix weave format test. |
99 |
if lightweight: |
100 |
format.set_branch_format(self._format) |
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
101 |
format.repository_format = self.controldir._format.repository_format |
|
6127.1.11
by Jelmer Vernooij
Fix weave format test. |
102 |
else: |
103 |
format.repository_format = RepositoryFormat7() |
|
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
104 |
return format |
105 |
||
|
5718.8.2
by Jelmer Vernooij
Split out full history branch code. |
106 |
def unbind(self): |
107 |
raise errors.UpgradeRequired(self.user_url) |
|
108 |
||
109 |
def bind(self, other): |
|
110 |
raise errors.UpgradeRequired(self.user_url) |
|
111 |
||
112 |
def set_bound_location(self, location): |
|
113 |
raise NotImplementedError(self.set_bound_location) |
|
114 |
||
115 |
def get_bound_location(self): |
|
116 |
return None |
|
117 |
||
118 |
def update(self): |
|
119 |
return None |
|
120 |
||
121 |
def get_master_branch(self, possible_transports=None): |
|
122 |
return None |
|
123 |
||
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
124 |
|
125 |
class BzrBranchFormat4(BranchFormat): |
|
126 |
"""Bzr branch format 4. |
|
127 |
||
128 |
This format has:
|
|
129 |
- a revision-history file.
|
|
130 |
- a branch-lock lock file [ to be shared with the bzrdir ]
|
|
|
5718.8.2
by Jelmer Vernooij
Split out full history branch code. |
131 |
|
132 |
It does not support binding.
|
|
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
133 |
"""
|
134 |
||
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
135 |
def initialize(self, a_controldir, name=None, repository=None, |
|
6123.9.12
by Jelmer Vernooij
Add append_revisions_only argument to BranchFormat.initialize. |
136 |
append_revisions_only=None): |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
137 |
"""Create a branch of this format in a_controldir. |
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
138 |
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
139 |
:param a_controldir: The bzrdir to initialize the branch in
|
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
140 |
:param name: Name of colocated branch to create, if any
|
|
5705.2.1
by Jelmer Vernooij
Inline _initialize_helper. |
141 |
:param repository: Repository for this branch (unused)
|
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
142 |
"""
|
|
6123.9.12
by Jelmer Vernooij
Add append_revisions_only argument to BranchFormat.initialize. |
143 |
if append_revisions_only: |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
144 |
raise errors.UpgradeRequired(a_controldir.user_url) |
|
5705.2.1
by Jelmer Vernooij
Inline _initialize_helper. |
145 |
if repository is not None: |
146 |
raise NotImplementedError( |
|
147 |
"initialize(repository=<not None>) on %r" % (self,)) |
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
148 |
if not [isinstance(a_controldir._format, format) for format in |
|
5705.2.2
by Jelmer Vernooij
Only support BzrBranchFormat4 in pre-metadir bzr dirs. |
149 |
self._compatible_bzrdirs]: |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
150 |
raise errors.IncompatibleFormat(self, a_controldir._format) |
|
6855.2.2
by Jelmer Vernooij
Format strings are bytes. |
151 |
utf8_files = [('revision-history', b''), |
152 |
('branch-name', b''), |
|
|
5705.2.1
by Jelmer Vernooij
Inline _initialize_helper. |
153 |
]
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
154 |
mutter('creating branch %r in %s', self, a_controldir.user_url) |
155 |
branch_transport = a_controldir.get_branch_transport(self, name=name) |
|
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
156 |
control_files = lockable_files.LockableFiles(branch_transport, |
157 |
'branch-lock', lockable_files.TransportLock) |
|
158 |
control_files.create_lock() |
|
159 |
try: |
|
160 |
control_files.lock_write() |
|
161 |
except errors.LockContention: |
|
162 |
lock_taken = False |
|
163 |
else: |
|
164 |
lock_taken = True |
|
165 |
try: |
|
166 |
for (filename, content) in utf8_files: |
|
167 |
branch_transport.put_bytes( |
|
168 |
filename, content, |
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
169 |
mode=a_controldir._get_file_mode()) |
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
170 |
finally: |
171 |
if lock_taken: |
|
172 |
control_files.unlock() |
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
173 |
branch = self.open(a_controldir, name, _found=True, |
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
174 |
found_repository=None) |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
175 |
self._run_post_branch_init_hooks(a_controldir, name, branch) |
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
176 |
return branch |
177 |
||
178 |
def __init__(self): |
|
179 |
super(BzrBranchFormat4, self).__init__() |
|
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
180 |
from .bzrdir import ( |
|
5582.10.87
by Jelmer Vernooij
Merge bzr.dev. |
181 |
BzrDirFormat4, BzrDirFormat5, BzrDirFormat6, |
182 |
)
|
|
|
6746.2.1
by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir. |
183 |
self._matchingcontroldir = BzrDirFormat6() |
|
5705.2.2
by Jelmer Vernooij
Only support BzrBranchFormat4 in pre-metadir bzr dirs. |
184 |
self._compatible_bzrdirs = [BzrDirFormat4, BzrDirFormat5, |
185 |
BzrDirFormat6] |
|
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
186 |
|
187 |
def network_name(self): |
|
188 |
"""The network name for this format is the control dirs disk label.""" |
|
|
6746.2.1
by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir. |
189 |
return self._matchingcontroldir.get_format_string() |
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
190 |
|
|
5705.2.4
by Jelmer Vernooij
Add BzrBranchFormat4.get_format_description(). |
191 |
def get_format_description(self): |
|
5705.2.6
by Jelmer Vernooij
Fix case sensitivity. |
192 |
return "Branch format 4" |
|
5705.2.4
by Jelmer Vernooij
Add BzrBranchFormat4.get_format_description(). |
193 |
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
194 |
def open(self, a_controldir, name=None, _found=False, ignore_fallbacks=False, |
|
6305.3.3
by Jelmer Vernooij
Fix use of possible_transports. |
195 |
found_repository=None, possible_transports=None): |
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
196 |
"""See BranchFormat.open().""" |
|
6436.1.2
by Jelmer Vernooij
Fix some tests. |
197 |
if name is None: |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
198 |
name = a_controldir._get_selected_branch() |
|
6436.1.2
by Jelmer Vernooij
Fix some tests. |
199 |
if name != "": |
|
5699.4.8
by Jelmer Vernooij
Properly raise NoColocatedBranchSupport. |
200 |
raise errors.NoColocatedBranchSupport(self) |
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
201 |
if not _found: |
202 |
# we are being called directly and must probe.
|
|
203 |
raise NotImplementedError |
|
204 |
if found_repository is None: |
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
205 |
found_repository = a_controldir.open_repository() |
|
5718.8.1
by Jelmer Vernooij
Add FullHistoryBzrBranch. |
206 |
return BzrBranch4(_format=self, |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
207 |
_control_files=a_controldir._control_files, |
208 |
a_controldir=a_controldir, |
|
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
209 |
name=name, |
|
6305.3.3
by Jelmer Vernooij
Fix use of possible_transports. |
210 |
_repository=found_repository, |
211 |
possible_transports=possible_transports) |
|
|
5697.2.1
by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave. |
212 |
|
213 |
def __str__(self): |
|
214 |
return "Bazaar-NG branch format 4" |
|
215 |
||
216 |
def supports_leaving_lock(self): |
|
217 |
return False |