/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4110.2.26 by Martin Pool
Remove outdated progress bar test
1
# Copyright (C) 2006, 2007, 2008, 2009 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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
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
                           )
4360.4.3 by John Arbash Meinel
Introduce a KnitPackStreamSource which is used when
34
from bzrlib import (
35
    graph,
36
    tests,
37
    )
3735.4.1 by Andrew Bennetts
Add _find_revision_outside_set.
38
from bzrlib.branchbuilder import BranchBuilder
3735.1.1 by Robert Collins
Add development2 formats using BTree indices.
39
from bzrlib.btree_index import BTreeBuilder, BTreeGraphIndex
2592.3.192 by Robert Collins
Move new revision index management to NewPack.
40
from bzrlib.index import GraphIndex, InMemoryGraphIndex
2241.1.1 by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary
41
from bzrlib.repository import RepositoryFormat
2535.3.41 by Andrew Bennetts
Add tests for InterRemoteToOther.is_compatible.
42
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.
43
from bzrlib.tests import (
44
    TestCase,
45
    TestCaseWithTransport,
3446.2.1 by Martin Pool
Failure to delete an obsolete pack file should not be fatal.
46
    TestSkipped,
2670.3.5 by Andrew Bennetts
Remove get_stream_as_bytes from KnitVersionedFile's API, make it a function in knitrepo.py instead.
47
    test_knit,
48
    )
3446.2.1 by Martin Pool
Failure to delete an obsolete pack file should not be fatal.
49
from bzrlib.transport import (
50
    fakenfs,
51
    get_transport,
52
    )
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
53
from bzrlib.transport.memory import MemoryServer
2241.1.1 by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary
54
from bzrlib import (
2694.5.4 by Jelmer Vernooij
Move bzrlib.util.bencode to bzrlib._bencode_py.
55
    bencode,
2535.3.41 by Andrew Bennetts
Add tests for InterRemoteToOther.is_compatible.
56
    bzrdir,
57
    errors,
2535.3.57 by Andrew Bennetts
Perform some sanity checking of data streams rather than blindly inserting them into our repository.
58
    inventory,
2929.3.5 by Vincent Ladeuil
New files, same warnings, same fixes.
59
    osutils,
3146.6.1 by Aaron Bentley
InterDifferingSerializer shows a progress bar
60
    progress,
2241.1.1 by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary
61
    repository,
2535.3.57 by Andrew Bennetts
Perform some sanity checking of data streams rather than blindly inserting them into our repository.
62
    revision as _mod_revision,
2535.3.41 by Andrew Bennetts
Add tests for InterRemoteToOther.is_compatible.
63
    symbol_versioning,
2241.1.1 by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary
64
    upgrade,
65
    workingtree,
66
    )
3735.42.5 by John Arbash Meinel
Change the tests so we now just use a direct test that _get_source is
67
from bzrlib.repofmt import (
68
    groupcompress_repo,
69
    knitrepo,
70
    pack_repo,
71
    weaverepo,
72
    )
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
73
74
75
class TestDefaultFormat(TestCase):
76
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
77
    def test_get_set_default_format(self):
2204.5.3 by Aaron Bentley
zap old repository default handling
78
        old_default = bzrdir.format_registry.get('default')
79
        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.
80
        old_format = repository.RepositoryFormat.get_default_format()
1910.2.33 by Aaron Bentley
Fix default format test
81
        self.assertTrue(isinstance(old_format, private_default))
2204.5.3 by Aaron Bentley
zap old repository default handling
82
        def make_sample_bzrdir():
83
            my_bzrdir = bzrdir.BzrDirMetaFormat1()
84
            my_bzrdir.repository_format = SampleRepositoryFormat()
85
            return my_bzrdir
86
        bzrdir.format_registry.remove('default')
87
        bzrdir.format_registry.register('sample', make_sample_bzrdir, '')
88
        bzrdir.format_registry.set_default('sample')
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
89
        # creating a repository should now create an instrumented dir.
90
        try:
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
91
            # the default branch format is used by the meta dir format
92
            # which is not the default bzrdir format at this point
1685.1.63 by Martin Pool
Small Transport fixups
93
            dir = bzrdir.BzrDirMetaFormat1().initialize('memory:///')
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
94
            result = dir.create_repository()
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
95
            self.assertEqual(result, 'A bzr repository dir')
2241.1.1 by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary
96
        finally:
2204.5.3 by Aaron Bentley
zap old repository default handling
97
            bzrdir.format_registry.remove('default')
2363.5.14 by Aaron Bentley
Prevent repository.get_set_default_format from corrupting inventory
98
            bzrdir.format_registry.remove('sample')
2204.5.3 by Aaron Bentley
zap old repository default handling
99
            bzrdir.format_registry.register('default', old_default, '')
100
        self.assertIsInstance(repository.RepositoryFormat.get_default_format(),
101
                              old_format.__class__)
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
102
103
104
class SampleRepositoryFormat(repository.RepositoryFormat):
105
    """A sample format
106
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
107
    this format is initializable, unsupported to aid in testing the
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
108
    open and open(unsupported=True) routines.
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
109
    """
110
111
    def get_format_string(self):
112
        """See RepositoryFormat.get_format_string()."""
113
        return "Sample .bzr repository format."
114
1534.6.1 by Robert Collins
allow API creation of shared repositories
115
    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.
116
        """Initialize a repository in a BzrDir"""
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
117
        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.
118
        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.
119
        return 'A bzr repository dir'
120
121
    def is_supported(self):
122
        return False
123
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
124
    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.
125
        return "opened repository."
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
126
127
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
128
class TestRepositoryFormat(TestCaseWithTransport):
129
    """Tests for the Repository format detection used by the bzr meta dir facility.BzrBranchFormat facility."""
130
131
    def test_find_format(self):
132
        # is the right format object found for a repository?
133
        # create a branch with a few known format objects.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
134
        # this is not quite the same as
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
135
        self.build_tree(["foo/", "bar/"])
136
        def check_format(format, url):
137
            dir = format._matchingbzrdir.initialize(url)
138
            format.initialize(dir)
139
            t = get_transport(url)
140
            found_format = repository.RepositoryFormat.find_format(dir)
141
            self.failUnless(isinstance(found_format, format.__class__))
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
142
        check_format(weaverepo.RepositoryFormat7(), "bar")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
143
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
144
    def test_find_format_no_repository(self):
145
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
146
        self.assertRaises(errors.NoRepositoryPresent,
147
                          repository.RepositoryFormat.find_format,
148
                          dir)
149
150
    def test_find_format_unknown_format(self):
151
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
152
        SampleRepositoryFormat().initialize(dir)
153
        self.assertRaises(UnknownFormatError,
154
                          repository.RepositoryFormat.find_format,
155
                          dir)
156
157
    def test_register_unregister_format(self):
158
        format = SampleRepositoryFormat()
159
        # make a control dir
160
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
161
        # make a repo
162
        format.initialize(dir)
163
        # register a format for it.
164
        repository.RepositoryFormat.register_format(format)
165
        # which repository.Open will refuse (not supported)
166
        self.assertRaises(UnsupportedFormatError, repository.Repository.open, self.get_url())
167
        # but open(unsupported) will work
168
        self.assertEqual(format.open(dir), "opened repository.")
169
        # unregister the format
170
        repository.RepositoryFormat.unregister_format(format)
171
172
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
173
class TestFormat6(TestCaseWithTransport):
174
3565.3.1 by Robert Collins
* The generic fetch code now uses two attributes on Repository objects
175
    def test_attribute__fetch_order(self):
176
        """Weaves need topological data insertion."""
177
        control = bzrdir.BzrDirFormat6().initialize(self.get_url())
178
        repo = weaverepo.RepositoryFormat6().initialize(control)
4053.1.4 by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat.
179
        self.assertEqual('topological', repo._format._fetch_order)
3565.3.1 by Robert Collins
* The generic fetch code now uses two attributes on Repository objects
180
181
    def test_attribute__fetch_uses_deltas(self):
182
        """Weaves do not reuse deltas."""
183
        control = bzrdir.BzrDirFormat6().initialize(self.get_url())
184
        repo = weaverepo.RepositoryFormat6().initialize(control)
4053.1.4 by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat.
185
        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
186
3565.3.4 by Robert Collins
Defer decision to reconcile to the repository being fetched into.
187
    def test_attribute__fetch_reconcile(self):
188
        """Weave repositories need a reconcile after fetch."""
189
        control = bzrdir.BzrDirFormat6().initialize(self.get_url())
190
        repo = weaverepo.RepositoryFormat6().initialize(control)
4053.1.4 by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat.
191
        self.assertEqual(True, repo._format._fetch_reconcile)
3565.3.4 by Robert Collins
Defer decision to reconcile to the repository being fetched into.
192
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
193
    def test_no_ancestry_weave(self):
194
        control = bzrdir.BzrDirFormat6().initialize(self.get_url())
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
195
        repo = weaverepo.RepositoryFormat6().initialize(control)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
196
        # We no longer need to create the ancestry.weave file
197
        # since it is *never* used.
198
        self.assertRaises(NoSuchFile,
199
                          control.transport.get,
200
                          'ancestry.weave')
201
3221.3.1 by Robert Collins
* Repository formats have a new supported-feature attribute
202
    def test_supports_external_lookups(self):
203
        control = bzrdir.BzrDirFormat6().initialize(self.get_url())
204
        repo = weaverepo.RepositoryFormat6().initialize(control)
205
        self.assertFalse(repo._format.supports_external_lookups)
206
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
207
208
class TestFormat7(TestCaseWithTransport):
3565.3.1 by Robert Collins
* The generic fetch code now uses two attributes on Repository objects
209
210
    def test_attribute__fetch_order(self):
211
        """Weaves need topological data insertion."""
212
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
213
        repo = weaverepo.RepositoryFormat7().initialize(control)
4053.1.4 by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat.
214
        self.assertEqual('topological', repo._format._fetch_order)
3565.3.1 by Robert Collins
* The generic fetch code now uses two attributes on Repository objects
215
216
    def test_attribute__fetch_uses_deltas(self):
217
        """Weaves do not reuse deltas."""
218
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
219
        repo = weaverepo.RepositoryFormat7().initialize(control)
4053.1.4 by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat.
220
        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
221
3565.3.4 by Robert Collins
Defer decision to reconcile to the repository being fetched into.
222
    def test_attribute__fetch_reconcile(self):
223
        """Weave repositories need a reconcile after fetch."""
224
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
225
        repo = weaverepo.RepositoryFormat7().initialize(control)
4053.1.4 by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat.
226
        self.assertEqual(True, repo._format._fetch_reconcile)
3565.3.4 by Robert Collins
Defer decision to reconcile to the repository being fetched into.
227
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
228
    def test_disk_layout(self):
229
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
230
        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.
231
        # in case of side effects of locking.
232
        repo.lock_write()
233
        repo.unlock()
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
234
        # we want:
235
        # format 'Bazaar-NG Repository format 7'
236
        # lock ''
237
        # inventory.weave == empty_weave
238
        # empty revision-store directory
239
        # empty weaves directory
240
        t = control.get_repository_transport(None)
241
        self.assertEqualDiff('Bazaar-NG Repository format 7',
242
                             t.get('format').read())
243
        self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
244
        self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
245
        self.assertEqualDiff('# bzr weave file v5\n'
246
                             'w\n'
247
                             'W\n',
248
                             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.
249
        # Creating a file with id Foo:Bar results in a non-escaped file name on
250
        # disk.
251
        control.create_branch()
252
        tree = control.create_workingtree()
253
        tree.add(['foo'], ['Foo:Bar'], ['file'])
254
        tree.put_file_bytes_non_atomic('Foo:Bar', 'content\n')
255
        tree.commit('first post', rev_id='first')
256
        self.assertEqualDiff(
257
            '# bzr weave file v5\n'
258
            'i\n'
259
            '1 7fe70820e08a1aac0ef224d9c66ab66831cc4ab1\n'
260
            'n first\n'
261
            '\n'
262
            'w\n'
263
            '{ 0\n'
264
            '. content\n'
265
            '}\n'
266
            'W\n',
267
            t.get('weaves/74/Foo%3ABar.weave').read())
1534.6.1 by Robert Collins
allow API creation of shared repositories
268
269
    def test_shared_disk_layout(self):
270
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
271
        repo = weaverepo.RepositoryFormat7().initialize(control, shared=True)
1534.6.1 by Robert Collins
allow API creation of shared repositories
272
        # we want:
273
        # format 'Bazaar-NG Repository format 7'
274
        # inventory.weave == empty_weave
275
        # empty revision-store directory
276
        # empty weaves directory
277
        # a 'shared-storage' marker file.
1553.5.49 by Martin Pool
Use LockDirs for repo format 7
278
        # lock is not present when unlocked
1534.6.1 by Robert Collins
allow API creation of shared repositories
279
        t = control.get_repository_transport(None)
280
        self.assertEqualDiff('Bazaar-NG Repository format 7',
281
                             t.get('format').read())
282
        self.assertEqualDiff('', t.get('shared-storage').read())
283
        self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
284
        self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
285
        self.assertEqualDiff('# bzr weave file v5\n'
286
                             'w\n'
287
                             'W\n',
288
                             t.get('inventory.weave').read())
1553.5.49 by Martin Pool
Use LockDirs for repo format 7
289
        self.assertFalse(t.has('branch-lock'))
290
1553.5.56 by Martin Pool
Format 7 repo now uses LockDir!
291
    def test_creates_lockdir(self):
1553.5.49 by Martin Pool
Use LockDirs for repo format 7
292
        """Make sure it appears to be controlled by a LockDir existence"""
293
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
294
        repo = weaverepo.RepositoryFormat7().initialize(control, shared=True)
1553.5.49 by Martin Pool
Use LockDirs for repo format 7
295
        t = control.get_repository_transport(None)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
296
        # TODO: Should check there is a 'lock' toplevel directory,
1553.5.58 by Martin Pool
Change LockDirs to format "lock-name/held/info"
297
        # regardless of contents
298
        self.assertFalse(t.has('lock/held/info'))
1553.5.49 by Martin Pool
Use LockDirs for repo format 7
299
        repo.lock_write()
1658.1.4 by Martin Pool
Quieten warning from TestFormat7.test_creates_lockdir about failing to unlock
300
        try:
301
            self.assertTrue(t.has('lock/held/info'))
302
        finally:
303
            # unlock so we don't get a warning about failing to do so
304
            repo.unlock()
1553.5.56 by Martin Pool
Format 7 repo now uses LockDir!
305
306
    def test_uses_lockdir(self):
307
        """repo format 7 actually locks on lockdir"""
308
        base_url = self.get_url()
309
        control = bzrdir.BzrDirMetaFormat1().initialize(base_url)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
310
        repo = weaverepo.RepositoryFormat7().initialize(control, shared=True)
1553.5.56 by Martin Pool
Format 7 repo now uses LockDir!
311
        t = control.get_repository_transport(None)
312
        repo.lock_write()
313
        repo.unlock()
314
        del repo
315
        # make sure the same lock is created by opening it
316
        repo = repository.Repository.open(base_url)
317
        repo.lock_write()
1553.5.58 by Martin Pool
Change LockDirs to format "lock-name/held/info"
318
        self.assertTrue(t.has('lock/held/info'))
1553.5.56 by Martin Pool
Format 7 repo now uses LockDir!
319
        repo.unlock()
1553.5.58 by Martin Pool
Change LockDirs to format "lock-name/held/info"
320
        self.assertFalse(t.has('lock/held/info'))
1534.6.5 by Robert Collins
Cloning of repos preserves shared and make-working-tree attributes.
321
322
    def test_shared_no_tree_disk_layout(self):
323
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
324
        repo = weaverepo.RepositoryFormat7().initialize(control, shared=True)
1534.6.5 by Robert Collins
Cloning of repos preserves shared and make-working-tree attributes.
325
        repo.set_make_working_trees(False)
326
        # we want:
327
        # format 'Bazaar-NG Repository format 7'
328
        # lock ''
329
        # inventory.weave == empty_weave
330
        # empty revision-store directory
331
        # empty weaves directory
332
        # a 'shared-storage' marker file.
333
        t = control.get_repository_transport(None)
334
        self.assertEqualDiff('Bazaar-NG Repository format 7',
335
                             t.get('format').read())
1553.5.56 by Martin Pool
Format 7 repo now uses LockDir!
336
        ## self.assertEqualDiff('', t.get('lock').read())
1534.6.5 by Robert Collins
Cloning of repos preserves shared and make-working-tree attributes.
337
        self.assertEqualDiff('', t.get('shared-storage').read())
338
        self.assertEqualDiff('', t.get('no-working-trees').read())
339
        repo.set_make_working_trees(True)
340
        self.assertFalse(t.has('no-working-trees'))
341
        self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
342
        self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
343
        self.assertEqualDiff('# bzr weave file v5\n'
344
                             'w\n'
345
                             'W\n',
346
                             t.get('inventory.weave').read())
1534.1.27 by Robert Collins
Start InterRepository with InterRepository.get.
347
3221.3.1 by Robert Collins
* Repository formats have a new supported-feature attribute
348
    def test_supports_external_lookups(self):
349
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
350
        repo = weaverepo.RepositoryFormat7().initialize(control)
351
        self.assertFalse(repo._format.supports_external_lookups)
352
1534.1.27 by Robert Collins
Start InterRepository with InterRepository.get.
353
1556.1.3 by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids
354
class TestFormatKnit1(TestCaseWithTransport):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
355
3565.3.1 by Robert Collins
* The generic fetch code now uses two attributes on Repository objects
356
    def test_attribute__fetch_order(self):
357
        """Knits need topological data insertion."""
358
        repo = self.make_repository('.',
359
                format=bzrdir.format_registry.get('knit')())
4053.1.4 by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat.
360
        self.assertEqual('topological', repo._format._fetch_order)
3565.3.1 by Robert Collins
* The generic fetch code now uses two attributes on Repository objects
361
362
    def test_attribute__fetch_uses_deltas(self):
363
        """Knits reuse deltas."""
364
        repo = self.make_repository('.',
365
                format=bzrdir.format_registry.get('knit')())
4053.1.4 by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat.
366
        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
367
1556.1.3 by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids
368
    def test_disk_layout(self):
369
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
370
        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
371
        # in case of side effects of locking.
372
        repo.lock_write()
373
        repo.unlock()
374
        # we want:
375
        # format 'Bazaar-NG Knit Repository Format 1'
1553.5.62 by Martin Pool
Add tests that MetaDir repositories use LockDirs
376
        # 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
377
        # inventory.weave == empty_weave
378
        # empty revision-store directory
379
        # empty weaves directory
380
        t = control.get_repository_transport(None)
381
        self.assertEqualDiff('Bazaar-NG Knit Repository Format 1',
382
                             t.get('format').read())
1553.5.57 by Martin Pool
[merge] sync from bzr.dev
383
        # XXX: no locks left when unlocked at the moment
384
        # 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
385
        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.
386
        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.
387
        # Check per-file knits.
388
        branch = control.create_branch()
389
        tree = control.create_workingtree()
390
        tree.add(['foo'], ['Nasty-IdC:'], ['file'])
391
        tree.put_file_bytes_non_atomic('Nasty-IdC:', '')
392
        tree.commit('1st post', rev_id='foo')
393
        self.assertHasKnit(t, 'knits/e8/%254easty-%2549d%2543%253a',
394
            '\nfoo fulltext 0 81  :')
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
395
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.
396
    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.
397
        """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.
398
        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.
399
                             t.get(knit_name + '.kndx').read())
400
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
401
    def check_knits(self, t):
402
        """check knit content for a repository."""
1654.1.3 by Robert Collins
Refactor repository knit tests slightly to remove duplication - add a assertHasKnit method.
403
        self.assertHasKnit(t, 'inventory')
404
        self.assertHasKnit(t, 'revisions')
405
        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
406
407
    def test_shared_disk_layout(self):
408
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
409
        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
410
        # we want:
411
        # format 'Bazaar-NG Knit Repository Format 1'
1553.5.62 by Martin Pool
Add tests that MetaDir repositories use LockDirs
412
        # 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
413
        # inventory.weave == empty_weave
414
        # empty revision-store directory
415
        # empty weaves directory
416
        # a 'shared-storage' marker file.
417
        t = control.get_repository_transport(None)
418
        self.assertEqualDiff('Bazaar-NG Knit Repository Format 1',
419
                             t.get('format').read())
1553.5.57 by Martin Pool
[merge] sync from bzr.dev
420
        # XXX: no locks left when unlocked at the moment
421
        # 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
422
        self.assertEqualDiff('', t.get('shared-storage').read())
423
        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.
424
        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
425
426
    def test_shared_no_tree_disk_layout(self):
427
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
428
        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
429
        repo.set_make_working_trees(False)
430
        # we want:
431
        # format 'Bazaar-NG Knit Repository Format 1'
432
        # lock ''
433
        # inventory.weave == empty_weave
434
        # empty revision-store directory
435
        # empty weaves directory
436
        # a 'shared-storage' marker file.
437
        t = control.get_repository_transport(None)
438
        self.assertEqualDiff('Bazaar-NG Knit Repository Format 1',
439
                             t.get('format').read())
1553.5.57 by Martin Pool
[merge] sync from bzr.dev
440
        # XXX: no locks left when unlocked at the moment
441
        # 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
442
        self.assertEqualDiff('', t.get('shared-storage').read())
443
        self.assertEqualDiff('', t.get('no-working-trees').read())
444
        repo.set_make_working_trees(True)
445
        self.assertFalse(t.has('no-working-trees'))
446
        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.
447
        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
448
2917.2.1 by John Arbash Meinel
Fix bug #152360. The xml5 serializer should be using
449
    def test_deserialise_sets_root_revision(self):
450
        """We must have a inventory.root.revision
451
452
        Old versions of the XML5 serializer did not set the revision_id for
453
        the whole inventory. So we grab the one from the expected text. Which
454
        is valid when the api is not being abused.
455
        """
456
        repo = self.make_repository('.',
457
                format=bzrdir.format_registry.get('knit')())
458
        inv_xml = '<inventory format="5">\n</inventory>\n'
459
        inv = repo.deserialise_inventory('test-rev-id', inv_xml)
460
        self.assertEqual('test-rev-id', inv.root.revision)
461
462
    def test_deserialise_uses_global_revision_id(self):
463
        """If it is set, then we re-use the global revision id"""
464
        repo = self.make_repository('.',
465
                format=bzrdir.format_registry.get('knit')())
466
        inv_xml = ('<inventory format="5" revision_id="other-rev-id">\n'
467
                   '</inventory>\n')
468
        # Arguably, the deserialise_inventory should detect a mismatch, and
469
        # raise an error, rather than silently using one revision_id over the
470
        # 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.
471
        self.assertRaises(AssertionError, repo.deserialise_inventory,
472
            'test-rev-id', inv_xml)
473
        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
474
        self.assertEqual('other-rev-id', inv.root.revision)
475
3221.3.1 by Robert Collins
* Repository formats have a new supported-feature attribute
476
    def test_supports_external_lookups(self):
477
        repo = self.make_repository('.',
478
                format=bzrdir.format_registry.get('knit')())
479
        self.assertFalse(repo._format.supports_external_lookups)
480
2535.3.53 by Andrew Bennetts
Remove get_stream_as_bytes from KnitVersionedFile's API, make it a function in knitrepo.py instead.
481
2305.2.3 by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures.
482
class DummyRepository(object):
483
    """A dummy repository for testing."""
484
3452.2.11 by Andrew Bennetts
Merge thread.
485
    _format = None
2305.2.3 by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures.
486
    _serializer = None
487
488
    def supports_rich_root(self):
489
        return False
490
3709.5.10 by Andrew Bennetts
Fix test failure caused by missing attributes on DummyRepository.
491
    def get_graph(self):
492
        raise NotImplementedError
493
494
    def get_parent_map(self, revision_ids):
495
        raise NotImplementedError
496
2305.2.3 by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures.
497
498
class InterDummy(repository.InterRepository):
499
    """An inter-repository optimised code path for DummyRepository.
500
501
    This is for use during testing where we use DummyRepository as repositories
1534.1.28 by Robert Collins
Allow for optimised InterRepository selection.
502
    so that none of the default regsitered inter-repository classes will
2818.4.2 by Robert Collins
Review feedback.
503
    MATCH.
1534.1.28 by Robert Collins
Allow for optimised InterRepository selection.
504
    """
505
506
    @staticmethod
507
    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.
508
        """InterDummy is compatible with DummyRepository."""
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
509
        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.
510
            isinstance(repo_target, DummyRepository))
1534.1.28 by Robert Collins
Allow for optimised InterRepository selection.
511
512
1534.1.27 by Robert Collins
Start InterRepository with InterRepository.get.
513
class TestInterRepository(TestCaseWithTransport):
514
515
    def test_get_default_inter_repository(self):
516
        # test that the InterRepository.get(repo_a, repo_b) probes
517
        # for a inter_repo class where is_compatible(repo_a, repo_b) returns
518
        # true and returns a default inter_repo otherwise.
519
        # This also tests that the default registered optimised interrepository
520
        # classes do not barf inappropriately when a surprising repository type
521
        # 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.
522
        dummy_a = DummyRepository()
523
        dummy_b = DummyRepository()
1534.1.28 by Robert Collins
Allow for optimised InterRepository selection.
524
        self.assertGetsDefaultInterRepository(dummy_a, dummy_b)
525
526
    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.
527
        """Asserts that InterRepository.get(repo_a, repo_b) -> the default.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
528
2305.2.3 by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures.
529
        The effective default is now InterSameDataRepository because there is
530
        no actual sane default in the presence of incompatible data models.
531
        """
1534.1.28 by Robert Collins
Allow for optimised InterRepository selection.
532
        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.
533
        self.assertEqual(repository.InterSameDataRepository,
1534.1.27 by Robert Collins
Start InterRepository with InterRepository.get.
534
                         inter_repo.__class__)
1534.1.28 by Robert Collins
Allow for optimised InterRepository selection.
535
        self.assertEqual(repo_a, inter_repo.source)
536
        self.assertEqual(repo_b, inter_repo.target)
537
538
    def test_register_inter_repository_class(self):
539
        # test that a optimised code path provider - a
540
        # InterRepository subclass can be registered and unregistered
541
        # and that it is correctly selected when given a repository
542
        # pair that it returns true on for the is_compatible static method
543
        # check
2305.2.3 by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures.
544
        dummy_a = DummyRepository()
545
        dummy_b = DummyRepository()
546
        repo = self.make_repository('.')
547
        # hack dummies to look like repo somewhat.
548
        dummy_a._serializer = repo._serializer
549
        dummy_b._serializer = repo._serializer
550
        repository.InterRepository.register_optimiser(InterDummy)
1534.1.28 by Robert Collins
Allow for optimised InterRepository selection.
551
        try:
2305.2.3 by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures.
552
            # we should get the default for something InterDummy returns False
1534.1.28 by Robert Collins
Allow for optimised InterRepository selection.
553
            # to
2305.2.3 by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures.
554
            self.assertFalse(InterDummy.is_compatible(dummy_a, repo))
555
            self.assertGetsDefaultInterRepository(dummy_a, repo)
556
            # and we should get an InterDummy for a pair it 'likes'
557
            self.assertTrue(InterDummy.is_compatible(dummy_a, dummy_b))
1534.1.28 by Robert Collins
Allow for optimised InterRepository selection.
558
            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.
559
            self.assertEqual(InterDummy, inter_repo.__class__)
1534.1.28 by Robert Collins
Allow for optimised InterRepository selection.
560
            self.assertEqual(dummy_a, inter_repo.source)
561
            self.assertEqual(dummy_b, inter_repo.target)
562
        finally:
2305.2.3 by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures.
563
            repository.InterRepository.unregister_optimiser(InterDummy)
1534.1.28 by Robert Collins
Allow for optimised InterRepository selection.
564
        # now we should get the default InterRepository object again.
565
        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.
566
2241.1.17 by Martin Pool
Restore old InterWeave tests
567
568
class TestInterWeaveRepo(TestCaseWithTransport):
569
570
    def test_is_compatible_and_registered(self):
571
        # InterWeaveRepo is compatible when either side
572
        # is a format 5/6/7 branch
2241.1.20 by mbp at sourcefrog
update tests for new locations of weave repos
573
        from bzrlib.repofmt import knitrepo, weaverepo
574
        formats = [weaverepo.RepositoryFormat5(),
575
                   weaverepo.RepositoryFormat6(),
576
                   weaverepo.RepositoryFormat7()]
577
        incompatible_formats = [weaverepo.RepositoryFormat4(),
578
                                knitrepo.RepositoryFormatKnit1(),
2241.1.17 by Martin Pool
Restore old InterWeave tests
579
                                ]
580
        repo_a = self.make_repository('a')
581
        repo_b = self.make_repository('b')
582
        is_compatible = repository.InterWeaveRepo.is_compatible
583
        for source in incompatible_formats:
584
            # force incompatible left then right
585
            repo_a._format = source
586
            repo_b._format = formats[0]
587
            self.assertFalse(is_compatible(repo_a, repo_b))
588
            self.assertFalse(is_compatible(repo_b, repo_a))
589
        for source in formats:
590
            repo_a._format = source
591
            for target in formats:
592
                repo_b._format = target
593
                self.assertTrue(is_compatible(repo_a, repo_b))
594
        self.assertEqual(repository.InterWeaveRepo,
595
                         repository.InterRepository.get(repo_a,
596
                                                        repo_b).__class__)
597
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
599
class TestRepositoryConverter(TestCaseWithTransport):
600
601
    def test_convert_empty(self):
602
        t = get_transport(self.get_url('.'))
603
        t.mkdir('repository')
604
        repo_dir = bzrdir.BzrDirMetaFormat1().initialize('repository')
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
605
        repo = weaverepo.RepositoryFormat7().initialize(repo_dir)
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
606
        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.
607
        converter = repository.CopyConverter(target_format)
1594.1.3 by Robert Collins
Fixup pb usage to use nested_progress_bar.
608
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
609
        try:
610
            converter.convert(repo, pb)
611
        finally:
612
            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.
613
        repo = repo_dir.open_repository()
614
        self.assertTrue(isinstance(target_format, repo._format.__class__))
1843.2.5 by Aaron Bentley
Add test of _unescape_xml
615
616
617
class TestMisc(TestCase):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
618
1843.2.5 by Aaron Bentley
Add test of _unescape_xml
619
    def test_unescape_xml(self):
620
        """We get some kind of error when malformed entities are passed"""
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
621
        self.assertRaises(KeyError, repository._unescape_xml, 'foo&bar;')
1910.2.13 by Aaron Bentley
Start work on converter
622
623
2255.2.211 by Robert Collins
Remove knit2 repository format- it has never been supported.
624
class TestRepositoryFormatKnit3(TestCaseWithTransport):
1910.2.13 by Aaron Bentley
Start work on converter
625
3565.3.1 by Robert Collins
* The generic fetch code now uses two attributes on Repository objects
626
    def test_attribute__fetch_order(self):
627
        """Knits need topological data insertion."""
628
        format = bzrdir.BzrDirMetaFormat1()
629
        format.repository_format = knitrepo.RepositoryFormatKnit3()
630
        repo = self.make_repository('.', format=format)
4053.1.4 by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat.
631
        self.assertEqual('topological', repo._format._fetch_order)
3565.3.1 by Robert Collins
* The generic fetch code now uses two attributes on Repository objects
632
633
    def test_attribute__fetch_uses_deltas(self):
634
        """Knits reuse deltas."""
635
        format = bzrdir.BzrDirMetaFormat1()
636
        format.repository_format = knitrepo.RepositoryFormatKnit3()
637
        repo = self.make_repository('.', format=format)
4053.1.4 by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat.
638
        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
639
1910.2.13 by Aaron Bentley
Start work on converter
640
    def test_convert(self):
641
        """Ensure the upgrade adds weaves for roots"""
1910.2.35 by Aaron Bentley
Better fix for convesion test
642
        format = bzrdir.BzrDirMetaFormat1()
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
643
        format.repository_format = knitrepo.RepositoryFormatKnit1()
1910.2.35 by Aaron Bentley
Better fix for convesion test
644
        tree = self.make_branch_and_tree('.', format)
1910.2.13 by Aaron Bentley
Start work on converter
645
        tree.commit("Dull commit", rev_id="dull")
646
        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.
647
        revision_tree.lock_read()
648
        try:
649
            self.assertRaises(errors.NoSuchFile, revision_tree.get_file_lines,
650
                revision_tree.inventory.root.file_id)
651
        finally:
652
            revision_tree.unlock()
1910.2.13 by Aaron Bentley
Start work on converter
653
        format = bzrdir.BzrDirMetaFormat1()
2255.2.211 by Robert Collins
Remove knit2 repository format- it has never been supported.
654
        format.repository_format = knitrepo.RepositoryFormatKnit3()
1910.2.13 by Aaron Bentley
Start work on converter
655
        upgrade.Convert('.', format)
1910.2.27 by Aaron Bentley
Fixed conversion test
656
        tree = workingtree.WorkingTree.open('.')
1910.2.13 by Aaron Bentley
Start work on converter
657
        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.
658
        revision_tree.lock_read()
659
        try:
660
            revision_tree.get_file_lines(revision_tree.inventory.root.file_id)
661
        finally:
662
            revision_tree.unlock()
1910.2.27 by Aaron Bentley
Fixed conversion test
663
        tree.commit("Another dull commit", rev_id='dull2')
664
        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.
665
        revision_tree.lock_read()
666
        self.addCleanup(revision_tree.unlock)
1910.2.27 by Aaron Bentley
Fixed conversion test
667
        self.assertEqual('dull', revision_tree.inventory.root.revision)
2220.2.2 by Martin Pool
Add tag command and basic implementation
668
3221.3.1 by Robert Collins
* Repository formats have a new supported-feature attribute
669
    def test_supports_external_lookups(self):
670
        format = bzrdir.BzrDirMetaFormat1()
671
        format.repository_format = knitrepo.RepositoryFormatKnit3()
672
        repo = self.make_repository('.', format=format)
673
        self.assertFalse(repo._format.supports_external_lookups)
674
2535.3.57 by Andrew Bennetts
Perform some sanity checking of data streams rather than blindly inserting them into our repository.
675
4462.2.1 by Robert Collins
Add new attribute to RepositoryFormat pack_compresses, hinting when pack can be useful.
676
class Test2alpha(TestCaseWithTransport):
677
678
    def test_format_pack_compresses_True(self):
679
        repo = self.make_repository('repo', format='2a')
680
        self.assertTrue(repo._format.pack_compresses)
3735.2.40 by Robert Collins
Add development4 which has a parent_id to basename index on CHKInventory objects.
681
682
    def test_inventories_use_chk_map_with_parent_base_dict(self):
4462.2.1 by Robert Collins
Add new attribute to RepositoryFormat pack_compresses, hinting when pack can be useful.
683
        tree = self.make_branch_and_tree('repo', format="2a")
3735.2.40 by Robert Collins
Add development4 which has a parent_id to basename index on CHKInventory objects.
684
        revid = tree.commit("foo")
685
        tree.lock_read()
686
        self.addCleanup(tree.unlock)
687
        inv = tree.branch.repository.get_inventory(revid)
3735.2.41 by Robert Collins
Make the parent_id_basename index be updated during CHKInventory.apply_delta.
688
        self.assertNotEqual(None, inv.parent_id_basename_to_file_id)
689
        inv.parent_id_basename_to_file_id._ensure_root()
3735.2.40 by Robert Collins
Add development4 which has a parent_id to basename index on CHKInventory objects.
690
        inv.id_to_entry._ensure_root()
4241.6.8 by Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil
Add --development6-rich-root, disabling the legacy and unneeded development2 format, and activating the tests for CHK features disabled pending this format. (Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil)
691
        self.assertEqual(65536, inv.id_to_entry._root_node.maximum_size)
692
        self.assertEqual(65536,
3735.2.41 by Robert Collins
Make the parent_id_basename index be updated during CHKInventory.apply_delta.
693
            inv.parent_id_basename_to_file_id._root_node.maximum_size)
3735.2.40 by Robert Collins
Add development4 which has a parent_id to basename index on CHKInventory objects.
694
4360.4.3 by John Arbash Meinel
Introduce a KnitPackStreamSource which is used when
695
    def test_stream_source_to_gc(self):
4462.2.1 by Robert Collins
Add new attribute to RepositoryFormat pack_compresses, hinting when pack can be useful.
696
        source = self.make_repository('source', format='2a')
697
        target = self.make_repository('target', format='2a')
4360.4.3 by John Arbash Meinel
Introduce a KnitPackStreamSource which is used when
698
        stream = source._get_source(target._format)
699
        self.assertIsInstance(stream, groupcompress_repo.GroupCHKStreamSource)
700
701
    def test_stream_source_to_non_gc(self):
4462.2.1 by Robert Collins
Add new attribute to RepositoryFormat pack_compresses, hinting when pack can be useful.
702
        source = self.make_repository('source', format='2a')
4360.4.3 by John Arbash Meinel
Introduce a KnitPackStreamSource which is used when
703
        target = self.make_repository('target', format='rich-root-pack')
704
        stream = source._get_source(target._format)
705
        # We don't want the child GroupCHKStreamSource
706
        self.assertIs(type(stream), repository.StreamSource)
707
4360.4.9 by John Arbash Meinel
Merge bzr.dev, bringing in the gc stacking fixes.
708
    def test_get_stream_for_missing_keys_includes_all_chk_refs(self):
709
        source_builder = self.make_branch_builder('source',
4462.2.1 by Robert Collins
Add new attribute to RepositoryFormat pack_compresses, hinting when pack can be useful.
710
                            format='2a')
4360.4.9 by John Arbash Meinel
Merge bzr.dev, bringing in the gc stacking fixes.
711
        # We have to build a fairly large tree, so that we are sure the chk
712
        # pages will have split into multiple pages.
713
        entries = [('add', ('', 'a-root-id', 'directory', None))]
714
        for i in 'abcdefghijklmnopqrstuvwxyz123456789':
715
            for j in 'abcdefghijklmnopqrstuvwxyz123456789':
716
                fname = i + j
717
                fid = fname + '-id'
718
                content = 'content for %s\n' % (fname,)
719
                entries.append(('add', (fname, fid, 'file', content)))
720
        source_builder.start_series()
721
        source_builder.build_snapshot('rev-1', None, entries)
722
        # Now change a few of them, so we get a few new pages for the second
723
        # revision
724
        source_builder.build_snapshot('rev-2', ['rev-1'], [
725
            ('modify', ('aa-id', 'new content for aa-id\n')),
726
            ('modify', ('cc-id', 'new content for cc-id\n')),
727
            ('modify', ('zz-id', 'new content for zz-id\n')),
728
            ])
729
        source_builder.finish_series()
730
        source_branch = source_builder.get_branch()
731
        source_branch.lock_read()
732
        self.addCleanup(source_branch.unlock)
4462.2.1 by Robert Collins
Add new attribute to RepositoryFormat pack_compresses, hinting when pack can be useful.
733
        target = self.make_repository('target', format='2a')
4360.4.9 by John Arbash Meinel
Merge bzr.dev, bringing in the gc stacking fixes.
734
        source = source_branch.repository._get_source(target._format)
735
        self.assertIsInstance(source, groupcompress_repo.GroupCHKStreamSource)
736
737
        # On a regular pass, getting the inventories and chk pages for rev-2
738
        # would only get the newly created chk pages
739
        search = graph.SearchResult(set(['rev-2']), set(['rev-1']), 1,
740
                                    set(['rev-2']))
741
        simple_chk_records = []
742
        for vf_name, substream in source.get_stream(search):
743
            if vf_name == 'chk_bytes':
744
                for record in substream:
745
                    simple_chk_records.append(record.key)
746
            else:
747
                for _ in substream:
748
                    continue
749
        # 3 pages, the root (InternalNode), + 2 pages which actually changed
750
        self.assertEqual([('sha1:91481f539e802c76542ea5e4c83ad416bf219f73',),
751
                          ('sha1:4ff91971043668583985aec83f4f0ab10a907d3f',),
752
                          ('sha1:81e7324507c5ca132eedaf2d8414ee4bb2226187',),
753
                          ('sha1:b101b7da280596c71a4540e9a1eeba8045985ee0',)],
754
                         simple_chk_records)
755
        # Now, when we do a similar call using 'get_stream_for_missing_keys'
756
        # we should get a much larger set of pages.
757
        missing = [('inventories', 'rev-2')]
758
        full_chk_records = []
759
        for vf_name, substream in source.get_stream_for_missing_keys(missing):
760
            if vf_name == 'inventories':
761
                for record in substream:
762
                    self.assertEqual(('rev-2',), record.key)
763
            elif vf_name == 'chk_bytes':
764
                for record in substream:
765
                    full_chk_records.append(record.key)
766
            else:
767
                self.fail('Should not be getting a stream of %s' % (vf_name,))
768
        # We have 257 records now. This is because we have 1 root page, and 256
769
        # leaf pages in a complete listing.
770
        self.assertEqual(257, len(full_chk_records))
771
        self.assertSubset(simple_chk_records, full_chk_records)
772
4360.4.3 by John Arbash Meinel
Introduce a KnitPackStreamSource which is used when
773
774
class TestKnitPackStreamSource(tests.TestCaseWithMemoryTransport):
775
776
    def test_source_to_exact_pack_092(self):
777
        source = self.make_repository('source', format='pack-0.92')
778
        target = self.make_repository('target', format='pack-0.92')
779
        stream_source = source._get_source(target._format)
780
        self.assertIsInstance(stream_source, pack_repo.KnitPackStreamSource)
781
782
    def test_source_to_exact_pack_rich_root_pack(self):
783
        source = self.make_repository('source', format='rich-root-pack')
784
        target = self.make_repository('target', format='rich-root-pack')
785
        stream_source = source._get_source(target._format)
786
        self.assertIsInstance(stream_source, pack_repo.KnitPackStreamSource)
787
788
    def test_source_to_exact_pack_19(self):
789
        source = self.make_repository('source', format='1.9')
790
        target = self.make_repository('target', format='1.9')
791
        stream_source = source._get_source(target._format)
792
        self.assertIsInstance(stream_source, pack_repo.KnitPackStreamSource)
793
794
    def test_source_to_exact_pack_19_rich_root(self):
795
        source = self.make_repository('source', format='1.9-rich-root')
796
        target = self.make_repository('target', format='1.9-rich-root')
797
        stream_source = source._get_source(target._format)
798
        self.assertIsInstance(stream_source, pack_repo.KnitPackStreamSource)
799
800
    def test_source_to_remote_exact_pack_19(self):
801
        trans = self.make_smart_server('target')
802
        trans.ensure_base()
803
        source = self.make_repository('source', format='1.9')
804
        target = self.make_repository('target', format='1.9')
805
        target = repository.Repository.open(trans.base)
806
        stream_source = source._get_source(target._format)
807
        self.assertIsInstance(stream_source, pack_repo.KnitPackStreamSource)
808
809
    def test_stream_source_to_non_exact(self):
810
        source = self.make_repository('source', format='pack-0.92')
811
        target = self.make_repository('target', format='1.9')
812
        stream = source._get_source(target._format)
813
        self.assertIs(type(stream), repository.StreamSource)
814
815
    def test_stream_source_to_non_exact_rich_root(self):
816
        source = self.make_repository('source', format='1.9')
817
        target = self.make_repository('target', format='1.9-rich-root')
818
        stream = source._get_source(target._format)
819
        self.assertIs(type(stream), repository.StreamSource)
820
821
    def test_source_to_remote_non_exact_pack_19(self):
822
        trans = self.make_smart_server('target')
823
        trans.ensure_base()
824
        source = self.make_repository('source', format='1.9')
825
        target = self.make_repository('target', format='1.6')
826
        target = repository.Repository.open(trans.base)
827
        stream_source = source._get_source(target._format)
828
        self.assertIs(type(stream_source), repository.StreamSource)
829
830
    def test_stream_source_to_knit(self):
831
        source = self.make_repository('source', format='pack-0.92')
832
        target = self.make_repository('target', format='dirstate')
833
        stream = source._get_source(target._format)
834
        self.assertIs(type(stream), repository.StreamSource)
835
3735.2.40 by Robert Collins
Add development4 which has a parent_id to basename index on CHKInventory objects.
836
4343.3.32 by John Arbash Meinel
Change the tests for _find_revision_outside_set to the new _find_parent_ids function.
837
class TestDevelopment6FindParentIdsOfRevisions(TestCaseWithTransport):
838
    """Tests for _find_parent_ids_of_revisions."""
3735.4.1 by Andrew Bennetts
Add _find_revision_outside_set.
839
840
    def setUp(self):
4343.3.32 by John Arbash Meinel
Change the tests for _find_revision_outside_set to the new _find_parent_ids function.
841
        super(TestDevelopment6FindParentIdsOfRevisions, self).setUp()
4241.6.8 by Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil
Add --development6-rich-root, disabling the legacy and unneeded development2 format, and activating the tests for CHK features disabled pending this format. (Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil)
842
        self.builder = self.make_branch_builder('source',
843
            format='development6-rich-root')
3735.4.1 by Andrew Bennetts
Add _find_revision_outside_set.
844
        self.builder.start_series()
845
        self.builder.build_snapshot('initial', None,
846
            [('add', ('', 'tree-root', 'directory', None))])
847
        self.repo = self.builder.get_branch().repository
848
        self.addCleanup(self.builder.finish_series)
3735.2.99 by John Arbash Meinel
Merge bzr.dev 4034. Whitespace cleanup
849
4343.3.32 by John Arbash Meinel
Change the tests for _find_revision_outside_set to the new _find_parent_ids function.
850
    def assertParentIds(self, expected_result, rev_set):
851
        self.assertEqual(sorted(expected_result),
852
            sorted(self.repo._find_parent_ids_of_revisions(rev_set)))
3735.4.1 by Andrew Bennetts
Add _find_revision_outside_set.
853
854
    def test_simple(self):
855
        self.builder.build_snapshot('revid1', None, [])
4343.3.32 by John Arbash Meinel
Change the tests for _find_revision_outside_set to the new _find_parent_ids function.
856
        self.builder.build_snapshot('revid2', ['revid1'], [])
3735.4.1 by Andrew Bennetts
Add _find_revision_outside_set.
857
        rev_set = ['revid2']
4343.3.32 by John Arbash Meinel
Change the tests for _find_revision_outside_set to the new _find_parent_ids function.
858
        self.assertParentIds(['revid1'], rev_set)
3735.4.1 by Andrew Bennetts
Add _find_revision_outside_set.
859
860
    def test_not_first_parent(self):
861
        self.builder.build_snapshot('revid1', None, [])
4343.3.32 by John Arbash Meinel
Change the tests for _find_revision_outside_set to the new _find_parent_ids function.
862
        self.builder.build_snapshot('revid2', ['revid1'], [])
863
        self.builder.build_snapshot('revid3', ['revid2'], [])
3735.4.1 by Andrew Bennetts
Add _find_revision_outside_set.
864
        rev_set = ['revid3', 'revid2']
4343.3.32 by John Arbash Meinel
Change the tests for _find_revision_outside_set to the new _find_parent_ids function.
865
        self.assertParentIds(['revid1'], rev_set)
3735.4.1 by Andrew Bennetts
Add _find_revision_outside_set.
866
867
    def test_not_null(self):
868
        rev_set = ['initial']
4343.3.32 by John Arbash Meinel
Change the tests for _find_revision_outside_set to the new _find_parent_ids function.
869
        self.assertParentIds([], rev_set)
3735.4.1 by Andrew Bennetts
Add _find_revision_outside_set.
870
871
    def test_not_null_set(self):
872
        self.builder.build_snapshot('revid1', None, [])
873
        rev_set = [_mod_revision.NULL_REVISION]
4343.3.32 by John Arbash Meinel
Change the tests for _find_revision_outside_set to the new _find_parent_ids function.
874
        self.assertParentIds([], rev_set)
3735.4.1 by Andrew Bennetts
Add _find_revision_outside_set.
875
876
    def test_ghost(self):
877
        self.builder.build_snapshot('revid1', None, [])
878
        rev_set = ['ghost', 'revid1']
4343.3.32 by John Arbash Meinel
Change the tests for _find_revision_outside_set to the new _find_parent_ids function.
879
        self.assertParentIds(['initial'], rev_set)
3735.4.1 by Andrew Bennetts
Add _find_revision_outside_set.
880
881
    def test_ghost_parent(self):
882
        self.builder.build_snapshot('revid1', None, [])
883
        self.builder.build_snapshot('revid2', ['revid1', 'ghost'], [])
884
        rev_set = ['revid2', 'revid1']
4343.3.32 by John Arbash Meinel
Change the tests for _find_revision_outside_set to the new _find_parent_ids function.
885
        self.assertParentIds(['ghost', 'initial'], rev_set)
3735.4.1 by Andrew Bennetts
Add _find_revision_outside_set.
886
887
    def test_righthand_parent(self):
888
        self.builder.build_snapshot('revid1', None, [])
889
        self.builder.build_snapshot('revid2a', ['revid1'], [])
890
        self.builder.build_snapshot('revid2b', ['revid1'], [])
891
        self.builder.build_snapshot('revid3', ['revid2a', 'revid2b'], [])
892
        rev_set = ['revid3', 'revid2a']
4343.3.32 by John Arbash Meinel
Change the tests for _find_revision_outside_set to the new _find_parent_ids function.
893
        self.assertParentIds(['revid1', 'revid2b'], rev_set)
3735.4.1 by Andrew Bennetts
Add _find_revision_outside_set.
894
895
2535.3.57 by Andrew Bennetts
Perform some sanity checking of data streams rather than blindly inserting them into our repository.
896
class TestWithBrokenRepo(TestCaseWithTransport):
2592.3.214 by Robert Collins
Merge bzr.dev.
897
    """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.
898
899
    def make_broken_repository(self):
900
        # XXX: This function is borrowed from Aaron's "Reconcile can fix bad
901
        # parent references" branch which is due to land in bzr.dev soon.  Once
902
        # it does, this duplication should be removed.
903
        repo = self.make_repository('broken-repo')
904
        cleanups = []
905
        try:
906
            repo.lock_write()
907
            cleanups.append(repo.unlock)
908
            repo.start_write_group()
909
            cleanups.append(repo.commit_write_group)
910
            # make rev1a: A well-formed revision, containing 'file1'
911
            inv = inventory.Inventory(revision_id='rev1a')
912
            inv.root.revision = 'rev1a'
913
            self.add_file(repo, inv, 'file1', 'rev1a', [])
914
            repo.add_inventory('rev1a', inv, [])
915
            revision = _mod_revision.Revision('rev1a',
916
                committer='jrandom@example.com', timestamp=0,
917
                inventory_sha1='', timezone=0, message='foo', parent_ids=[])
918
            repo.add_revision('rev1a',revision, inv)
919
920
            # make rev1b, which has no Revision, but has an Inventory, and
921
            # file1
922
            inv = inventory.Inventory(revision_id='rev1b')
923
            inv.root.revision = 'rev1b'
924
            self.add_file(repo, inv, 'file1', 'rev1b', [])
925
            repo.add_inventory('rev1b', inv, [])
926
927
            # make rev2, with file1 and file2
928
            # file2 is sane
929
            # file1 has 'rev1b' as an ancestor, even though this is not
930
            # mentioned by 'rev1a', making it an unreferenced ancestor
931
            inv = inventory.Inventory()
932
            self.add_file(repo, inv, 'file1', 'rev2', ['rev1a', 'rev1b'])
933
            self.add_file(repo, inv, 'file2', 'rev2', [])
934
            self.add_revision(repo, 'rev2', inv, ['rev1a'])
935
936
            # make ghost revision rev1c
937
            inv = inventory.Inventory()
938
            self.add_file(repo, inv, 'file2', 'rev1c', [])
939
940
            # make rev3 with file2
941
            # file2 refers to 'rev1c', which is a ghost in this repository, so
942
            # file2 cannot have rev1c as its ancestor.
943
            inv = inventory.Inventory()
944
            self.add_file(repo, inv, 'file2', 'rev3', ['rev1c'])
945
            self.add_revision(repo, 'rev3', inv, ['rev1c'])
946
            return repo
947
        finally:
948
            for cleanup in reversed(cleanups):
949
                cleanup()
950
951
    def add_revision(self, repo, revision_id, inv, parent_ids):
952
        inv.revision_id = revision_id
953
        inv.root.revision = revision_id
954
        repo.add_inventory(revision_id, inv, parent_ids)
955
        revision = _mod_revision.Revision(revision_id,
956
            committer='jrandom@example.com', timestamp=0, inventory_sha1='',
957
            timezone=0, message='foo', parent_ids=parent_ids)
958
        repo.add_revision(revision_id,revision, inv)
959
960
    def add_file(self, repo, inv, filename, revision, parents):
961
        file_id = filename + '-id'
962
        entry = inventory.InventoryFile(file_id, filename, 'TREE_ROOT')
963
        entry.revision = revision
2535.4.10 by Andrew Bennetts
Fix one failing test, disable another.
964
        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.
965
        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.
966
        text_key = (file_id, revision)
967
        parent_keys = [(file_id, parent) for parent in parents]
968
        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.
969
970
    def test_insert_from_broken_repo(self):
971
        """Inserting a data stream from a broken repository won't silently
972
        corrupt the target repository.
973
        """
974
        broken_repo = self.make_broken_repository()
975
        empty_repo = self.make_repository('empty-repo')
4360.4.17 by John Arbash Meinel
Change insert_from_broken_repo into an expectedFailure.
976
        # See bug https://bugs.launchpad.net/bzr/+bug/389141 for information
977
        # about why this was turned into expectFailure
978
        self.expectFailure('new Stream fetch fills in missing compression'
979
           ' parents (bug #389141)',
980
           self.assertRaises, (errors.RevisionNotPresent, errors.BzrCheckError),
981
                              empty_repo.fetch, broken_repo)
3830.3.25 by John Arbash Meinel
We changed the error that is raised when fetching from a broken repo.
982
        self.assertRaises((errors.RevisionNotPresent, errors.BzrCheckError),
983
                          empty_repo.fetch, broken_repo)
2592.3.214 by Robert Collins
Merge bzr.dev.
984
985
2592.3.84 by Robert Collins
Start of autopacking logic.
986
class TestRepositoryPackCollection(TestCaseWithTransport):
987
988
    def get_format(self):
3010.3.3 by Martin Pool
Merge trunk
989
        return bzrdir.format_registry.make_bzrdir('pack-0.92')
2592.3.84 by Robert Collins
Start of autopacking logic.
990
3711.4.1 by John Arbash Meinel
Fix bug #242510, when determining the autopack sequence,
991
    def get_packs(self):
992
        format = self.get_format()
993
        repo = self.make_repository('.', format=format)
994
        return repo._pack_collection
995
3789.2.20 by John Arbash Meinel
The autopack code can now trigger itself to retry when _copy_revision_texts fails.
996
    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
997
        """Create a pack repo with 3 packs, and access it via a second repo."""
998
        tree = self.make_branch_and_tree('.')
999
        tree.lock_write()
1000
        self.addCleanup(tree.unlock)
1001
        rev1 = tree.commit('one')
1002
        rev2 = tree.commit('two')
1003
        rev3 = tree.commit('three')
1004
        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.
1005
        if write_lock:
1006
            r.lock_write()
1007
        else:
1008
            r.lock_read()
3789.2.19 by John Arbash Meinel
Refactor to make the tests a bit simpler
1009
        self.addCleanup(r.unlock)
1010
        packs = r._pack_collection
1011
        packs.ensure_loaded()
1012
        return tree, r, packs, [rev1, rev2, rev3]
1013
2592.3.84 by Robert Collins
Start of autopacking logic.
1014
    def test__max_pack_count(self):
2592.3.219 by Robert Collins
Review feedback.
1015
        """The maximum pack count is a function of the number of revisions."""
2592.3.84 by Robert Collins
Start of autopacking logic.
1016
        # no revisions - one pack, so that we can have a revision free repo
1017
        # without it blowing up
3711.4.1 by John Arbash Meinel
Fix bug #242510, when determining the autopack sequence,
1018
        packs = self.get_packs()
2592.3.84 by Robert Collins
Start of autopacking logic.
1019
        self.assertEqual(1, packs._max_pack_count(0))
1020
        # after that the sum of the digits, - check the first 1-9
1021
        self.assertEqual(1, packs._max_pack_count(1))
1022
        self.assertEqual(2, packs._max_pack_count(2))
1023
        self.assertEqual(3, packs._max_pack_count(3))
1024
        self.assertEqual(4, packs._max_pack_count(4))
1025
        self.assertEqual(5, packs._max_pack_count(5))
1026
        self.assertEqual(6, packs._max_pack_count(6))
1027
        self.assertEqual(7, packs._max_pack_count(7))
1028
        self.assertEqual(8, packs._max_pack_count(8))
1029
        self.assertEqual(9, packs._max_pack_count(9))
1030
        # check the boundary cases with two digits for the next decade
1031
        self.assertEqual(1, packs._max_pack_count(10))
1032
        self.assertEqual(2, packs._max_pack_count(11))
1033
        self.assertEqual(10, packs._max_pack_count(19))
1034
        self.assertEqual(2, packs._max_pack_count(20))
1035
        self.assertEqual(3, packs._max_pack_count(21))
1036
        # check some arbitrary big numbers
1037
        self.assertEqual(25, packs._max_pack_count(112894))
1038
1039
    def test_pack_distribution_zero(self):
3711.4.1 by John Arbash Meinel
Fix bug #242510, when determining the autopack sequence,
1040
        packs = self.get_packs()
2592.3.84 by Robert Collins
Start of autopacking logic.
1041
        self.assertEqual([0], packs.pack_distribution(0))
3052.1.6 by John Arbash Meinel
Change the lock check to raise ObjectNotLocked.
1042
1043
    def test_ensure_loaded_unlocked(self):
3711.4.1 by John Arbash Meinel
Fix bug #242510, when determining the autopack sequence,
1044
        packs = self.get_packs()
3052.1.6 by John Arbash Meinel
Change the lock check to raise ObjectNotLocked.
1045
        self.assertRaises(errors.ObjectNotLocked,
3711.4.1 by John Arbash Meinel
Fix bug #242510, when determining the autopack sequence,
1046
                          packs.ensure_loaded)
3052.1.6 by John Arbash Meinel
Change the lock check to raise ObjectNotLocked.
1047
2592.3.84 by Robert Collins
Start of autopacking logic.
1048
    def test_pack_distribution_one_to_nine(self):
3711.4.1 by John Arbash Meinel
Fix bug #242510, when determining the autopack sequence,
1049
        packs = self.get_packs()
2592.3.84 by Robert Collins
Start of autopacking logic.
1050
        self.assertEqual([1],
1051
            packs.pack_distribution(1))
1052
        self.assertEqual([1, 1],
1053
            packs.pack_distribution(2))
1054
        self.assertEqual([1, 1, 1],
1055
            packs.pack_distribution(3))
1056
        self.assertEqual([1, 1, 1, 1],
1057
            packs.pack_distribution(4))
1058
        self.assertEqual([1, 1, 1, 1, 1],
1059
            packs.pack_distribution(5))
1060
        self.assertEqual([1, 1, 1, 1, 1, 1],
1061
            packs.pack_distribution(6))
1062
        self.assertEqual([1, 1, 1, 1, 1, 1, 1],
1063
            packs.pack_distribution(7))
1064
        self.assertEqual([1, 1, 1, 1, 1, 1, 1, 1],
1065
            packs.pack_distribution(8))
1066
        self.assertEqual([1, 1, 1, 1, 1, 1, 1, 1, 1],
1067
            packs.pack_distribution(9))
1068
1069
    def test_pack_distribution_stable_at_boundaries(self):
1070
        """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,
1071
        packs = self.get_packs()
2592.3.84 by Robert Collins
Start of autopacking logic.
1072
        # in 10s:
1073
        self.assertEqual([10], packs.pack_distribution(10))
1074
        self.assertEqual([10, 1], packs.pack_distribution(11))
1075
        self.assertEqual([10, 10], packs.pack_distribution(20))
1076
        self.assertEqual([10, 10, 1], packs.pack_distribution(21))
1077
        # 100s
1078
        self.assertEqual([100], packs.pack_distribution(100))
1079
        self.assertEqual([100, 1], packs.pack_distribution(101))
1080
        self.assertEqual([100, 10, 1], packs.pack_distribution(111))
1081
        self.assertEqual([100, 100], packs.pack_distribution(200))
1082
        self.assertEqual([100, 100, 1], packs.pack_distribution(201))
1083
        self.assertEqual([100, 100, 10, 1], packs.pack_distribution(211))
1084
2592.3.85 by Robert Collins
Finish autopack corner cases.
1085
    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,
1086
        packs = self.get_packs()
2592.3.85 by Robert Collins
Finish autopack corner cases.
1087
        existing_packs = [(2000, "big"), (9, "medium")]
1088
        # rev count - 2009 -> 2x1000 + 9x1
1089
        pack_operations = packs.plan_autopack_combinations(
1090
            existing_packs, [1000, 1000, 1, 1, 1, 1, 1, 1, 1, 1, 1])
1091
        self.assertEqual([], pack_operations)
1092
1093
    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,
1094
        packs = self.get_packs()
2592.3.85 by Robert Collins
Finish autopack corner cases.
1095
        existing_packs = [(2000, "big"), (9, "medium"), (1, "single")]
1096
        # rev count - 2010 -> 2x1000 + 1x10
1097
        pack_operations = packs.plan_autopack_combinations(
1098
            existing_packs, [1000, 1000, 10])
1099
        self.assertEqual([], pack_operations)
1100
1101
    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,
1102
        packs = self.get_packs()
2592.3.85 by Robert Collins
Finish autopack corner cases.
1103
        existing_packs = [(1999, "big"), (9, "medium"), (1, "single2"),
1104
            (1, "single1")]
1105
        # rev count - 2010 -> 2x1000 + 1x10 (3)
1106
        pack_operations = packs.plan_autopack_combinations(
1107
            existing_packs, [1000, 1000, 10])
3711.4.2 by John Arbash Meinel
Change the logic to solve it in a different way.
1108
        self.assertEqual([[2, ["single2", "single1"]]], pack_operations)
2592.3.85 by Robert Collins
Finish autopack corner cases.
1109
3711.4.2 by John Arbash Meinel
Change the logic to solve it in a different way.
1110
    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,
1111
        packs = self.get_packs()
3711.4.2 by John Arbash Meinel
Change the logic to solve it in a different way.
1112
        existing_packs = [(50, 'a'), (40, 'b'), (30, 'c'), (10, 'd'),
1113
                          (10, 'e'), (6, 'f'), (4, 'g')]
1114
        # rev count 150 -> 1x100 and 5x10
1115
        # The two size 10 packs do not need to be touched. The 50, 40, 30 would
1116
        # be combined into a single 120 size pack, and the 6 & 4 would
1117
        # becombined into a size 10 pack. However, if we have to rewrite them,
1118
        # we save a pack file with no increased I/O by putting them into the
1119
        # same file.
1120
        distribution = packs.pack_distribution(150)
3711.4.1 by John Arbash Meinel
Fix bug #242510, when determining the autopack sequence,
1121
        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.
1122
                                                           distribution)
1123
        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,
1124
2592.3.173 by Robert Collins
Basic implementation of all_packs.
1125
    def test_all_packs_none(self):
1126
        format = self.get_format()
1127
        tree = self.make_branch_and_tree('.', format=format)
1128
        tree.lock_read()
1129
        self.addCleanup(tree.unlock)
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1130
        packs = tree.branch.repository._pack_collection
2592.3.173 by Robert Collins
Basic implementation of all_packs.
1131
        packs.ensure_loaded()
1132
        self.assertEqual([], packs.all_packs())
1133
1134
    def test_all_packs_one(self):
1135
        format = self.get_format()
1136
        tree = self.make_branch_and_tree('.', format=format)
1137
        tree.commit('start')
1138
        tree.lock_read()
1139
        self.addCleanup(tree.unlock)
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1140
        packs = tree.branch.repository._pack_collection
2592.3.173 by Robert Collins
Basic implementation of all_packs.
1141
        packs.ensure_loaded()
2592.3.176 by Robert Collins
Various pack refactorings.
1142
        self.assertEqual([
1143
            packs.get_pack_by_name(packs.names()[0])],
1144
            packs.all_packs())
2592.3.173 by Robert Collins
Basic implementation of all_packs.
1145
1146
    def test_all_packs_two(self):
1147
        format = self.get_format()
1148
        tree = self.make_branch_and_tree('.', format=format)
1149
        tree.commit('start')
1150
        tree.commit('continue')
1151
        tree.lock_read()
1152
        self.addCleanup(tree.unlock)
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1153
        packs = tree.branch.repository._pack_collection
2592.3.173 by Robert Collins
Basic implementation of all_packs.
1154
        packs.ensure_loaded()
1155
        self.assertEqual([
2592.3.176 by Robert Collins
Various pack refactorings.
1156
            packs.get_pack_by_name(packs.names()[0]),
1157
            packs.get_pack_by_name(packs.names()[1]),
2592.3.173 by Robert Collins
Basic implementation of all_packs.
1158
            ], packs.all_packs())
1159
2592.3.176 by Robert Collins
Various pack refactorings.
1160
    def test_get_pack_by_name(self):
1161
        format = self.get_format()
1162
        tree = self.make_branch_and_tree('.', format=format)
1163
        tree.commit('start')
1164
        tree.lock_read()
1165
        self.addCleanup(tree.unlock)
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1166
        packs = tree.branch.repository._pack_collection
4145.1.6 by Robert Collins
More test fallout, but all caught now.
1167
        packs.reset()
2592.3.176 by Robert Collins
Various pack refactorings.
1168
        packs.ensure_loaded()
1169
        name = packs.names()[0]
1170
        pack_1 = packs.get_pack_by_name(name)
1171
        # the pack should be correctly initialised
3517.4.5 by Martin Pool
Correct use of packs._names in test_get_pack_by_name
1172
        sizes = packs._names[name]
3221.12.4 by Robert Collins
Implement basic repository supporting external references.
1173
        rev_index = GraphIndex(packs._index_transport, name + '.rix', sizes[0])
1174
        inv_index = GraphIndex(packs._index_transport, name + '.iix', sizes[1])
1175
        txt_index = GraphIndex(packs._index_transport, name + '.tix', sizes[2])
1176
        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.
1177
        self.assertEqual(pack_repo.ExistingPack(packs._pack_transport,
2592.3.219 by Robert Collins
Review feedback.
1178
            name, rev_index, inv_index, txt_index, sig_index), pack_1)
2592.3.176 by Robert Collins
Various pack refactorings.
1179
        # and the same instance should be returned on successive calls.
1180
        self.assertTrue(pack_1 is packs.get_pack_by_name(name))
1181
3789.1.2 by John Arbash Meinel
Add RepositoryPackCollection.reload_pack_names()
1182
    def test_reload_pack_names_new_entry(self):
3789.2.19 by John Arbash Meinel
Refactor to make the tests a bit simpler
1183
        tree, r, packs, revs = self.make_packs_and_alt_repo()
3789.1.2 by John Arbash Meinel
Add RepositoryPackCollection.reload_pack_names()
1184
        names = packs.names()
1185
        # Add a new pack file into the repository
3789.2.19 by John Arbash Meinel
Refactor to make the tests a bit simpler
1186
        rev4 = tree.commit('four')
3789.1.2 by John Arbash Meinel
Add RepositoryPackCollection.reload_pack_names()
1187
        new_names = tree.branch.repository._pack_collection.names()
1188
        new_name = set(new_names).difference(names)
1189
        self.assertEqual(1, len(new_name))
1190
        new_name = new_name.pop()
1191
        # The old collection hasn't noticed yet
1192
        self.assertEqual(names, packs.names())
3789.1.8 by John Arbash Meinel
Change the api of reload_pack_names().
1193
        self.assertTrue(packs.reload_pack_names())
3789.1.2 by John Arbash Meinel
Add RepositoryPackCollection.reload_pack_names()
1194
        self.assertEqual(new_names, packs.names())
1195
        # And the repository can access the new revision
3789.2.19 by John Arbash Meinel
Refactor to make the tests a bit simpler
1196
        self.assertEqual({rev4:(revs[-1],)}, r.get_parent_map([rev4]))
3789.1.8 by John Arbash Meinel
Change the api of reload_pack_names().
1197
        self.assertFalse(packs.reload_pack_names())
3789.1.2 by John Arbash Meinel
Add RepositoryPackCollection.reload_pack_names()
1198
1199
    def test_reload_pack_names_added_and_removed(self):
3789.2.19 by John Arbash Meinel
Refactor to make the tests a bit simpler
1200
        tree, r, packs, revs = self.make_packs_and_alt_repo()
3789.1.2 by John Arbash Meinel
Add RepositoryPackCollection.reload_pack_names()
1201
        names = packs.names()
1202
        # Now repack the whole thing
1203
        tree.branch.repository.pack()
1204
        new_names = tree.branch.repository._pack_collection.names()
1205
        # The other collection hasn't noticed yet
1206
        self.assertEqual(names, packs.names())
3789.1.8 by John Arbash Meinel
Change the api of reload_pack_names().
1207
        self.assertTrue(packs.reload_pack_names())
3789.1.2 by John Arbash Meinel
Add RepositoryPackCollection.reload_pack_names()
1208
        self.assertEqual(new_names, packs.names())
3789.2.19 by John Arbash Meinel
Refactor to make the tests a bit simpler
1209
        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().
1210
        self.assertFalse(packs.reload_pack_names())
3789.1.2 by John Arbash Meinel
Add RepositoryPackCollection.reload_pack_names()
1211
3789.2.20 by John Arbash Meinel
The autopack code can now trigger itself to retry when _copy_revision_texts fails.
1212
    def test_autopack_reloads_and_stops(self):
1213
        tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
1214
        # After we have determined what needs to be autopacked, trigger a
1215
        # full-pack via the other repo which will cause us to re-evaluate and
1216
        # decide we don't need to do anything
1217
        orig_execute = packs._execute_pack_operations
1218
        def _munged_execute_pack_ops(*args, **kwargs):
1219
            tree.branch.repository.pack()
1220
            return orig_execute(*args, **kwargs)
1221
        packs._execute_pack_operations = _munged_execute_pack_ops
1222
        packs._max_pack_count = lambda x: 1
1223
        packs.pack_distribution = lambda x: [10]
1224
        self.assertFalse(packs.autopack())
1225
        self.assertEqual(1, len(packs.names()))
1226
        self.assertEqual(tree.branch.repository._pack_collection.names(),
1227
                         packs.names())
1228
2592.3.173 by Robert Collins
Basic implementation of all_packs.
1229
1230
class TestPack(TestCaseWithTransport):
1231
    """Tests for the Pack object."""
1232
1233
    def assertCurrentlyEqual(self, left, right):
1234
        self.assertTrue(left == right)
1235
        self.assertTrue(right == left)
1236
        self.assertFalse(left != right)
1237
        self.assertFalse(right != left)
1238
1239
    def assertCurrentlyNotEqual(self, left, right):
1240
        self.assertFalse(left == right)
1241
        self.assertFalse(right == left)
1242
        self.assertTrue(left != right)
1243
        self.assertTrue(right != left)
1244
1245
    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.
1246
        left = pack_repo.ExistingPack('', '', '', '', '', '')
1247
        right = pack_repo.ExistingPack('', '', '', '', '', '')
2592.3.173 by Robert Collins
Basic implementation of all_packs.
1248
        self.assertCurrentlyEqual(left, right)
1249
        # change all attributes and ensure equality changes as we do.
1250
        left.revision_index = 'a'
1251
        self.assertCurrentlyNotEqual(left, right)
1252
        right.revision_index = 'a'
1253
        self.assertCurrentlyEqual(left, right)
1254
        left.inventory_index = 'a'
1255
        self.assertCurrentlyNotEqual(left, right)
1256
        right.inventory_index = 'a'
1257
        self.assertCurrentlyEqual(left, right)
1258
        left.text_index = 'a'
1259
        self.assertCurrentlyNotEqual(left, right)
1260
        right.text_index = 'a'
1261
        self.assertCurrentlyEqual(left, right)
1262
        left.signature_index = 'a'
1263
        self.assertCurrentlyNotEqual(left, right)
1264
        right.signature_index = 'a'
1265
        self.assertCurrentlyEqual(left, right)
1266
        left.name = 'a'
1267
        self.assertCurrentlyNotEqual(left, right)
1268
        right.name = 'a'
1269
        self.assertCurrentlyEqual(left, right)
1270
        left.transport = 'a'
1271
        self.assertCurrentlyNotEqual(left, right)
1272
        right.transport = 'a'
1273
        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.
1274
1275
    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.
1276
        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.
1277
        self.assertEqual('a_name.pack', pack.file_name())
2592.3.192 by Robert Collins
Move new revision index management to NewPack.
1278
1279
1280
class TestNewPack(TestCaseWithTransport):
1281
    """Tests for pack_repo.NewPack."""
1282
2592.3.193 by Robert Collins
Move hash tracking of new packs into NewPack.
1283
    def test_new_instance_attributes(self):
2592.3.194 by Robert Collins
Output the revision index from NewPack.finish
1284
        upload_transport = self.get_transport('upload')
1285
        pack_transport = self.get_transport('pack')
1286
        index_transport = self.get_transport('index')
1287
        upload_transport.mkdir('.')
4241.6.8 by Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil
Add --development6-rich-root, disabling the legacy and unneeded development2 format, and activating the tests for CHK features disabled pending this format. (Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil)
1288
        collection = pack_repo.RepositoryPackCollection(
1289
            repo=None,
3830.3.1 by Martin Pool
NewPack should be constructed from the PackCollection, rather than attributes of it
1290
            transport=self.get_transport('.'),
1291
            index_transport=index_transport,
1292
            upload_transport=upload_transport,
1293
            pack_transport=pack_transport,
1294
            index_builder_class=BTreeBuilder,
4241.6.8 by Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil
Add --development6-rich-root, disabling the legacy and unneeded development2 format, and activating the tests for CHK features disabled pending this format. (Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil)
1295
            index_class=BTreeGraphIndex,
1296
            use_chk_index=False)
3830.3.1 by Martin Pool
NewPack should be constructed from the PackCollection, rather than attributes of it
1297
        pack = pack_repo.NewPack(collection)
3735.1.1 by Robert Collins
Add development2 formats using BTree indices.
1298
        self.assertIsInstance(pack.revision_index, BTreeBuilder)
1299
        self.assertIsInstance(pack.inventory_index, BTreeBuilder)
2929.3.5 by Vincent Ladeuil
New files, same warnings, same fixes.
1300
        self.assertIsInstance(pack._hash, type(osutils.md5()))
2592.3.194 by Robert Collins
Output the revision index from NewPack.finish
1301
        self.assertTrue(pack.upload_transport is upload_transport)
1302
        self.assertTrue(pack.index_transport is index_transport)
1303
        self.assertTrue(pack.pack_transport is pack_transport)
1304
        self.assertEqual(None, pack.index_sizes)
1305
        self.assertEqual(20, len(pack.random_name))
1306
        self.assertIsInstance(pack.random_name, str)
1307
        self.assertIsInstance(pack.start_time, float)
2951.1.2 by Robert Collins
Partial refactoring of pack_repo to create a Packer object for packing.
1308
1309
1310
class TestPacker(TestCaseWithTransport):
1311
    """Tests for the packs repository Packer class."""
2951.1.10 by Robert Collins
Peer review feedback with Ian.
1312
3824.2.4 by John Arbash Meinel
Add a test that ensures the pack ordering changes as part of calling .pack()
1313
    def test_pack_optimizes_pack_order(self):
1314
        builder = self.make_branch_builder('.')
1315
        builder.start_series()
1316
        builder.build_snapshot('A', None, [
1317
            ('add', ('', 'root-id', 'directory', None)),
1318
            ('add', ('f', 'f-id', 'file', 'content\n'))])
1319
        builder.build_snapshot('B', ['A'],
1320
            [('modify', ('f-id', 'new-content\n'))])
1321
        builder.build_snapshot('C', ['B'],
1322
            [('modify', ('f-id', 'third-content\n'))])
1323
        builder.build_snapshot('D', ['C'],
1324
            [('modify', ('f-id', 'fourth-content\n'))])
1325
        b = builder.get_branch()
1326
        b.lock_read()
1327
        builder.finish_series()
1328
        self.addCleanup(b.unlock)
1329
        # At this point, we should have 4 pack files available
1330
        # Because of how they were built, they correspond to
1331
        # ['D', 'C', 'B', 'A']
1332
        packs = b.repository._pack_collection.packs
1333
        packer = pack_repo.Packer(b.repository._pack_collection,
1334
                                  packs, 'testing',
1335
                                  revision_ids=['B', 'C'])
1336
        # Now, when we are copying the B & C revisions, their pack files should
1337
        # be moved to the front of the stack
3824.2.5 by Andrew Bennetts
Minor tweaks to comments etc.
1338
        # The new ordering moves B & C to the front of the .packs attribute,
1339
        # 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()
1340
        new_packs = [packs[1], packs[2], packs[0], packs[3]]
1341
        new_pack = packer.pack()
1342
        self.assertEqual(new_packs, packer.packs)
3146.6.1 by Aaron Bentley
InterDifferingSerializer shows a progress bar
1343
1344
3777.5.4 by John Arbash Meinel
OptimisingPacker now sets the optimize flags for the indexes being built.
1345
class TestOptimisingPacker(TestCaseWithTransport):
1346
    """Tests for the OptimisingPacker class."""
1347
1348
    def get_pack_collection(self):
1349
        repo = self.make_repository('.')
1350
        return repo._pack_collection
1351
1352
    def test_open_pack_will_optimise(self):
1353
        packer = pack_repo.OptimisingPacker(self.get_pack_collection(),
1354
                                            [], '.test')
1355
        new_pack = packer.open_pack()
1356
        self.assertIsInstance(new_pack, pack_repo.NewPack)
1357
        self.assertTrue(new_pack.revision_index._optimize_for_size)
1358
        self.assertTrue(new_pack.inventory_index._optimize_for_size)
1359
        self.assertTrue(new_pack.text_index._optimize_for_size)
1360
        self.assertTrue(new_pack.signature_index._optimize_for_size)