bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
3602.2.1
by Martin Pool
Fix and test for problem upgrading stacked branches |
1 |
# Copyright (C) 2006, 2007, 2008 Canonical Ltd
|
|
1685.1.63
by Martin Pool
Small Transport fixups |
2 |
#
|
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
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.
|
|
|
1685.1.63
by Martin Pool
Small Transport fixups |
7 |
#
|
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
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.
|
|
|
1685.1.63
by Martin Pool
Small Transport fixups |
12 |
#
|
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
"""Tests for the Repository facility that are not interface tests.
|
|
18 |
||
|
3689.1.4
by John Arbash Meinel
Doc strings that reference repository_implementations |
19 |
For interface tests see tests/per_repository/*.py.
|
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
20 |
|
21 |
For concrete class tests see this file, and for storage formats tests
|
|
22 |
also see this file.
|
|
23 |
"""
|
|
24 |
||
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
25 |
from stat import S_ISDIR |
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
26 |
from StringIO import StringIO |
27 |
||
|
1556.1.4
by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same. |
28 |
import bzrlib |
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
29 |
from bzrlib.errors import (NotBranchError, |
|
1534.4.41
by Robert Collins
Branch now uses BzrDir reasonably sanely. |
30 |
NoSuchFile, |
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
31 |
UnknownFormatError, |
32 |
UnsupportedFormatError, |
|
33 |
)
|
|
|
3184.1.9
by Robert Collins
* ``Repository.get_data_stream`` is now deprecated in favour of |
34 |
from bzrlib import graph |
|
3735.1.1
by Robert Collins
Add development2 formats using BTree indices. |
35 |
from bzrlib.btree_index import BTreeBuilder, BTreeGraphIndex |
|
2592.3.192
by Robert Collins
Move new revision index management to NewPack. |
36 |
from bzrlib.index import GraphIndex, InMemoryGraphIndex |
|
2241.1.1
by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary |
37 |
from bzrlib.repository import RepositoryFormat |
|
2535.3.41
by Andrew Bennetts
Add tests for InterRemoteToOther.is_compatible. |
38 |
from bzrlib.smart import server |
|
2670.3.5
by Andrew Bennetts
Remove get_stream_as_bytes from KnitVersionedFile's API, make it a function in knitrepo.py instead. |
39 |
from bzrlib.tests import ( |
40 |
TestCase, |
|
41 |
TestCaseWithTransport, |
|
|
3446.2.1
by Martin Pool
Failure to delete an obsolete pack file should not be fatal. |
42 |
TestSkipped, |
|
2670.3.5
by Andrew Bennetts
Remove get_stream_as_bytes from KnitVersionedFile's API, make it a function in knitrepo.py instead. |
43 |
test_knit, |
44 |
)
|
|
|
3446.2.1
by Martin Pool
Failure to delete an obsolete pack file should not be fatal. |
45 |
from bzrlib.transport import ( |
46 |
fakenfs, |
|
47 |
get_transport, |
|
48 |
)
|
|
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
49 |
from bzrlib.transport.memory import MemoryServer |
|
2535.3.53
by Andrew Bennetts
Remove get_stream_as_bytes from KnitVersionedFile's API, make it a function in knitrepo.py instead. |
50 |
from bzrlib.util import bencode |
|
2241.1.1
by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary |
51 |
from bzrlib import ( |
|
2535.3.41
by Andrew Bennetts
Add tests for InterRemoteToOther.is_compatible. |
52 |
bzrdir, |
53 |
errors, |
|
|
2535.3.57
by Andrew Bennetts
Perform some sanity checking of data streams rather than blindly inserting them into our repository. |
54 |
inventory, |
|
2929.3.5
by Vincent Ladeuil
New files, same warnings, same fixes. |
55 |
osutils, |
|
3146.6.1
by Aaron Bentley
InterDifferingSerializer shows a progress bar |
56 |
progress, |
|
2241.1.1
by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary |
57 |
repository, |
|
2535.3.57
by Andrew Bennetts
Perform some sanity checking of data streams rather than blindly inserting them into our repository. |
58 |
revision as _mod_revision, |
|
2535.3.41
by Andrew Bennetts
Add tests for InterRemoteToOther.is_compatible. |
59 |
symbol_versioning, |
|
2241.1.1
by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary |
60 |
upgrade, |
61 |
workingtree, |
|
62 |
)
|
|
|
2592.3.173
by Robert Collins
Basic implementation of all_packs. |
63 |
from bzrlib.repofmt import knitrepo, weaverepo, pack_repo |
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
64 |
|
65 |
||
66 |
class TestDefaultFormat(TestCase): |
|
67 |
||
|
1534.4.41
by Robert Collins
Branch now uses BzrDir reasonably sanely. |
68 |
def test_get_set_default_format(self): |
|
2204.5.3
by Aaron Bentley
zap old repository default handling |
69 |
old_default = bzrdir.format_registry.get('default') |
70 |
private_default = old_default().repository_format.__class__ |
|
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
71 |
old_format = repository.RepositoryFormat.get_default_format() |
|
1910.2.33
by Aaron Bentley
Fix default format test |
72 |
self.assertTrue(isinstance(old_format, private_default)) |
|
2204.5.3
by Aaron Bentley
zap old repository default handling |
73 |
def make_sample_bzrdir(): |
74 |
my_bzrdir = bzrdir.BzrDirMetaFormat1() |
|
75 |
my_bzrdir.repository_format = SampleRepositoryFormat() |
|
76 |
return my_bzrdir |
|
77 |
bzrdir.format_registry.remove('default') |
|
78 |
bzrdir.format_registry.register('sample', make_sample_bzrdir, '') |
|
79 |
bzrdir.format_registry.set_default('sample') |
|
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
80 |
# creating a repository should now create an instrumented dir.
|
81 |
try: |
|
|
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
82 |
# the default branch format is used by the meta dir format
|
83 |
# which is not the default bzrdir format at this point
|
|
|
1685.1.63
by Martin Pool
Small Transport fixups |
84 |
dir = bzrdir.BzrDirMetaFormat1().initialize('memory:///') |
|
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
85 |
result = dir.create_repository() |
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
86 |
self.assertEqual(result, 'A bzr repository dir') |
|
2241.1.1
by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary |
87 |
finally: |
|
2204.5.3
by Aaron Bentley
zap old repository default handling |
88 |
bzrdir.format_registry.remove('default') |
|
2363.5.14
by Aaron Bentley
Prevent repository.get_set_default_format from corrupting inventory |
89 |
bzrdir.format_registry.remove('sample') |
|
2204.5.3
by Aaron Bentley
zap old repository default handling |
90 |
bzrdir.format_registry.register('default', old_default, '') |
91 |
self.assertIsInstance(repository.RepositoryFormat.get_default_format(), |
|
92 |
old_format.__class__) |
|
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
93 |
|
94 |
||
95 |
class SampleRepositoryFormat(repository.RepositoryFormat): |
|
96 |
"""A sample format |
|
97 |
||
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
98 |
this format is initializable, unsupported to aid in testing the
|
|
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
99 |
open and open(unsupported=True) routines.
|
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
100 |
"""
|
101 |
||
102 |
def get_format_string(self): |
|
103 |
"""See RepositoryFormat.get_format_string().""" |
|
104 |
return "Sample .bzr repository format." |
|
105 |
||
|
1534.6.1
by Robert Collins
allow API creation of shared repositories |
106 |
def initialize(self, a_bzrdir, shared=False): |
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
107 |
"""Initialize a repository in a BzrDir""" |
|
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
108 |
t = a_bzrdir.get_repository_transport(self) |
|
1955.3.13
by John Arbash Meinel
Run the full test suite, and fix up any deprecation warnings. |
109 |
t.put_bytes('format', self.get_format_string()) |
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
110 |
return 'A bzr repository dir' |
111 |
||
112 |
def is_supported(self): |
|
113 |
return False |
|
114 |
||
|
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
115 |
def open(self, a_bzrdir, _found=False): |
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
116 |
return "opened repository." |
|
1534.4.41
by Robert Collins
Branch now uses BzrDir reasonably sanely. |
117 |
|
118 |
||
|
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
119 |
class TestRepositoryFormat(TestCaseWithTransport): |
120 |
"""Tests for the Repository format detection used by the bzr meta dir facility.BzrBranchFormat facility.""" |
|
121 |
||
122 |
def test_find_format(self): |
|
123 |
# is the right format object found for a repository?
|
|
124 |
# create a branch with a few known format objects.
|
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
125 |
# this is not quite the same as
|
|
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
126 |
self.build_tree(["foo/", "bar/"]) |
127 |
def check_format(format, url): |
|
128 |
dir = format._matchingbzrdir.initialize(url) |
|
129 |
format.initialize(dir) |
|
130 |
t = get_transport(url) |
|
131 |
found_format = repository.RepositoryFormat.find_format(dir) |
|
132 |
self.failUnless(isinstance(found_format, format.__class__)) |
|
|
2241.1.4
by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo. |
133 |
check_format(weaverepo.RepositoryFormat7(), "bar") |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
134 |
|
|
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
135 |
def test_find_format_no_repository(self): |
136 |
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url()) |
|
137 |
self.assertRaises(errors.NoRepositoryPresent, |
|
138 |
repository.RepositoryFormat.find_format, |
|
139 |
dir) |
|
140 |
||
141 |
def test_find_format_unknown_format(self): |
|
142 |
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url()) |
|
143 |
SampleRepositoryFormat().initialize(dir) |
|
144 |
self.assertRaises(UnknownFormatError, |
|
145 |
repository.RepositoryFormat.find_format, |
|
146 |
dir) |
|
147 |
||
148 |
def test_register_unregister_format(self): |
|
149 |
format = SampleRepositoryFormat() |
|
150 |
# make a control dir
|
|
151 |
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url()) |
|
152 |
# make a repo
|
|
153 |
format.initialize(dir) |
|
154 |
# register a format for it.
|
|
155 |
repository.RepositoryFormat.register_format(format) |
|
156 |
# which repository.Open will refuse (not supported)
|
|
157 |
self.assertRaises(UnsupportedFormatError, repository.Repository.open, self.get_url()) |
|
158 |
# but open(unsupported) will work
|
|
159 |
self.assertEqual(format.open(dir), "opened repository.") |
|
160 |
# unregister the format
|
|
161 |
repository.RepositoryFormat.unregister_format(format) |
|
162 |
||
163 |
||
|
1534.4.41
by Robert Collins
Branch now uses BzrDir reasonably sanely. |
164 |
class TestFormat6(TestCaseWithTransport): |
165 |
||
|
3565.3.1
by Robert Collins
* The generic fetch code now uses two attributes on Repository objects |
166 |
def test_attribute__fetch_order(self): |
167 |
"""Weaves need topological data insertion.""" |
|
168 |
control = bzrdir.BzrDirFormat6().initialize(self.get_url()) |
|
169 |
repo = weaverepo.RepositoryFormat6().initialize(control) |
|
|
4053.1.4
by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat. |
170 |
self.assertEqual('topological', repo._format._fetch_order) |
|
3565.3.1
by Robert Collins
* The generic fetch code now uses two attributes on Repository objects |
171 |
|
172 |
def test_attribute__fetch_uses_deltas(self): |
|
173 |
"""Weaves do not reuse deltas.""" |
|
174 |
control = bzrdir.BzrDirFormat6().initialize(self.get_url()) |
|
175 |
repo = weaverepo.RepositoryFormat6().initialize(control) |
|
|
4053.1.4
by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat. |
176 |
self.assertEqual(False, repo._format._fetch_uses_deltas) |
|
3565.3.1
by Robert Collins
* The generic fetch code now uses two attributes on Repository objects |
177 |
|
|
3565.3.4
by Robert Collins
Defer decision to reconcile to the repository being fetched into. |
178 |
def test_attribute__fetch_reconcile(self): |
179 |
"""Weave repositories need a reconcile after fetch.""" |
|
180 |
control = bzrdir.BzrDirFormat6().initialize(self.get_url()) |
|
181 |
repo = weaverepo.RepositoryFormat6().initialize(control) |
|
|
4053.1.4
by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat. |
182 |
self.assertEqual(True, repo._format._fetch_reconcile) |
|
3565.3.4
by Robert Collins
Defer decision to reconcile to the repository being fetched into. |
183 |
|
|
1534.4.41
by Robert Collins
Branch now uses BzrDir reasonably sanely. |
184 |
def test_no_ancestry_weave(self): |
185 |
control = bzrdir.BzrDirFormat6().initialize(self.get_url()) |
|
|
2241.1.4
by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo. |
186 |
repo = weaverepo.RepositoryFormat6().initialize(control) |
|
1534.4.41
by Robert Collins
Branch now uses BzrDir reasonably sanely. |
187 |
# We no longer need to create the ancestry.weave file
|
188 |
# since it is *never* used.
|
|
189 |
self.assertRaises(NoSuchFile, |
|
190 |
control.transport.get, |
|
191 |
'ancestry.weave') |
|
192 |
||
|
3221.3.1
by Robert Collins
* Repository formats have a new supported-feature attribute |
193 |
def test_supports_external_lookups(self): |
194 |
control = bzrdir.BzrDirFormat6().initialize(self.get_url()) |
|
195 |
repo = weaverepo.RepositoryFormat6().initialize(control) |
|
196 |
self.assertFalse(repo._format.supports_external_lookups) |
|
197 |
||
|
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
198 |
|
199 |
class TestFormat7(TestCaseWithTransport): |
|
|
3565.3.1
by Robert Collins
* The generic fetch code now uses two attributes on Repository objects |
200 |
|
201 |
def test_attribute__fetch_order(self): |
|
202 |
"""Weaves need topological data insertion.""" |
|
203 |
control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url()) |
|
204 |
repo = weaverepo.RepositoryFormat7().initialize(control) |
|
|
4053.1.4
by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat. |
205 |
self.assertEqual('topological', repo._format._fetch_order) |
|
3565.3.1
by Robert Collins
* The generic fetch code now uses two attributes on Repository objects |
206 |
|
207 |
def test_attribute__fetch_uses_deltas(self): |
|
208 |
"""Weaves do not reuse deltas.""" |
|
209 |
control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url()) |
|
210 |
repo = weaverepo.RepositoryFormat7().initialize(control) |
|
|
4053.1.4
by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat. |
211 |
self.assertEqual(False, repo._format._fetch_uses_deltas) |
|
3565.3.1
by Robert Collins
* The generic fetch code now uses two attributes on Repository objects |
212 |
|
|
3565.3.4
by Robert Collins
Defer decision to reconcile to the repository being fetched into. |
213 |
def test_attribute__fetch_reconcile(self): |
214 |
"""Weave repositories need a reconcile after fetch.""" |
|
215 |
control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url()) |
|
216 |
repo = weaverepo.RepositoryFormat7().initialize(control) |
|
|
4053.1.4
by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat. |
217 |
self.assertEqual(True, repo._format._fetch_reconcile) |
|
3565.3.4
by Robert Collins
Defer decision to reconcile to the repository being fetched into. |
218 |
|
|
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
219 |
def test_disk_layout(self): |
220 |
control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url()) |
|
|
2241.1.4
by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo. |
221 |
repo = weaverepo.RepositoryFormat7().initialize(control) |
|
1534.5.3
by Robert Collins
Make format 4/5/6 branches share a single LockableFiles instance across wt/branch/repository. |
222 |
# in case of side effects of locking.
|
223 |
repo.lock_write() |
|
224 |
repo.unlock() |
|
|
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
225 |
# we want:
|
226 |
# format 'Bazaar-NG Repository format 7'
|
|
227 |
# lock ''
|
|
228 |
# inventory.weave == empty_weave
|
|
229 |
# empty revision-store directory
|
|
230 |
# empty weaves directory
|
|
231 |
t = control.get_repository_transport(None) |
|
232 |
self.assertEqualDiff('Bazaar-NG Repository format 7', |
|
233 |
t.get('format').read()) |
|
234 |
self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode)) |
|
235 |
self.assertTrue(S_ISDIR(t.stat('weaves').st_mode)) |
|
236 |
self.assertEqualDiff('# bzr weave file v5\n' |
|
237 |
'w\n' |
|
238 |
'W\n', |
|
239 |
t.get('inventory.weave').read()) |
|
|
3350.6.4
by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores. |
240 |
# Creating a file with id Foo:Bar results in a non-escaped file name on
|
241 |
# disk.
|
|
242 |
control.create_branch() |
|
243 |
tree = control.create_workingtree() |
|
244 |
tree.add(['foo'], ['Foo:Bar'], ['file']) |
|
245 |
tree.put_file_bytes_non_atomic('Foo:Bar', 'content\n') |
|
246 |
tree.commit('first post', rev_id='first') |
|
247 |
self.assertEqualDiff( |
|
248 |
'# bzr weave file v5\n' |
|
249 |
'i\n' |
|
250 |
'1 7fe70820e08a1aac0ef224d9c66ab66831cc4ab1\n' |
|
251 |
'n first\n' |
|
252 |
'\n' |
|
253 |
'w\n' |
|
254 |
'{ 0\n' |
|
255 |
'. content\n' |
|
256 |
'}\n' |
|
257 |
'W\n', |
|
258 |
t.get('weaves/74/Foo%3ABar.weave').read()) |
|
|
1534.6.1
by Robert Collins
allow API creation of shared repositories |
259 |
|
260 |
def test_shared_disk_layout(self): |
|
261 |
control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url()) |
|
|
2241.1.4
by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo. |
262 |
repo = weaverepo.RepositoryFormat7().initialize(control, shared=True) |
|
1534.6.1
by Robert Collins
allow API creation of shared repositories |
263 |
# we want:
|
264 |
# format 'Bazaar-NG Repository format 7'
|
|
265 |
# inventory.weave == empty_weave
|
|
266 |
# empty revision-store directory
|
|
267 |
# empty weaves directory
|
|
268 |
# a 'shared-storage' marker file.
|
|
|
1553.5.49
by Martin Pool
Use LockDirs for repo format 7 |
269 |
# lock is not present when unlocked
|
|
1534.6.1
by Robert Collins
allow API creation of shared repositories |
270 |
t = control.get_repository_transport(None) |
271 |
self.assertEqualDiff('Bazaar-NG Repository format 7', |
|
272 |
t.get('format').read()) |
|
273 |
self.assertEqualDiff('', t.get('shared-storage').read()) |
|
274 |
self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode)) |
|
275 |
self.assertTrue(S_ISDIR(t.stat('weaves').st_mode)) |
|
276 |
self.assertEqualDiff('# bzr weave file v5\n' |
|
277 |
'w\n' |
|
278 |
'W\n', |
|
279 |
t.get('inventory.weave').read()) |
|
|
1553.5.49
by Martin Pool
Use LockDirs for repo format 7 |
280 |
self.assertFalse(t.has('branch-lock')) |
281 |
||
|
1553.5.56
by Martin Pool
Format 7 repo now uses LockDir! |
282 |
def test_creates_lockdir(self): |
|
1553.5.49
by Martin Pool
Use LockDirs for repo format 7 |
283 |
"""Make sure it appears to be controlled by a LockDir existence""" |
284 |
control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url()) |
|
|
2241.1.4
by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo. |
285 |
repo = weaverepo.RepositoryFormat7().initialize(control, shared=True) |
|
1553.5.49
by Martin Pool
Use LockDirs for repo format 7 |
286 |
t = control.get_repository_transport(None) |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
287 |
# TODO: Should check there is a 'lock' toplevel directory,
|
|
1553.5.58
by Martin Pool
Change LockDirs to format "lock-name/held/info" |
288 |
# regardless of contents
|
289 |
self.assertFalse(t.has('lock/held/info')) |
|
|
1553.5.49
by Martin Pool
Use LockDirs for repo format 7 |
290 |
repo.lock_write() |
|
1658.1.4
by Martin Pool
Quieten warning from TestFormat7.test_creates_lockdir about failing to unlock |
291 |
try: |
292 |
self.assertTrue(t.has('lock/held/info')) |
|
293 |
finally: |
|
294 |
# unlock so we don't get a warning about failing to do so
|
|
295 |
repo.unlock() |
|
|
1553.5.56
by Martin Pool
Format 7 repo now uses LockDir! |
296 |
|
297 |
def test_uses_lockdir(self): |
|
298 |
"""repo format 7 actually locks on lockdir""" |
|
299 |
base_url = self.get_url() |
|
300 |
control = bzrdir.BzrDirMetaFormat1().initialize(base_url) |
|
|
2241.1.4
by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo. |
301 |
repo = weaverepo.RepositoryFormat7().initialize(control, shared=True) |
|
1553.5.56
by Martin Pool
Format 7 repo now uses LockDir! |
302 |
t = control.get_repository_transport(None) |
303 |
repo.lock_write() |
|
304 |
repo.unlock() |
|
305 |
del repo |
|
306 |
# make sure the same lock is created by opening it
|
|
307 |
repo = repository.Repository.open(base_url) |
|
308 |
repo.lock_write() |
|
|
1553.5.58
by Martin Pool
Change LockDirs to format "lock-name/held/info" |
309 |
self.assertTrue(t.has('lock/held/info')) |
|
1553.5.56
by Martin Pool
Format 7 repo now uses LockDir! |
310 |
repo.unlock() |
|
1553.5.58
by Martin Pool
Change LockDirs to format "lock-name/held/info" |
311 |
self.assertFalse(t.has('lock/held/info')) |
|
1534.6.5
by Robert Collins
Cloning of repos preserves shared and make-working-tree attributes. |
312 |
|
313 |
def test_shared_no_tree_disk_layout(self): |
|
314 |
control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url()) |
|
|
2241.1.4
by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo. |
315 |
repo = weaverepo.RepositoryFormat7().initialize(control, shared=True) |
|
1534.6.5
by Robert Collins
Cloning of repos preserves shared and make-working-tree attributes. |
316 |
repo.set_make_working_trees(False) |
317 |
# we want:
|
|
318 |
# format 'Bazaar-NG Repository format 7'
|
|
319 |
# lock ''
|
|
320 |
# inventory.weave == empty_weave
|
|
321 |
# empty revision-store directory
|
|
322 |
# empty weaves directory
|
|
323 |
# a 'shared-storage' marker file.
|
|
324 |
t = control.get_repository_transport(None) |
|
325 |
self.assertEqualDiff('Bazaar-NG Repository format 7', |
|
326 |
t.get('format').read()) |
|
|
1553.5.56
by Martin Pool
Format 7 repo now uses LockDir! |
327 |
## self.assertEqualDiff('', t.get('lock').read())
|
|
1534.6.5
by Robert Collins
Cloning of repos preserves shared and make-working-tree attributes. |
328 |
self.assertEqualDiff('', t.get('shared-storage').read()) |
329 |
self.assertEqualDiff('', t.get('no-working-trees').read()) |
|
330 |
repo.set_make_working_trees(True) |
|
331 |
self.assertFalse(t.has('no-working-trees')) |
|
332 |
self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode)) |
|
333 |
self.assertTrue(S_ISDIR(t.stat('weaves').st_mode)) |
|
334 |
self.assertEqualDiff('# bzr weave file v5\n' |
|
335 |
'w\n' |
|
336 |
'W\n', |
|
337 |
t.get('inventory.weave').read()) |
|
|
1534.1.27
by Robert Collins
Start InterRepository with InterRepository.get. |
338 |
|
|
3221.3.1
by Robert Collins
* Repository formats have a new supported-feature attribute |
339 |
def test_supports_external_lookups(self): |
340 |
control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url()) |
|
341 |
repo = weaverepo.RepositoryFormat7().initialize(control) |
|
342 |
self.assertFalse(repo._format.supports_external_lookups) |
|
343 |
||
|
1534.1.27
by Robert Collins
Start InterRepository with InterRepository.get. |
344 |
|
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
345 |
class TestFormatKnit1(TestCaseWithTransport): |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
346 |
|
|
3565.3.1
by Robert Collins
* The generic fetch code now uses two attributes on Repository objects |
347 |
def test_attribute__fetch_order(self): |
348 |
"""Knits need topological data insertion.""" |
|
349 |
repo = self.make_repository('.', |
|
350 |
format=bzrdir.format_registry.get('knit')()) |
|
|
4053.1.4
by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat. |
351 |
self.assertEqual('topological', repo._format._fetch_order) |
|
3565.3.1
by Robert Collins
* The generic fetch code now uses two attributes on Repository objects |
352 |
|
353 |
def test_attribute__fetch_uses_deltas(self): |
|
354 |
"""Knits reuse deltas.""" |
|
355 |
repo = self.make_repository('.', |
|
356 |
format=bzrdir.format_registry.get('knit')()) |
|
|
4053.1.4
by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat. |
357 |
self.assertEqual(True, repo._format._fetch_uses_deltas) |
|
3565.3.1
by Robert Collins
* The generic fetch code now uses two attributes on Repository objects |
358 |
|
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
359 |
def test_disk_layout(self): |
360 |
control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url()) |
|
|
2241.1.6
by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and |
361 |
repo = knitrepo.RepositoryFormatKnit1().initialize(control) |
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
362 |
# in case of side effects of locking.
|
363 |
repo.lock_write() |
|
364 |
repo.unlock() |
|
365 |
# we want:
|
|
366 |
# format 'Bazaar-NG Knit Repository Format 1'
|
|
|
1553.5.62
by Martin Pool
Add tests that MetaDir repositories use LockDirs |
367 |
# lock: is a directory
|
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
368 |
# inventory.weave == empty_weave
|
369 |
# empty revision-store directory
|
|
370 |
# empty weaves directory
|
|
371 |
t = control.get_repository_transport(None) |
|
372 |
self.assertEqualDiff('Bazaar-NG Knit Repository Format 1', |
|
373 |
t.get('format').read()) |
|
|
1553.5.57
by Martin Pool
[merge] sync from bzr.dev |
374 |
# XXX: no locks left when unlocked at the moment
|
375 |
# self.assertEqualDiff('', t.get('lock').read())
|
|
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
376 |
self.assertTrue(S_ISDIR(t.stat('knits').st_mode)) |
|
1563.2.35
by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too. |
377 |
self.check_knits(t) |
|
3350.6.4
by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores. |
378 |
# Check per-file knits.
|
379 |
branch = control.create_branch() |
|
380 |
tree = control.create_workingtree() |
|
381 |
tree.add(['foo'], ['Nasty-IdC:'], ['file']) |
|
382 |
tree.put_file_bytes_non_atomic('Nasty-IdC:', '') |
|
383 |
tree.commit('1st post', rev_id='foo') |
|
384 |
self.assertHasKnit(t, 'knits/e8/%254easty-%2549d%2543%253a', |
|
385 |
'\nfoo fulltext 0 81 :') |
|
|
1563.2.35
by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too. |
386 |
|
|
3350.6.4
by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores. |
387 |
def assertHasKnit(self, t, knit_name, extra_content=''): |
|
1654.1.3
by Robert Collins
Refactor repository knit tests slightly to remove duplication - add a assertHasKnit method. |
388 |
"""Assert that knit_name exists on t.""" |
|
3350.6.4
by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores. |
389 |
self.assertEqualDiff('# bzr knit index 8\n' + extra_content, |
|
1654.1.3
by Robert Collins
Refactor repository knit tests slightly to remove duplication - add a assertHasKnit method. |
390 |
t.get(knit_name + '.kndx').read()) |
391 |
||
|
1563.2.35
by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too. |
392 |
def check_knits(self, t): |
393 |
"""check knit content for a repository.""" |
|
|
1654.1.3
by Robert Collins
Refactor repository knit tests slightly to remove duplication - add a assertHasKnit method. |
394 |
self.assertHasKnit(t, 'inventory') |
395 |
self.assertHasKnit(t, 'revisions') |
|
396 |
self.assertHasKnit(t, 'signatures') |
|
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
397 |
|
398 |
def test_shared_disk_layout(self): |
|
399 |
control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url()) |
|
|
2241.1.6
by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and |
400 |
repo = knitrepo.RepositoryFormatKnit1().initialize(control, shared=True) |
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
401 |
# we want:
|
402 |
# format 'Bazaar-NG Knit Repository Format 1'
|
|
|
1553.5.62
by Martin Pool
Add tests that MetaDir repositories use LockDirs |
403 |
# lock: is a directory
|
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
404 |
# inventory.weave == empty_weave
|
405 |
# empty revision-store directory
|
|
406 |
# empty weaves directory
|
|
407 |
# a 'shared-storage' marker file.
|
|
408 |
t = control.get_repository_transport(None) |
|
409 |
self.assertEqualDiff('Bazaar-NG Knit Repository Format 1', |
|
410 |
t.get('format').read()) |
|
|
1553.5.57
by Martin Pool
[merge] sync from bzr.dev |
411 |
# XXX: no locks left when unlocked at the moment
|
412 |
# self.assertEqualDiff('', t.get('lock').read())
|
|
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
413 |
self.assertEqualDiff('', t.get('shared-storage').read()) |
414 |
self.assertTrue(S_ISDIR(t.stat('knits').st_mode)) |
|
|
1563.2.35
by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too. |
415 |
self.check_knits(t) |
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
416 |
|
417 |
def test_shared_no_tree_disk_layout(self): |
|
418 |
control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url()) |
|
|
2241.1.6
by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and |
419 |
repo = knitrepo.RepositoryFormatKnit1().initialize(control, shared=True) |
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
420 |
repo.set_make_working_trees(False) |
421 |
# we want:
|
|
422 |
# format 'Bazaar-NG Knit Repository Format 1'
|
|
423 |
# lock ''
|
|
424 |
# inventory.weave == empty_weave
|
|
425 |
# empty revision-store directory
|
|
426 |
# empty weaves directory
|
|
427 |
# a 'shared-storage' marker file.
|
|
428 |
t = control.get_repository_transport(None) |
|
429 |
self.assertEqualDiff('Bazaar-NG Knit Repository Format 1', |
|
430 |
t.get('format').read()) |
|
|
1553.5.57
by Martin Pool
[merge] sync from bzr.dev |
431 |
# XXX: no locks left when unlocked at the moment
|
432 |
# self.assertEqualDiff('', t.get('lock').read())
|
|
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
433 |
self.assertEqualDiff('', t.get('shared-storage').read()) |
434 |
self.assertEqualDiff('', t.get('no-working-trees').read()) |
|
435 |
repo.set_make_working_trees(True) |
|
436 |
self.assertFalse(t.has('no-working-trees')) |
|
437 |
self.assertTrue(S_ISDIR(t.stat('knits').st_mode)) |
|
|
1563.2.35
by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too. |
438 |
self.check_knits(t) |
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
439 |
|
|
2917.2.1
by John Arbash Meinel
Fix bug #152360. The xml5 serializer should be using |
440 |
def test_deserialise_sets_root_revision(self): |
441 |
"""We must have a inventory.root.revision |
|
442 |
||
443 |
Old versions of the XML5 serializer did not set the revision_id for
|
|
444 |
the whole inventory. So we grab the one from the expected text. Which
|
|
445 |
is valid when the api is not being abused.
|
|
446 |
"""
|
|
447 |
repo = self.make_repository('.', |
|
448 |
format=bzrdir.format_registry.get('knit')()) |
|
449 |
inv_xml = '<inventory format="5">\n</inventory>\n' |
|
450 |
inv = repo.deserialise_inventory('test-rev-id', inv_xml) |
|
451 |
self.assertEqual('test-rev-id', inv.root.revision) |
|
452 |
||
453 |
def test_deserialise_uses_global_revision_id(self): |
|
454 |
"""If it is set, then we re-use the global revision id""" |
|
455 |
repo = self.make_repository('.', |
|
456 |
format=bzrdir.format_registry.get('knit')()) |
|
457 |
inv_xml = ('<inventory format="5" revision_id="other-rev-id">\n' |
|
458 |
'</inventory>\n') |
|
459 |
# Arguably, the deserialise_inventory should detect a mismatch, and
|
|
460 |
# raise an error, rather than silently using one revision_id over the
|
|
461 |
# other.
|
|
|
3169.2.2
by Robert Collins
Add a test to Repository.deserialise_inventory that the resulting ivnentory is the one asked for, and update relevant tests. Also tweak the model 1 to 2 regenerate inventories logic to use the revision trees parent marker which is more accurate in some cases. |
462 |
self.assertRaises(AssertionError, repo.deserialise_inventory, |
463 |
'test-rev-id', inv_xml) |
|
464 |
inv = repo.deserialise_inventory('other-rev-id', inv_xml) |
|
|
2917.2.1
by John Arbash Meinel
Fix bug #152360. The xml5 serializer should be using |
465 |
self.assertEqual('other-rev-id', inv.root.revision) |
466 |
||
|
3221.3.1
by Robert Collins
* Repository formats have a new supported-feature attribute |
467 |
def test_supports_external_lookups(self): |
468 |
repo = self.make_repository('.', |
|
469 |
format=bzrdir.format_registry.get('knit')()) |
|
470 |
self.assertFalse(repo._format.supports_external_lookups) |
|
471 |
||
|
2535.3.53
by Andrew Bennetts
Remove get_stream_as_bytes from KnitVersionedFile's API, make it a function in knitrepo.py instead. |
472 |
|
|
2305.2.3
by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures. |
473 |
class DummyRepository(object): |
474 |
"""A dummy repository for testing.""" |
|
475 |
||
|
3452.2.11
by Andrew Bennetts
Merge thread. |
476 |
_format = None |
|
2305.2.3
by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures. |
477 |
_serializer = None |
478 |
||
479 |
def supports_rich_root(self): |
|
480 |
return False |
|
481 |
||
|
3709.5.10
by Andrew Bennetts
Fix test failure caused by missing attributes on DummyRepository. |
482 |
def get_graph(self): |
483 |
raise NotImplementedError |
|
484 |
||
485 |
def get_parent_map(self, revision_ids): |
|
486 |
raise NotImplementedError |
|
487 |
||
|
2305.2.3
by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures. |
488 |
|
489 |
class InterDummy(repository.InterRepository): |
|
490 |
"""An inter-repository optimised code path for DummyRepository. |
|
491 |
||
492 |
This is for use during testing where we use DummyRepository as repositories
|
|
|
1534.1.28
by Robert Collins
Allow for optimised InterRepository selection. |
493 |
so that none of the default regsitered inter-repository classes will
|
|
2818.4.2
by Robert Collins
Review feedback. |
494 |
MATCH.
|
|
1534.1.28
by Robert Collins
Allow for optimised InterRepository selection. |
495 |
"""
|
496 |
||
497 |
@staticmethod
|
|
498 |
def is_compatible(repo_source, repo_target): |
|
|
2305.2.3
by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures. |
499 |
"""InterDummy is compatible with DummyRepository.""" |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
500 |
return (isinstance(repo_source, DummyRepository) and |
|
2305.2.3
by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures. |
501 |
isinstance(repo_target, DummyRepository)) |
|
1534.1.28
by Robert Collins
Allow for optimised InterRepository selection. |
502 |
|
503 |
||
|
1534.1.27
by Robert Collins
Start InterRepository with InterRepository.get. |
504 |
class TestInterRepository(TestCaseWithTransport): |
505 |
||
506 |
def test_get_default_inter_repository(self): |
|
507 |
# test that the InterRepository.get(repo_a, repo_b) probes
|
|
508 |
# for a inter_repo class where is_compatible(repo_a, repo_b) returns
|
|
509 |
# true and returns a default inter_repo otherwise.
|
|
510 |
# This also tests that the default registered optimised interrepository
|
|
511 |
# classes do not barf inappropriately when a surprising repository type
|
|
512 |
# is handed to them.
|
|
|
2305.2.3
by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures. |
513 |
dummy_a = DummyRepository() |
514 |
dummy_b = DummyRepository() |
|
|
1534.1.28
by Robert Collins
Allow for optimised InterRepository selection. |
515 |
self.assertGetsDefaultInterRepository(dummy_a, dummy_b) |
516 |
||
517 |
def assertGetsDefaultInterRepository(self, repo_a, repo_b): |
|
|
2305.2.3
by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures. |
518 |
"""Asserts that InterRepository.get(repo_a, repo_b) -> the default. |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
519 |
|
|
2305.2.3
by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures. |
520 |
The effective default is now InterSameDataRepository because there is
|
521 |
no actual sane default in the presence of incompatible data models.
|
|
522 |
"""
|
|
|
1534.1.28
by Robert Collins
Allow for optimised InterRepository selection. |
523 |
inter_repo = repository.InterRepository.get(repo_a, repo_b) |
|
2305.2.3
by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures. |
524 |
self.assertEqual(repository.InterSameDataRepository, |
|
1534.1.27
by Robert Collins
Start InterRepository with InterRepository.get. |
525 |
inter_repo.__class__) |
|
1534.1.28
by Robert Collins
Allow for optimised InterRepository selection. |
526 |
self.assertEqual(repo_a, inter_repo.source) |
527 |
self.assertEqual(repo_b, inter_repo.target) |
|
528 |
||
529 |
def test_register_inter_repository_class(self): |
|
530 |
# test that a optimised code path provider - a
|
|
531 |
# InterRepository subclass can be registered and unregistered
|
|
532 |
# and that it is correctly selected when given a repository
|
|
533 |
# pair that it returns true on for the is_compatible static method
|
|
534 |
# check
|
|
|
2305.2.3
by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures. |
535 |
dummy_a = DummyRepository() |
536 |
dummy_b = DummyRepository() |
|
537 |
repo = self.make_repository('.') |
|
538 |
# hack dummies to look like repo somewhat.
|
|
539 |
dummy_a._serializer = repo._serializer |
|
540 |
dummy_b._serializer = repo._serializer |
|
541 |
repository.InterRepository.register_optimiser(InterDummy) |
|
|
1534.1.28
by Robert Collins
Allow for optimised InterRepository selection. |
542 |
try: |
|
2305.2.3
by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures. |
543 |
# we should get the default for something InterDummy returns False
|
|
1534.1.28
by Robert Collins
Allow for optimised InterRepository selection. |
544 |
# to
|
|
2305.2.3
by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures. |
545 |
self.assertFalse(InterDummy.is_compatible(dummy_a, repo)) |
546 |
self.assertGetsDefaultInterRepository(dummy_a, repo) |
|
547 |
# and we should get an InterDummy for a pair it 'likes'
|
|
548 |
self.assertTrue(InterDummy.is_compatible(dummy_a, dummy_b)) |
|
|
1534.1.28
by Robert Collins
Allow for optimised InterRepository selection. |
549 |
inter_repo = repository.InterRepository.get(dummy_a, dummy_b) |
|
2305.2.3
by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures. |
550 |
self.assertEqual(InterDummy, inter_repo.__class__) |
|
1534.1.28
by Robert Collins
Allow for optimised InterRepository selection. |
551 |
self.assertEqual(dummy_a, inter_repo.source) |
552 |
self.assertEqual(dummy_b, inter_repo.target) |
|
553 |
finally: |
|
|
2305.2.3
by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures. |
554 |
repository.InterRepository.unregister_optimiser(InterDummy) |
|
1534.1.28
by Robert Collins
Allow for optimised InterRepository selection. |
555 |
# now we should get the default InterRepository object again.
|
556 |
self.assertGetsDefaultInterRepository(dummy_a, dummy_b) |
|
|
1534.1.33
by Robert Collins
Move copy_content_into into InterRepository and InterWeaveRepo, and disable the default codepath test as we have optimised paths for all current combinations. |
557 |
|
|
2241.1.17
by Martin Pool
Restore old InterWeave tests |
558 |
|
559 |
class TestInterWeaveRepo(TestCaseWithTransport): |
|
560 |
||
561 |
def test_is_compatible_and_registered(self): |
|
562 |
# InterWeaveRepo is compatible when either side
|
|
563 |
# is a format 5/6/7 branch
|
|
|
2241.1.20
by mbp at sourcefrog
update tests for new locations of weave repos |
564 |
from bzrlib.repofmt import knitrepo, weaverepo |
565 |
formats = [weaverepo.RepositoryFormat5(), |
|
566 |
weaverepo.RepositoryFormat6(), |
|
567 |
weaverepo.RepositoryFormat7()] |
|
568 |
incompatible_formats = [weaverepo.RepositoryFormat4(), |
|
569 |
knitrepo.RepositoryFormatKnit1(), |
|
|
2241.1.17
by Martin Pool
Restore old InterWeave tests |
570 |
]
|
571 |
repo_a = self.make_repository('a') |
|
572 |
repo_b = self.make_repository('b') |
|
573 |
is_compatible = repository.InterWeaveRepo.is_compatible |
|
574 |
for source in incompatible_formats: |
|
575 |
# force incompatible left then right
|
|
576 |
repo_a._format = source |
|
577 |
repo_b._format = formats[0] |
|
578 |
self.assertFalse(is_compatible(repo_a, repo_b)) |
|
579 |
self.assertFalse(is_compatible(repo_b, repo_a)) |
|
580 |
for source in formats: |
|
581 |
repo_a._format = source |
|
582 |
for target in formats: |
|
583 |
repo_b._format = target |
|
584 |
self.assertTrue(is_compatible(repo_a, repo_b)) |
|
585 |
self.assertEqual(repository.InterWeaveRepo, |
|
586 |
repository.InterRepository.get(repo_a, |
|
587 |
repo_b).__class__) |
|
588 |
||
|
1556.1.4
by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same. |
589 |
|
590 |
class TestRepositoryConverter(TestCaseWithTransport): |
|
591 |
||
592 |
def test_convert_empty(self): |
|
593 |
t = get_transport(self.get_url('.')) |
|
594 |
t.mkdir('repository') |
|
595 |
repo_dir = bzrdir.BzrDirMetaFormat1().initialize('repository') |
|
|
2241.1.4
by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo. |
596 |
repo = weaverepo.RepositoryFormat7().initialize(repo_dir) |
|
2241.1.6
by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and |
597 |
target_format = knitrepo.RepositoryFormatKnit1() |
|
1556.1.4
by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same. |
598 |
converter = repository.CopyConverter(target_format) |
|
1594.1.3
by Robert Collins
Fixup pb usage to use nested_progress_bar. |
599 |
pb = bzrlib.ui.ui_factory.nested_progress_bar() |
600 |
try: |
|
601 |
converter.convert(repo, pb) |
|
602 |
finally: |
|
603 |
pb.finished() |
|
|
1556.1.4
by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same. |
604 |
repo = repo_dir.open_repository() |
605 |
self.assertTrue(isinstance(target_format, repo._format.__class__)) |
|
|
1843.2.5
by Aaron Bentley
Add test of _unescape_xml |
606 |
|
607 |
||
608 |
class TestMisc(TestCase): |
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
609 |
|
|
1843.2.5
by Aaron Bentley
Add test of _unescape_xml |
610 |
def test_unescape_xml(self): |
611 |
"""We get some kind of error when malformed entities are passed""" |
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
612 |
self.assertRaises(KeyError, repository._unescape_xml, 'foo&bar;') |
|
1910.2.13
by Aaron Bentley
Start work on converter |
613 |
|
614 |
||
|
2255.2.211
by Robert Collins
Remove knit2 repository format- it has never been supported. |
615 |
class TestRepositoryFormatKnit3(TestCaseWithTransport): |
|
1910.2.13
by Aaron Bentley
Start work on converter |
616 |
|
|
3565.3.1
by Robert Collins
* The generic fetch code now uses two attributes on Repository objects |
617 |
def test_attribute__fetch_order(self): |
618 |
"""Knits need topological data insertion.""" |
|
619 |
format = bzrdir.BzrDirMetaFormat1() |
|
620 |
format.repository_format = knitrepo.RepositoryFormatKnit3() |
|
621 |
repo = self.make_repository('.', format=format) |
|
|
4053.1.4
by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat. |
622 |
self.assertEqual('topological', repo._format._fetch_order) |
|
3565.3.1
by Robert Collins
* The generic fetch code now uses two attributes on Repository objects |
623 |
|
624 |
def test_attribute__fetch_uses_deltas(self): |
|
625 |
"""Knits reuse deltas.""" |
|
626 |
format = bzrdir.BzrDirMetaFormat1() |
|
627 |
format.repository_format = knitrepo.RepositoryFormatKnit3() |
|
628 |
repo = self.make_repository('.', format=format) |
|
|
4053.1.4
by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat. |
629 |
self.assertEqual(True, repo._format._fetch_uses_deltas) |
|
3565.3.1
by Robert Collins
* The generic fetch code now uses two attributes on Repository objects |
630 |
|
|
1910.2.13
by Aaron Bentley
Start work on converter |
631 |
def test_convert(self): |
632 |
"""Ensure the upgrade adds weaves for roots""" |
|
|
1910.2.35
by Aaron Bentley
Better fix for convesion test |
633 |
format = bzrdir.BzrDirMetaFormat1() |
|
2241.1.6
by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and |
634 |
format.repository_format = knitrepo.RepositoryFormatKnit1() |
|
1910.2.35
by Aaron Bentley
Better fix for convesion test |
635 |
tree = self.make_branch_and_tree('.', format) |
|
1910.2.13
by Aaron Bentley
Start work on converter |
636 |
tree.commit("Dull commit", rev_id="dull") |
637 |
revision_tree = tree.branch.repository.revision_tree('dull') |
|
|
3350.6.4
by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores. |
638 |
revision_tree.lock_read() |
639 |
try: |
|
640 |
self.assertRaises(errors.NoSuchFile, revision_tree.get_file_lines, |
|
641 |
revision_tree.inventory.root.file_id) |
|
642 |
finally: |
|
643 |
revision_tree.unlock() |
|
|
1910.2.13
by Aaron Bentley
Start work on converter |
644 |
format = bzrdir.BzrDirMetaFormat1() |
|
2255.2.211
by Robert Collins
Remove knit2 repository format- it has never been supported. |
645 |
format.repository_format = knitrepo.RepositoryFormatKnit3() |
|
1910.2.13
by Aaron Bentley
Start work on converter |
646 |
upgrade.Convert('.', format) |
|
1910.2.27
by Aaron Bentley
Fixed conversion test |
647 |
tree = workingtree.WorkingTree.open('.') |
|
1910.2.13
by Aaron Bentley
Start work on converter |
648 |
revision_tree = tree.branch.repository.revision_tree('dull') |
|
3350.6.4
by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores. |
649 |
revision_tree.lock_read() |
650 |
try: |
|
651 |
revision_tree.get_file_lines(revision_tree.inventory.root.file_id) |
|
652 |
finally: |
|
653 |
revision_tree.unlock() |
|
|
1910.2.27
by Aaron Bentley
Fixed conversion test |
654 |
tree.commit("Another dull commit", rev_id='dull2') |
655 |
revision_tree = tree.branch.repository.revision_tree('dull2') |
|
|
3350.6.4
by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores. |
656 |
revision_tree.lock_read() |
657 |
self.addCleanup(revision_tree.unlock) |
|
|
1910.2.27
by Aaron Bentley
Fixed conversion test |
658 |
self.assertEqual('dull', revision_tree.inventory.root.revision) |
|
2220.2.2
by Martin Pool
Add tag command and basic implementation |
659 |
|
|
3221.3.1
by Robert Collins
* Repository formats have a new supported-feature attribute |
660 |
def test_supports_external_lookups(self): |
661 |
format = bzrdir.BzrDirMetaFormat1() |
|
662 |
format.repository_format = knitrepo.RepositoryFormatKnit3() |
|
663 |
repo = self.make_repository('.', format=format) |
|
664 |
self.assertFalse(repo._format.supports_external_lookups) |
|
665 |
||
|
2535.3.57
by Andrew Bennetts
Perform some sanity checking of data streams rather than blindly inserting them into our repository. |
666 |
|
667 |
class TestWithBrokenRepo(TestCaseWithTransport): |
|
|
2592.3.214
by Robert Collins
Merge bzr.dev. |
668 |
"""These tests seem to be more appropriate as interface tests?""" |
|
2535.3.57
by Andrew Bennetts
Perform some sanity checking of data streams rather than blindly inserting them into our repository. |
669 |
|
670 |
def make_broken_repository(self): |
|
671 |
# XXX: This function is borrowed from Aaron's "Reconcile can fix bad
|
|
672 |
# parent references" branch which is due to land in bzr.dev soon. Once
|
|
673 |
# it does, this duplication should be removed.
|
|
674 |
repo = self.make_repository('broken-repo') |
|
675 |
cleanups = [] |
|
676 |
try: |
|
677 |
repo.lock_write() |
|
678 |
cleanups.append(repo.unlock) |
|
679 |
repo.start_write_group() |
|
680 |
cleanups.append(repo.commit_write_group) |
|
681 |
# make rev1a: A well-formed revision, containing 'file1'
|
|
682 |
inv = inventory.Inventory(revision_id='rev1a') |
|
683 |
inv.root.revision = 'rev1a' |
|
684 |
self.add_file(repo, inv, 'file1', 'rev1a', []) |
|
685 |
repo.add_inventory('rev1a', inv, []) |
|
686 |
revision = _mod_revision.Revision('rev1a', |
|
687 |
committer='jrandom@example.com', timestamp=0, |
|
688 |
inventory_sha1='', timezone=0, message='foo', parent_ids=[]) |
|
689 |
repo.add_revision('rev1a',revision, inv) |
|
690 |
||
691 |
# make rev1b, which has no Revision, but has an Inventory, and
|
|
692 |
# file1
|
|
693 |
inv = inventory.Inventory(revision_id='rev1b') |
|
694 |
inv.root.revision = 'rev1b' |
|
695 |
self.add_file(repo, inv, 'file1', 'rev1b', []) |
|
696 |
repo.add_inventory('rev1b', inv, []) |
|
697 |
||
698 |
# make rev2, with file1 and file2
|
|
699 |
# file2 is sane
|
|
700 |
# file1 has 'rev1b' as an ancestor, even though this is not
|
|
701 |
# mentioned by 'rev1a', making it an unreferenced ancestor
|
|
702 |
inv = inventory.Inventory() |
|
703 |
self.add_file(repo, inv, 'file1', 'rev2', ['rev1a', 'rev1b']) |
|
704 |
self.add_file(repo, inv, 'file2', 'rev2', []) |
|
705 |
self.add_revision(repo, 'rev2', inv, ['rev1a']) |
|
706 |
||
707 |
# make ghost revision rev1c
|
|
708 |
inv = inventory.Inventory() |
|
709 |
self.add_file(repo, inv, 'file2', 'rev1c', []) |
|
710 |
||
711 |
# make rev3 with file2
|
|
712 |
# file2 refers to 'rev1c', which is a ghost in this repository, so
|
|
713 |
# file2 cannot have rev1c as its ancestor.
|
|
714 |
inv = inventory.Inventory() |
|
715 |
self.add_file(repo, inv, 'file2', 'rev3', ['rev1c']) |
|
716 |
self.add_revision(repo, 'rev3', inv, ['rev1c']) |
|
717 |
return repo |
|
718 |
finally: |
|
719 |
for cleanup in reversed(cleanups): |
|
720 |
cleanup() |
|
721 |
||
722 |
def add_revision(self, repo, revision_id, inv, parent_ids): |
|
723 |
inv.revision_id = revision_id |
|
724 |
inv.root.revision = revision_id |
|
725 |
repo.add_inventory(revision_id, inv, parent_ids) |
|
726 |
revision = _mod_revision.Revision(revision_id, |
|
727 |
committer='jrandom@example.com', timestamp=0, inventory_sha1='', |
|
728 |
timezone=0, message='foo', parent_ids=parent_ids) |
|
729 |
repo.add_revision(revision_id,revision, inv) |
|
730 |
||
731 |
def add_file(self, repo, inv, filename, revision, parents): |
|
732 |
file_id = filename + '-id' |
|
733 |
entry = inventory.InventoryFile(file_id, filename, 'TREE_ROOT') |
|
734 |
entry.revision = revision |
|
|
2535.4.10
by Andrew Bennetts
Fix one failing test, disable another. |
735 |
entry.text_size = 0 |
|
2535.3.57
by Andrew Bennetts
Perform some sanity checking of data streams rather than blindly inserting them into our repository. |
736 |
inv.add(entry) |
|
3350.6.4
by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores. |
737 |
text_key = (file_id, revision) |
738 |
parent_keys = [(file_id, parent) for parent in parents] |
|
739 |
repo.texts.add_lines(text_key, parent_keys, ['line\n']) |
|
|
2535.3.57
by Andrew Bennetts
Perform some sanity checking of data streams rather than blindly inserting them into our repository. |
740 |
|
741 |
def test_insert_from_broken_repo(self): |
|
742 |
"""Inserting a data stream from a broken repository won't silently |
|
743 |
corrupt the target repository.
|
|
744 |
"""
|
|
745 |
broken_repo = self.make_broken_repository() |
|
746 |
empty_repo = self.make_repository('empty-repo') |
|
|
3830.3.25
by John Arbash Meinel
We changed the error that is raised when fetching from a broken repo. |
747 |
self.assertRaises((errors.RevisionNotPresent, errors.BzrCheckError), |
748 |
empty_repo.fetch, broken_repo) |
|
|
2592.3.214
by Robert Collins
Merge bzr.dev. |
749 |
|
750 |
||
|
2592.3.84
by Robert Collins
Start of autopacking logic. |
751 |
class TestRepositoryPackCollection(TestCaseWithTransport): |
752 |
||
753 |
def get_format(self): |
|
|
3010.3.3
by Martin Pool
Merge trunk |
754 |
return bzrdir.format_registry.make_bzrdir('pack-0.92') |
|
2592.3.84
by Robert Collins
Start of autopacking logic. |
755 |
|
|
3711.4.1
by John Arbash Meinel
Fix bug #242510, when determining the autopack sequence, |
756 |
def get_packs(self): |
757 |
format = self.get_format() |
|
758 |
repo = self.make_repository('.', format=format) |
|
759 |
return repo._pack_collection |
|
760 |
||
|
3789.2.20
by John Arbash Meinel
The autopack code can now trigger itself to retry when _copy_revision_texts fails. |
761 |
def make_packs_and_alt_repo(self, write_lock=False): |
|
3789.2.19
by John Arbash Meinel
Refactor to make the tests a bit simpler |
762 |
"""Create a pack repo with 3 packs, and access it via a second repo.""" |
763 |
tree = self.make_branch_and_tree('.') |
|
764 |
tree.lock_write() |
|
765 |
self.addCleanup(tree.unlock) |
|
766 |
rev1 = tree.commit('one') |
|
767 |
rev2 = tree.commit('two') |
|
768 |
rev3 = tree.commit('three') |
|
769 |
r = repository.Repository.open('.') |
|
|
3789.2.20
by John Arbash Meinel
The autopack code can now trigger itself to retry when _copy_revision_texts fails. |
770 |
if write_lock: |
771 |
r.lock_write() |
|
772 |
else: |
|
773 |
r.lock_read() |
|
|
3789.2.19
by John Arbash Meinel
Refactor to make the tests a bit simpler |
774 |
self.addCleanup(r.unlock) |
775 |
packs = r._pack_collection |
|
776 |
packs.ensure_loaded() |
|
777 |
return tree, r, packs, [rev1, rev2, rev3] |
|
778 |
||
|
2592.3.84
by Robert Collins
Start of autopacking logic. |
779 |
def test__max_pack_count(self): |
|
2592.3.219
by Robert Collins
Review feedback. |
780 |
"""The maximum pack count is a function of the number of revisions.""" |
|
2592.3.84
by Robert Collins
Start of autopacking logic. |
781 |
# no revisions - one pack, so that we can have a revision free repo
|
782 |
# without it blowing up
|
|
|
3711.4.1
by John Arbash Meinel
Fix bug #242510, when determining the autopack sequence, |
783 |
packs = self.get_packs() |
|
2592.3.84
by Robert Collins
Start of autopacking logic. |
784 |
self.assertEqual(1, packs._max_pack_count(0)) |
785 |
# after that the sum of the digits, - check the first 1-9
|
|
786 |
self.assertEqual(1, packs._max_pack_count(1)) |
|
787 |
self.assertEqual(2, packs._max_pack_count(2)) |
|
788 |
self.assertEqual(3, packs._max_pack_count(3)) |
|
789 |
self.assertEqual(4, packs._max_pack_count(4)) |
|
790 |
self.assertEqual(5, packs._max_pack_count(5)) |
|
791 |
self.assertEqual(6, packs._max_pack_count(6)) |
|
792 |
self.assertEqual(7, packs._max_pack_count(7)) |
|
793 |
self.assertEqual(8, packs._max_pack_count(8)) |
|
794 |
self.assertEqual(9, packs._max_pack_count(9)) |
|
795 |
# check the boundary cases with two digits for the next decade
|
|
796 |
self.assertEqual(1, packs._max_pack_count(10)) |
|
797 |
self.assertEqual(2, packs._max_pack_count(11)) |
|
798 |
self.assertEqual(10, packs._max_pack_count(19)) |
|
799 |
self.assertEqual(2, packs._max_pack_count(20)) |
|
800 |
self.assertEqual(3, packs._max_pack_count(21)) |
|
801 |
# check some arbitrary big numbers
|
|
802 |
self.assertEqual(25, packs._max_pack_count(112894)) |
|
803 |
||
804 |
def test_pack_distribution_zero(self): |
|
|
3711.4.1
by John Arbash Meinel
Fix bug #242510, when determining the autopack sequence, |
805 |
packs = self.get_packs() |
|
2592.3.84
by Robert Collins
Start of autopacking logic. |
806 |
self.assertEqual([0], packs.pack_distribution(0)) |
|
3052.1.6
by John Arbash Meinel
Change the lock check to raise ObjectNotLocked. |
807 |
|
808 |
def test_ensure_loaded_unlocked(self): |
|
|
3711.4.1
by John Arbash Meinel
Fix bug #242510, when determining the autopack sequence, |
809 |
packs = self.get_packs() |
|
3052.1.6
by John Arbash Meinel
Change the lock check to raise ObjectNotLocked. |
810 |
self.assertRaises(errors.ObjectNotLocked, |
|
3711.4.1
by John Arbash Meinel
Fix bug #242510, when determining the autopack sequence, |
811 |
packs.ensure_loaded) |
|
3052.1.6
by John Arbash Meinel
Change the lock check to raise ObjectNotLocked. |
812 |
|
|
2592.3.84
by Robert Collins
Start of autopacking logic. |
813 |
def test_pack_distribution_one_to_nine(self): |
|
3711.4.1
by John Arbash Meinel
Fix bug #242510, when determining the autopack sequence, |
814 |
packs = self.get_packs() |
|
2592.3.84
by Robert Collins
Start of autopacking logic. |
815 |
self.assertEqual([1], |
816 |
packs.pack_distribution(1)) |
|
817 |
self.assertEqual([1, 1], |
|
818 |
packs.pack_distribution(2)) |
|
819 |
self.assertEqual([1, 1, 1], |
|
820 |
packs.pack_distribution(3)) |
|
821 |
self.assertEqual([1, 1, 1, 1], |
|
822 |
packs.pack_distribution(4)) |
|
823 |
self.assertEqual([1, 1, 1, 1, 1], |
|
824 |
packs.pack_distribution(5)) |
|
825 |
self.assertEqual([1, 1, 1, 1, 1, 1], |
|
826 |
packs.pack_distribution(6)) |
|
827 |
self.assertEqual([1, 1, 1, 1, 1, 1, 1], |
|
828 |
packs.pack_distribution(7)) |
|
829 |
self.assertEqual([1, 1, 1, 1, 1, 1, 1, 1], |
|
830 |
packs.pack_distribution(8)) |
|
831 |
self.assertEqual([1, 1, 1, 1, 1, 1, 1, 1, 1], |
|
832 |
packs.pack_distribution(9)) |
|
833 |
||
834 |
def test_pack_distribution_stable_at_boundaries(self): |
|
835 |
"""When there are multi-rev packs the counts are stable.""" |
|
|
3711.4.1
by John Arbash Meinel
Fix bug #242510, when determining the autopack sequence, |
836 |
packs = self.get_packs() |
|
2592.3.84
by Robert Collins
Start of autopacking logic. |
837 |
# in 10s:
|
838 |
self.assertEqual([10], packs.pack_distribution(10)) |
|
839 |
self.assertEqual([10, 1], packs.pack_distribution(11)) |
|
840 |
self.assertEqual([10, 10], packs.pack_distribution(20)) |
|
841 |
self.assertEqual([10, 10, 1], packs.pack_distribution(21)) |
|
842 |
# 100s
|
|
843 |
self.assertEqual([100], packs.pack_distribution(100)) |
|
844 |
self.assertEqual([100, 1], packs.pack_distribution(101)) |
|
845 |
self.assertEqual([100, 10, 1], packs.pack_distribution(111)) |
|
846 |
self.assertEqual([100, 100], packs.pack_distribution(200)) |
|
847 |
self.assertEqual([100, 100, 1], packs.pack_distribution(201)) |
|
848 |
self.assertEqual([100, 100, 10, 1], packs.pack_distribution(211)) |
|
849 |
||
|
2592.3.85
by Robert Collins
Finish autopack corner cases. |
850 |
def test_plan_pack_operations_2009_revisions_skip_all_packs(self): |
|
3711.4.1
by John Arbash Meinel
Fix bug #242510, when determining the autopack sequence, |
851 |
packs = self.get_packs() |
|
2592.3.85
by Robert Collins
Finish autopack corner cases. |
852 |
existing_packs = [(2000, "big"), (9, "medium")] |
853 |
# rev count - 2009 -> 2x1000 + 9x1
|
|
854 |
pack_operations = packs.plan_autopack_combinations( |
|
855 |
existing_packs, [1000, 1000, 1, 1, 1, 1, 1, 1, 1, 1, 1]) |
|
856 |
self.assertEqual([], pack_operations) |
|
857 |
||
858 |
def test_plan_pack_operations_2010_revisions_skip_all_packs(self): |
|
|
3711.4.1
by John Arbash Meinel
Fix bug #242510, when determining the autopack sequence, |
859 |
packs = self.get_packs() |
|
2592.3.85
by Robert Collins
Finish autopack corner cases. |
860 |
existing_packs = [(2000, "big"), (9, "medium"), (1, "single")] |
861 |
# rev count - 2010 -> 2x1000 + 1x10
|
|
862 |
pack_operations = packs.plan_autopack_combinations( |
|
863 |
existing_packs, [1000, 1000, 10]) |
|
864 |
self.assertEqual([], pack_operations) |
|
865 |
||
866 |
def test_plan_pack_operations_2010_combines_smallest_two(self): |
|
|
3711.4.1
by John Arbash Meinel
Fix bug #242510, when determining the autopack sequence, |
867 |
packs = self.get_packs() |
|
2592.3.85
by Robert Collins
Finish autopack corner cases. |
868 |
existing_packs = [(1999, "big"), (9, "medium"), (1, "single2"), |
869 |
(1, "single1")] |
|
870 |
# rev count - 2010 -> 2x1000 + 1x10 (3)
|
|
871 |
pack_operations = packs.plan_autopack_combinations( |
|
872 |
existing_packs, [1000, 1000, 10]) |
|
|
3711.4.2
by John Arbash Meinel
Change the logic to solve it in a different way. |
873 |
self.assertEqual([[2, ["single2", "single1"]]], pack_operations) |
|
2592.3.85
by Robert Collins
Finish autopack corner cases. |
874 |
|
|
3711.4.2
by John Arbash Meinel
Change the logic to solve it in a different way. |
875 |
def test_plan_pack_operations_creates_a_single_op(self): |
|
3711.4.1
by John Arbash Meinel
Fix bug #242510, when determining the autopack sequence, |
876 |
packs = self.get_packs() |
|
3711.4.2
by John Arbash Meinel
Change the logic to solve it in a different way. |
877 |
existing_packs = [(50, 'a'), (40, 'b'), (30, 'c'), (10, 'd'), |
878 |
(10, 'e'), (6, 'f'), (4, 'g')] |
|
879 |
# rev count 150 -> 1x100 and 5x10
|
|
880 |
# The two size 10 packs do not need to be touched. The 50, 40, 30 would
|
|
881 |
# be combined into a single 120 size pack, and the 6 & 4 would
|
|
882 |
# becombined into a size 10 pack. However, if we have to rewrite them,
|
|
883 |
# we save a pack file with no increased I/O by putting them into the
|
|
884 |
# same file.
|
|
885 |
distribution = packs.pack_distribution(150) |
|
|
3711.4.1
by John Arbash Meinel
Fix bug #242510, when determining the autopack sequence, |
886 |
pack_operations = packs.plan_autopack_combinations(existing_packs, |
|
3711.4.2
by John Arbash Meinel
Change the logic to solve it in a different way. |
887 |
distribution) |
888 |
self.assertEqual([[130, ['a', 'b', 'c', 'f', 'g']]], pack_operations) |
|
|
3711.4.1
by John Arbash Meinel
Fix bug #242510, when determining the autopack sequence, |
889 |
|
|
2592.3.173
by Robert Collins
Basic implementation of all_packs. |
890 |
def test_all_packs_none(self): |
891 |
format = self.get_format() |
|
892 |
tree = self.make_branch_and_tree('.', format=format) |
|
893 |
tree.lock_read() |
|
894 |
self.addCleanup(tree.unlock) |
|
|
2592.3.232
by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection |
895 |
packs = tree.branch.repository._pack_collection |
|
2592.3.173
by Robert Collins
Basic implementation of all_packs. |
896 |
packs.ensure_loaded() |
897 |
self.assertEqual([], packs.all_packs()) |
|
898 |
||
899 |
def test_all_packs_one(self): |
|
900 |
format = self.get_format() |
|
901 |
tree = self.make_branch_and_tree('.', format=format) |
|
902 |
tree.commit('start') |
|
903 |
tree.lock_read() |
|
904 |
self.addCleanup(tree.unlock) |
|
|
2592.3.232
by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection |
905 |
packs = tree.branch.repository._pack_collection |
|
2592.3.173
by Robert Collins
Basic implementation of all_packs. |
906 |
packs.ensure_loaded() |
|
2592.3.176
by Robert Collins
Various pack refactorings. |
907 |
self.assertEqual([ |
908 |
packs.get_pack_by_name(packs.names()[0])], |
|
909 |
packs.all_packs()) |
|
|
2592.3.173
by Robert Collins
Basic implementation of all_packs. |
910 |
|
911 |
def test_all_packs_two(self): |
|
912 |
format = self.get_format() |
|
913 |
tree = self.make_branch_and_tree('.', format=format) |
|
914 |
tree.commit('start') |
|
915 |
tree.commit('continue') |
|
916 |
tree.lock_read() |
|
917 |
self.addCleanup(tree.unlock) |
|
|
2592.3.232
by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection |
918 |
packs = tree.branch.repository._pack_collection |
|
2592.3.173
by Robert Collins
Basic implementation of all_packs. |
919 |
packs.ensure_loaded() |
920 |
self.assertEqual([ |
|
|
2592.3.176
by Robert Collins
Various pack refactorings. |
921 |
packs.get_pack_by_name(packs.names()[0]), |
922 |
packs.get_pack_by_name(packs.names()[1]), |
|
|
2592.3.173
by Robert Collins
Basic implementation of all_packs. |
923 |
], packs.all_packs()) |
924 |
||
|
2592.3.176
by Robert Collins
Various pack refactorings. |
925 |
def test_get_pack_by_name(self): |
926 |
format = self.get_format() |
|
927 |
tree = self.make_branch_and_tree('.', format=format) |
|
928 |
tree.commit('start') |
|
929 |
tree.lock_read() |
|
930 |
self.addCleanup(tree.unlock) |
|
|
2592.3.232
by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection |
931 |
packs = tree.branch.repository._pack_collection |
|
2592.3.176
by Robert Collins
Various pack refactorings. |
932 |
packs.ensure_loaded() |
933 |
name = packs.names()[0] |
|
934 |
pack_1 = packs.get_pack_by_name(name) |
|
935 |
# the pack should be correctly initialised
|
|
|
3517.4.5
by Martin Pool
Correct use of packs._names in test_get_pack_by_name |
936 |
sizes = packs._names[name] |
|
3221.12.4
by Robert Collins
Implement basic repository supporting external references. |
937 |
rev_index = GraphIndex(packs._index_transport, name + '.rix', sizes[0]) |
938 |
inv_index = GraphIndex(packs._index_transport, name + '.iix', sizes[1]) |
|
939 |
txt_index = GraphIndex(packs._index_transport, name + '.tix', sizes[2]) |
|
940 |
sig_index = GraphIndex(packs._index_transport, name + '.six', sizes[3]) |
|
|
2592.3.191
by Robert Collins
Give Pack responsibility for index naming, and two concrete classes - NewPack for new packs and ExistingPack for packs we read from disk. |
941 |
self.assertEqual(pack_repo.ExistingPack(packs._pack_transport, |
|
2592.3.219
by Robert Collins
Review feedback. |
942 |
name, rev_index, inv_index, txt_index, sig_index), pack_1) |
|
2592.3.176
by Robert Collins
Various pack refactorings. |
943 |
# and the same instance should be returned on successive calls.
|
944 |
self.assertTrue(pack_1 is packs.get_pack_by_name(name)) |
|
945 |
||
|
3789.1.2
by John Arbash Meinel
Add RepositoryPackCollection.reload_pack_names() |
946 |
def test_reload_pack_names_new_entry(self): |
|
3789.2.19
by John Arbash Meinel
Refactor to make the tests a bit simpler |
947 |
tree, r, packs, revs = self.make_packs_and_alt_repo() |
|
3789.1.2
by John Arbash Meinel
Add RepositoryPackCollection.reload_pack_names() |
948 |
names = packs.names() |
949 |
# Add a new pack file into the repository
|
|
|
3789.2.19
by John Arbash Meinel
Refactor to make the tests a bit simpler |
950 |
rev4 = tree.commit('four') |
|
3789.1.2
by John Arbash Meinel
Add RepositoryPackCollection.reload_pack_names() |
951 |
new_names = tree.branch.repository._pack_collection.names() |
952 |
new_name = set(new_names).difference(names) |
|
953 |
self.assertEqual(1, len(new_name)) |
|
954 |
new_name = new_name.pop() |
|
955 |
# The old collection hasn't noticed yet
|
|
956 |
self.assertEqual(names, packs.names()) |
|
|
3789.1.8
by John Arbash Meinel
Change the api of reload_pack_names(). |
957 |
self.assertTrue(packs.reload_pack_names()) |
|
3789.1.2
by John Arbash Meinel
Add RepositoryPackCollection.reload_pack_names() |
958 |
self.assertEqual(new_names, packs.names()) |
959 |
# And the repository can access the new revision
|
|
|
3789.2.19
by John Arbash Meinel
Refactor to make the tests a bit simpler |
960 |
self.assertEqual({rev4:(revs[-1],)}, r.get_parent_map([rev4])) |
|
3789.1.8
by John Arbash Meinel
Change the api of reload_pack_names(). |
961 |
self.assertFalse(packs.reload_pack_names()) |
|
3789.1.2
by John Arbash Meinel
Add RepositoryPackCollection.reload_pack_names() |
962 |
|
963 |
def test_reload_pack_names_added_and_removed(self): |
|
|
3789.2.19
by John Arbash Meinel
Refactor to make the tests a bit simpler |
964 |
tree, r, packs, revs = self.make_packs_and_alt_repo() |
|
3789.1.2
by John Arbash Meinel
Add RepositoryPackCollection.reload_pack_names() |
965 |
names = packs.names() |
966 |
# Now repack the whole thing
|
|
967 |
tree.branch.repository.pack() |
|
968 |
new_names = tree.branch.repository._pack_collection.names() |
|
969 |
# The other collection hasn't noticed yet
|
|
970 |
self.assertEqual(names, packs.names()) |
|
|
3789.1.8
by John Arbash Meinel
Change the api of reload_pack_names(). |
971 |
self.assertTrue(packs.reload_pack_names()) |
|
3789.1.2
by John Arbash Meinel
Add RepositoryPackCollection.reload_pack_names() |
972 |
self.assertEqual(new_names, packs.names()) |
|
3789.2.19
by John Arbash Meinel
Refactor to make the tests a bit simpler |
973 |
self.assertEqual({revs[-1]:(revs[-2],)}, r.get_parent_map([revs[-1]])) |
|
3789.1.8
by John Arbash Meinel
Change the api of reload_pack_names(). |
974 |
self.assertFalse(packs.reload_pack_names()) |
|
3789.1.2
by John Arbash Meinel
Add RepositoryPackCollection.reload_pack_names() |
975 |
|
|
3789.2.20
by John Arbash Meinel
The autopack code can now trigger itself to retry when _copy_revision_texts fails. |
976 |
def test_autopack_reloads_and_stops(self): |
977 |
tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True) |
|
978 |
# After we have determined what needs to be autopacked, trigger a
|
|
979 |
# full-pack via the other repo which will cause us to re-evaluate and
|
|
980 |
# decide we don't need to do anything
|
|
981 |
orig_execute = packs._execute_pack_operations |
|
982 |
def _munged_execute_pack_ops(*args, **kwargs): |
|
983 |
tree.branch.repository.pack() |
|
984 |
return orig_execute(*args, **kwargs) |
|
985 |
packs._execute_pack_operations = _munged_execute_pack_ops |
|
986 |
packs._max_pack_count = lambda x: 1 |
|
987 |
packs.pack_distribution = lambda x: [10] |
|
988 |
self.assertFalse(packs.autopack()) |
|
989 |
self.assertEqual(1, len(packs.names())) |
|
990 |
self.assertEqual(tree.branch.repository._pack_collection.names(), |
|
991 |
packs.names()) |
|
992 |
||
|
2592.3.173
by Robert Collins
Basic implementation of all_packs. |
993 |
|
994 |
class TestPack(TestCaseWithTransport): |
|
995 |
"""Tests for the Pack object.""" |
|
996 |
||
997 |
def assertCurrentlyEqual(self, left, right): |
|
998 |
self.assertTrue(left == right) |
|
999 |
self.assertTrue(right == left) |
|
1000 |
self.assertFalse(left != right) |
|
1001 |
self.assertFalse(right != left) |
|
1002 |
||
1003 |
def assertCurrentlyNotEqual(self, left, right): |
|
1004 |
self.assertFalse(left == right) |
|
1005 |
self.assertFalse(right == left) |
|
1006 |
self.assertTrue(left != right) |
|
1007 |
self.assertTrue(right != left) |
|
1008 |
||
1009 |
def test___eq____ne__(self): |
|
|
2592.3.191
by Robert Collins
Give Pack responsibility for index naming, and two concrete classes - NewPack for new packs and ExistingPack for packs we read from disk. |
1010 |
left = pack_repo.ExistingPack('', '', '', '', '', '') |
1011 |
right = pack_repo.ExistingPack('', '', '', '', '', '') |
|
|
2592.3.173
by Robert Collins
Basic implementation of all_packs. |
1012 |
self.assertCurrentlyEqual(left, right) |
1013 |
# change all attributes and ensure equality changes as we do.
|
|
1014 |
left.revision_index = 'a' |
|
1015 |
self.assertCurrentlyNotEqual(left, right) |
|
1016 |
right.revision_index = 'a' |
|
1017 |
self.assertCurrentlyEqual(left, right) |
|
1018 |
left.inventory_index = 'a' |
|
1019 |
self.assertCurrentlyNotEqual(left, right) |
|
1020 |
right.inventory_index = 'a' |
|
1021 |
self.assertCurrentlyEqual(left, right) |
|
1022 |
left.text_index = 'a' |
|
1023 |
self.assertCurrentlyNotEqual(left, right) |
|
1024 |
right.text_index = 'a' |
|
1025 |
self.assertCurrentlyEqual(left, right) |
|
1026 |
left.signature_index = 'a' |
|
1027 |
self.assertCurrentlyNotEqual(left, right) |
|
1028 |
right.signature_index = 'a' |
|
1029 |
self.assertCurrentlyEqual(left, right) |
|
1030 |
left.name = 'a' |
|
1031 |
self.assertCurrentlyNotEqual(left, right) |
|
1032 |
right.name = 'a' |
|
1033 |
self.assertCurrentlyEqual(left, right) |
|
1034 |
left.transport = 'a' |
|
1035 |
self.assertCurrentlyNotEqual(left, right) |
|
1036 |
right.transport = 'a' |
|
1037 |
self.assertCurrentlyEqual(left, right) |
|
|
2592.3.179
by Robert Collins
Generate the revision_index_map for packing during the core operation, from the pack objects. |
1038 |
|
1039 |
def test_file_name(self): |
|
|
2592.3.191
by Robert Collins
Give Pack responsibility for index naming, and two concrete classes - NewPack for new packs and ExistingPack for packs we read from disk. |
1040 |
pack = pack_repo.ExistingPack('', 'a_name', '', '', '', '') |
|
2592.3.179
by Robert Collins
Generate the revision_index_map for packing during the core operation, from the pack objects. |
1041 |
self.assertEqual('a_name.pack', pack.file_name()) |
|
2592.3.192
by Robert Collins
Move new revision index management to NewPack. |
1042 |
|
1043 |
||
1044 |
class TestNewPack(TestCaseWithTransport): |
|
1045 |
"""Tests for pack_repo.NewPack.""" |
|
1046 |
||
|
2592.3.193
by Robert Collins
Move hash tracking of new packs into NewPack. |
1047 |
def test_new_instance_attributes(self): |
|
2592.3.194
by Robert Collins
Output the revision index from NewPack.finish |
1048 |
upload_transport = self.get_transport('upload') |
1049 |
pack_transport = self.get_transport('pack') |
|
1050 |
index_transport = self.get_transport('index') |
|
1051 |
upload_transport.mkdir('.') |
|
|
3830.3.1
by Martin Pool
NewPack should be constructed from the PackCollection, rather than attributes of it |
1052 |
collection = pack_repo.RepositoryPackCollection(repo=None, |
1053 |
transport=self.get_transport('.'), |
|
1054 |
index_transport=index_transport, |
|
1055 |
upload_transport=upload_transport, |
|
1056 |
pack_transport=pack_transport, |
|
1057 |
index_builder_class=BTreeBuilder, |
|
|
3735.1.1
by Robert Collins
Add development2 formats using BTree indices. |
1058 |
index_class=BTreeGraphIndex) |
|
3830.3.1
by Martin Pool
NewPack should be constructed from the PackCollection, rather than attributes of it |
1059 |
pack = pack_repo.NewPack(collection) |
|
3735.1.1
by Robert Collins
Add development2 formats using BTree indices. |
1060 |
self.assertIsInstance(pack.revision_index, BTreeBuilder) |
1061 |
self.assertIsInstance(pack.inventory_index, BTreeBuilder) |
|
|
2929.3.5
by Vincent Ladeuil
New files, same warnings, same fixes. |
1062 |
self.assertIsInstance(pack._hash, type(osutils.md5())) |
|
2592.3.194
by Robert Collins
Output the revision index from NewPack.finish |
1063 |
self.assertTrue(pack.upload_transport is upload_transport) |
1064 |
self.assertTrue(pack.index_transport is index_transport) |
|
1065 |
self.assertTrue(pack.pack_transport is pack_transport) |
|
1066 |
self.assertEqual(None, pack.index_sizes) |
|
1067 |
self.assertEqual(20, len(pack.random_name)) |
|
1068 |
self.assertIsInstance(pack.random_name, str) |
|
1069 |
self.assertIsInstance(pack.start_time, float) |
|
|
2951.1.2
by Robert Collins
Partial refactoring of pack_repo to create a Packer object for packing. |
1070 |
|
1071 |
||
1072 |
class TestPacker(TestCaseWithTransport): |
|
1073 |
"""Tests for the packs repository Packer class.""" |
|
|
2951.1.10
by Robert Collins
Peer review feedback with Ian. |
1074 |
|
|
3824.2.4
by John Arbash Meinel
Add a test that ensures the pack ordering changes as part of calling .pack() |
1075 |
def test_pack_optimizes_pack_order(self): |
1076 |
builder = self.make_branch_builder('.') |
|
1077 |
builder.start_series() |
|
1078 |
builder.build_snapshot('A', None, [ |
|
1079 |
('add', ('', 'root-id', 'directory', None)), |
|
1080 |
('add', ('f', 'f-id', 'file', 'content\n'))]) |
|
1081 |
builder.build_snapshot('B', ['A'], |
|
1082 |
[('modify', ('f-id', 'new-content\n'))]) |
|
1083 |
builder.build_snapshot('C', ['B'], |
|
1084 |
[('modify', ('f-id', 'third-content\n'))]) |
|
1085 |
builder.build_snapshot('D', ['C'], |
|
1086 |
[('modify', ('f-id', 'fourth-content\n'))]) |
|
1087 |
b = builder.get_branch() |
|
1088 |
b.lock_read() |
|
1089 |
builder.finish_series() |
|
1090 |
self.addCleanup(b.unlock) |
|
1091 |
# At this point, we should have 4 pack files available
|
|
1092 |
# Because of how they were built, they correspond to
|
|
1093 |
# ['D', 'C', 'B', 'A']
|
|
1094 |
packs = b.repository._pack_collection.packs |
|
1095 |
packer = pack_repo.Packer(b.repository._pack_collection, |
|
1096 |
packs, 'testing', |
|
1097 |
revision_ids=['B', 'C']) |
|
1098 |
# Now, when we are copying the B & C revisions, their pack files should
|
|
1099 |
# be moved to the front of the stack
|
|
|
3824.2.5
by Andrew Bennetts
Minor tweaks to comments etc. |
1100 |
# The new ordering moves B & C to the front of the .packs attribute,
|
1101 |
# and leaves the others in the original order.
|
|
|
3824.2.4
by John Arbash Meinel
Add a test that ensures the pack ordering changes as part of calling .pack() |
1102 |
new_packs = [packs[1], packs[2], packs[0], packs[3]] |
1103 |
new_pack = packer.pack() |
|
1104 |
self.assertEqual(new_packs, packer.packs) |
|
|
3146.6.1
by Aaron Bentley
InterDifferingSerializer shows a progress bar |
1105 |
|
1106 |
||
|
3777.5.4
by John Arbash Meinel
OptimisingPacker now sets the optimize flags for the indexes being built. |
1107 |
class TestOptimisingPacker(TestCaseWithTransport): |
1108 |
"""Tests for the OptimisingPacker class.""" |
|
1109 |
||
1110 |
def get_pack_collection(self): |
|
1111 |
repo = self.make_repository('.') |
|
1112 |
return repo._pack_collection |
|
1113 |
||
1114 |
def test_open_pack_will_optimise(self): |
|
1115 |
packer = pack_repo.OptimisingPacker(self.get_pack_collection(), |
|
1116 |
[], '.test') |
|
1117 |
new_pack = packer.open_pack() |
|
1118 |
self.assertIsInstance(new_pack, pack_repo.NewPack) |
|
1119 |
self.assertTrue(new_pack.revision_index._optimize_for_size) |
|
1120 |
self.assertTrue(new_pack.inventory_index._optimize_for_size) |
|
1121 |
self.assertTrue(new_pack.text_index._optimize_for_size) |
|
1122 |
self.assertTrue(new_pack.signature_index._optimize_for_size) |
|
1123 |
||
1124 |
||
|
3146.6.1
by Aaron Bentley
InterDifferingSerializer shows a progress bar |
1125 |
class TestInterDifferingSerializer(TestCaseWithTransport): |
1126 |
||
1127 |
def test_progress_bar(self): |
|
1128 |
tree = self.make_branch_and_tree('tree') |
|
1129 |
tree.commit('rev1', rev_id='rev-1') |
|
1130 |
tree.commit('rev2', rev_id='rev-2') |
|
1131 |
tree.commit('rev3', rev_id='rev-3') |
|
1132 |
repo = self.make_repository('repo') |
|
1133 |
inter_repo = repository.InterDifferingSerializer( |
|
1134 |
tree.branch.repository, repo) |
|
1135 |
pb = progress.InstrumentedProgress(to_file=StringIO()) |
|
1136 |
pb.never_throttle = True |
|
1137 |
inter_repo.fetch('rev-1', pb) |
|
1138 |
self.assertEqual('Transferring revisions', pb.last_msg) |
|
1139 |
self.assertEqual(1, pb.last_cnt) |
|
1140 |
self.assertEqual(1, pb.last_total) |
|
1141 |
inter_repo.fetch('rev-3', pb) |
|
1142 |
self.assertEqual(2, pb.last_cnt) |
|
1143 |
self.assertEqual(2, pb.last_total) |