/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2220.2.2 by Martin Pool
Add tag command and basic implementation
1
# Copyright (C) 2006, 2007 Canonical Ltd
1685.1.63 by Martin Pool
Small Transport fixups
2
#
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1685.1.63 by Martin Pool
Small Transport fixups
7
#
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1685.1.63 by Martin Pool
Small Transport fixups
12
#
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Tests for the Repository facility that are not interface tests.
18
19
For interface tests see tests/repository_implementations/*.py.
20
21
For concrete class tests see this file, and for storage formats tests
22
also see this file.
23
"""
24
2592.3.193 by Robert Collins
Move hash tracking of new packs into NewPack.
25
import md5
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
26
from stat import S_ISDIR
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
27
from StringIO import StringIO
28
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.
29
import bzrlib
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
30
from bzrlib.errors import (NotBranchError,
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
31
                           NoSuchFile,
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
32
                           UnknownFormatError,
33
                           UnsupportedFormatError,
34
                           )
2592.3.192 by Robert Collins
Move new revision index management to NewPack.
35
from bzrlib.index import GraphIndex, InMemoryGraphIndex
2241.1.1 by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary
36
from bzrlib.repository import RepositoryFormat
2535.3.41 by Andrew Bennetts
Add tests for InterRemoteToOther.is_compatible.
37
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.
38
from bzrlib.tests import (
39
    TestCase,
40
    TestCaseWithTransport,
41
    test_knit,
42
    )
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
43
from bzrlib.transport import get_transport
44
from bzrlib.transport.memory import MemoryServer
2535.3.53 by Andrew Bennetts
Remove get_stream_as_bytes from KnitVersionedFile's API, make it a function in knitrepo.py instead.
45
from bzrlib.util import bencode
2241.1.1 by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary
46
from bzrlib import (
2535.3.41 by Andrew Bennetts
Add tests for InterRemoteToOther.is_compatible.
47
    bzrdir,
48
    errors,
2535.3.57 by Andrew Bennetts
Perform some sanity checking of data streams rather than blindly inserting them into our repository.
49
    inventory,
3146.6.1 by Aaron Bentley
InterDifferingSerializer shows a progress bar
50
    progress,
2241.1.1 by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary
51
    repository,
2535.3.57 by Andrew Bennetts
Perform some sanity checking of data streams rather than blindly inserting them into our repository.
52
    revision as _mod_revision,
2535.3.41 by Andrew Bennetts
Add tests for InterRemoteToOther.is_compatible.
53
    symbol_versioning,
2241.1.1 by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary
54
    upgrade,
55
    workingtree,
56
    )
2592.3.173 by Robert Collins
Basic implementation of all_packs.
57
from bzrlib.repofmt import knitrepo, weaverepo, pack_repo
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
58
59
60
class TestDefaultFormat(TestCase):
61
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
62
    def test_get_set_default_format(self):
2204.5.3 by Aaron Bentley
zap old repository default handling
63
        old_default = bzrdir.format_registry.get('default')
64
        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.
65
        old_format = repository.RepositoryFormat.get_default_format()
1910.2.33 by Aaron Bentley
Fix default format test
66
        self.assertTrue(isinstance(old_format, private_default))
2204.5.3 by Aaron Bentley
zap old repository default handling
67
        def make_sample_bzrdir():
68
            my_bzrdir = bzrdir.BzrDirMetaFormat1()
69
            my_bzrdir.repository_format = SampleRepositoryFormat()
70
            return my_bzrdir
71
        bzrdir.format_registry.remove('default')
72
        bzrdir.format_registry.register('sample', make_sample_bzrdir, '')
73
        bzrdir.format_registry.set_default('sample')
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
74
        # creating a repository should now create an instrumented dir.
75
        try:
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
76
            # the default branch format is used by the meta dir format
77
            # which is not the default bzrdir format at this point
1685.1.63 by Martin Pool
Small Transport fixups
78
            dir = bzrdir.BzrDirMetaFormat1().initialize('memory:///')
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
79
            result = dir.create_repository()
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
80
            self.assertEqual(result, 'A bzr repository dir')
2241.1.1 by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary
81
        finally:
2204.5.3 by Aaron Bentley
zap old repository default handling
82
            bzrdir.format_registry.remove('default')
2363.5.14 by Aaron Bentley
Prevent repository.get_set_default_format from corrupting inventory
83
            bzrdir.format_registry.remove('sample')
2204.5.3 by Aaron Bentley
zap old repository default handling
84
            bzrdir.format_registry.register('default', old_default, '')
85
        self.assertIsInstance(repository.RepositoryFormat.get_default_format(),
86
                              old_format.__class__)
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
87
88
89
class SampleRepositoryFormat(repository.RepositoryFormat):
90
    """A sample format
91
92
    this format is initializable, unsupported to aid in testing the 
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
93
    open and open(unsupported=True) routines.
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
94
    """
95
96
    def get_format_string(self):
97
        """See RepositoryFormat.get_format_string()."""
98
        return "Sample .bzr repository format."
99
1534.6.1 by Robert Collins
allow API creation of shared repositories
100
    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.
101
        """Initialize a repository in a BzrDir"""
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
102
        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.
103
        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.
104
        return 'A bzr repository dir'
105
106
    def is_supported(self):
107
        return False
108
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
109
    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.
110
        return "opened repository."
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
111
112
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
113
class TestRepositoryFormat(TestCaseWithTransport):
114
    """Tests for the Repository format detection used by the bzr meta dir facility.BzrBranchFormat facility."""
115
116
    def test_find_format(self):
117
        # is the right format object found for a repository?
118
        # create a branch with a few known format objects.
119
        # this is not quite the same as 
120
        self.build_tree(["foo/", "bar/"])
121
        def check_format(format, url):
122
            dir = format._matchingbzrdir.initialize(url)
123
            format.initialize(dir)
124
            t = get_transport(url)
125
            found_format = repository.RepositoryFormat.find_format(dir)
126
            self.failUnless(isinstance(found_format, format.__class__))
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
127
        check_format(weaverepo.RepositoryFormat7(), "bar")
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
128
        
129
    def test_find_format_no_repository(self):
130
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
131
        self.assertRaises(errors.NoRepositoryPresent,
132
                          repository.RepositoryFormat.find_format,
133
                          dir)
134
135
    def test_find_format_unknown_format(self):
136
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
137
        SampleRepositoryFormat().initialize(dir)
138
        self.assertRaises(UnknownFormatError,
139
                          repository.RepositoryFormat.find_format,
140
                          dir)
141
142
    def test_register_unregister_format(self):
143
        format = SampleRepositoryFormat()
144
        # make a control dir
145
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
146
        # make a repo
147
        format.initialize(dir)
148
        # register a format for it.
149
        repository.RepositoryFormat.register_format(format)
150
        # which repository.Open will refuse (not supported)
151
        self.assertRaises(UnsupportedFormatError, repository.Repository.open, self.get_url())
152
        # but open(unsupported) will work
153
        self.assertEqual(format.open(dir), "opened repository.")
154
        # unregister the format
155
        repository.RepositoryFormat.unregister_format(format)
156
157
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
158
class TestFormat6(TestCaseWithTransport):
159
160
    def test_no_ancestry_weave(self):
161
        control = bzrdir.BzrDirFormat6().initialize(self.get_url())
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
162
        repo = weaverepo.RepositoryFormat6().initialize(control)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
163
        # We no longer need to create the ancestry.weave file
164
        # since it is *never* used.
165
        self.assertRaises(NoSuchFile,
166
                          control.transport.get,
167
                          'ancestry.weave')
168
2818.4.2 by Robert Collins
Review feedback.
169
    def test_exposed_versioned_files_are_marked_dirty(self):
170
        control = bzrdir.BzrDirFormat6().initialize(self.get_url())
171
        repo = weaverepo.RepositoryFormat6().initialize(control)
172
        repo.lock_write()
173
        inv = repo.get_inventory_weave()
174
        repo.unlock()
175
        self.assertRaises(errors.OutSideTransaction,
176
            inv.add_lines, 'foo', [], [])
177
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
178
179
class TestFormat7(TestCaseWithTransport):
180
    
181
    def test_disk_layout(self):
182
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
183
        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.
184
        # in case of side effects of locking.
185
        repo.lock_write()
186
        repo.unlock()
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
187
        # we want:
188
        # format 'Bazaar-NG Repository format 7'
189
        # lock ''
190
        # inventory.weave == empty_weave
191
        # empty revision-store directory
192
        # empty weaves directory
193
        t = control.get_repository_transport(None)
194
        self.assertEqualDiff('Bazaar-NG Repository format 7',
195
                             t.get('format').read())
196
        self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
197
        self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
198
        self.assertEqualDiff('# bzr weave file v5\n'
199
                             'w\n'
200
                             'W\n',
201
                             t.get('inventory.weave').read())
1534.6.1 by Robert Collins
allow API creation of shared repositories
202
203
    def test_shared_disk_layout(self):
204
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
205
        repo = weaverepo.RepositoryFormat7().initialize(control, shared=True)
1534.6.1 by Robert Collins
allow API creation of shared repositories
206
        # we want:
207
        # format 'Bazaar-NG Repository format 7'
208
        # inventory.weave == empty_weave
209
        # empty revision-store directory
210
        # empty weaves directory
211
        # a 'shared-storage' marker file.
1553.5.49 by Martin Pool
Use LockDirs for repo format 7
212
        # lock is not present when unlocked
1534.6.1 by Robert Collins
allow API creation of shared repositories
213
        t = control.get_repository_transport(None)
214
        self.assertEqualDiff('Bazaar-NG Repository format 7',
215
                             t.get('format').read())
216
        self.assertEqualDiff('', t.get('shared-storage').read())
217
        self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
218
        self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
219
        self.assertEqualDiff('# bzr weave file v5\n'
220
                             'w\n'
221
                             'W\n',
222
                             t.get('inventory.weave').read())
1553.5.49 by Martin Pool
Use LockDirs for repo format 7
223
        self.assertFalse(t.has('branch-lock'))
224
1553.5.56 by Martin Pool
Format 7 repo now uses LockDir!
225
    def test_creates_lockdir(self):
1553.5.49 by Martin Pool
Use LockDirs for repo format 7
226
        """Make sure it appears to be controlled by a LockDir existence"""
227
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
228
        repo = weaverepo.RepositoryFormat7().initialize(control, shared=True)
1553.5.49 by Martin Pool
Use LockDirs for repo format 7
229
        t = control.get_repository_transport(None)
1553.5.58 by Martin Pool
Change LockDirs to format "lock-name/held/info"
230
        # TODO: Should check there is a 'lock' toplevel directory, 
231
        # regardless of contents
232
        self.assertFalse(t.has('lock/held/info'))
1553.5.49 by Martin Pool
Use LockDirs for repo format 7
233
        repo.lock_write()
1658.1.4 by Martin Pool
Quieten warning from TestFormat7.test_creates_lockdir about failing to unlock
234
        try:
235
            self.assertTrue(t.has('lock/held/info'))
236
        finally:
237
            # unlock so we don't get a warning about failing to do so
238
            repo.unlock()
1553.5.56 by Martin Pool
Format 7 repo now uses LockDir!
239
240
    def test_uses_lockdir(self):
241
        """repo format 7 actually locks on lockdir"""
242
        base_url = self.get_url()
243
        control = bzrdir.BzrDirMetaFormat1().initialize(base_url)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
244
        repo = weaverepo.RepositoryFormat7().initialize(control, shared=True)
1553.5.56 by Martin Pool
Format 7 repo now uses LockDir!
245
        t = control.get_repository_transport(None)
246
        repo.lock_write()
247
        repo.unlock()
248
        del repo
249
        # make sure the same lock is created by opening it
250
        repo = repository.Repository.open(base_url)
251
        repo.lock_write()
1553.5.58 by Martin Pool
Change LockDirs to format "lock-name/held/info"
252
        self.assertTrue(t.has('lock/held/info'))
1553.5.56 by Martin Pool
Format 7 repo now uses LockDir!
253
        repo.unlock()
1553.5.58 by Martin Pool
Change LockDirs to format "lock-name/held/info"
254
        self.assertFalse(t.has('lock/held/info'))
1534.6.5 by Robert Collins
Cloning of repos preserves shared and make-working-tree attributes.
255
256
    def test_shared_no_tree_disk_layout(self):
257
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
258
        repo = weaverepo.RepositoryFormat7().initialize(control, shared=True)
1534.6.5 by Robert Collins
Cloning of repos preserves shared and make-working-tree attributes.
259
        repo.set_make_working_trees(False)
260
        # we want:
261
        # format 'Bazaar-NG Repository format 7'
262
        # lock ''
263
        # inventory.weave == empty_weave
264
        # empty revision-store directory
265
        # empty weaves directory
266
        # a 'shared-storage' marker file.
267
        t = control.get_repository_transport(None)
268
        self.assertEqualDiff('Bazaar-NG Repository format 7',
269
                             t.get('format').read())
1553.5.56 by Martin Pool
Format 7 repo now uses LockDir!
270
        ## self.assertEqualDiff('', t.get('lock').read())
1534.6.5 by Robert Collins
Cloning of repos preserves shared and make-working-tree attributes.
271
        self.assertEqualDiff('', t.get('shared-storage').read())
272
        self.assertEqualDiff('', t.get('no-working-trees').read())
273
        repo.set_make_working_trees(True)
274
        self.assertFalse(t.has('no-working-trees'))
275
        self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
276
        self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
277
        self.assertEqualDiff('# bzr weave file v5\n'
278
                             'w\n'
279
                             'W\n',
280
                             t.get('inventory.weave').read())
1534.1.27 by Robert Collins
Start InterRepository with InterRepository.get.
281
2818.4.2 by Robert Collins
Review feedback.
282
    def test_exposed_versioned_files_are_marked_dirty(self):
283
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
284
        repo = weaverepo.RepositoryFormat7().initialize(control)
285
        repo.lock_write()
286
        inv = repo.get_inventory_weave()
287
        repo.unlock()
288
        self.assertRaises(errors.OutSideTransaction,
289
            inv.add_lines, 'foo', [], [])
290
1534.1.27 by Robert Collins
Start InterRepository with InterRepository.get.
291
1556.1.3 by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids
292
class TestFormatKnit1(TestCaseWithTransport):
293
    
294
    def test_disk_layout(self):
295
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
296
        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
297
        # in case of side effects of locking.
298
        repo.lock_write()
299
        repo.unlock()
300
        # we want:
301
        # format 'Bazaar-NG Knit Repository Format 1'
1553.5.62 by Martin Pool
Add tests that MetaDir repositories use LockDirs
302
        # 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
303
        # inventory.weave == empty_weave
304
        # empty revision-store directory
305
        # empty weaves directory
306
        t = control.get_repository_transport(None)
307
        self.assertEqualDiff('Bazaar-NG Knit Repository Format 1',
308
                             t.get('format').read())
1553.5.57 by Martin Pool
[merge] sync from bzr.dev
309
        # XXX: no locks left when unlocked at the moment
310
        # 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
311
        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.
312
        self.check_knits(t)
313
1654.1.3 by Robert Collins
Refactor repository knit tests slightly to remove duplication - add a assertHasKnit method.
314
    def assertHasKnit(self, t, knit_name):
315
        """Assert that knit_name exists on t."""
1666.1.7 by Robert Collins
Update repository format check to read knit correct header
316
        self.assertEqualDiff('# bzr knit index 8\n',
1654.1.3 by Robert Collins
Refactor repository knit tests slightly to remove duplication - add a assertHasKnit method.
317
                             t.get(knit_name + '.kndx').read())
318
        # no default content
319
        self.assertTrue(t.has(knit_name + '.knit'))
320
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
321
    def check_knits(self, t):
322
        """check knit content for a repository."""
1654.1.3 by Robert Collins
Refactor repository knit tests slightly to remove duplication - add a assertHasKnit method.
323
        self.assertHasKnit(t, 'inventory')
324
        self.assertHasKnit(t, 'revisions')
325
        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
326
327
    def test_shared_disk_layout(self):
328
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
329
        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
330
        # we want:
331
        # format 'Bazaar-NG Knit Repository Format 1'
1553.5.62 by Martin Pool
Add tests that MetaDir repositories use LockDirs
332
        # 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
333
        # inventory.weave == empty_weave
334
        # empty revision-store directory
335
        # empty weaves directory
336
        # a 'shared-storage' marker file.
337
        t = control.get_repository_transport(None)
338
        self.assertEqualDiff('Bazaar-NG Knit Repository Format 1',
339
                             t.get('format').read())
1553.5.57 by Martin Pool
[merge] sync from bzr.dev
340
        # XXX: no locks left when unlocked at the moment
341
        # 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
342
        self.assertEqualDiff('', t.get('shared-storage').read())
343
        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.
344
        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
345
346
    def test_shared_no_tree_disk_layout(self):
347
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
348
        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
349
        repo.set_make_working_trees(False)
350
        # we want:
351
        # format 'Bazaar-NG Knit Repository Format 1'
352
        # lock ''
353
        # inventory.weave == empty_weave
354
        # empty revision-store directory
355
        # empty weaves directory
356
        # a 'shared-storage' marker file.
357
        t = control.get_repository_transport(None)
358
        self.assertEqualDiff('Bazaar-NG Knit Repository Format 1',
359
                             t.get('format').read())
1553.5.57 by Martin Pool
[merge] sync from bzr.dev
360
        # XXX: no locks left when unlocked at the moment
361
        # 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
362
        self.assertEqualDiff('', t.get('shared-storage').read())
363
        self.assertEqualDiff('', t.get('no-working-trees').read())
364
        repo.set_make_working_trees(True)
365
        self.assertFalse(t.has('no-working-trees'))
366
        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.
367
        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
368
2818.4.2 by Robert Collins
Review feedback.
369
    def test_exposed_versioned_files_are_marked_dirty(self):
370
        format = bzrdir.BzrDirMetaFormat1()
371
        format.repository_format = knitrepo.RepositoryFormatKnit1()
372
        repo = self.make_repository('.', format=format)
373
        repo.lock_write()
374
        inv = repo.get_inventory_weave()
375
        repo.unlock()
376
        self.assertRaises(errors.OutSideTransaction,
377
            inv.add_lines, 'foo', [], [])
378
2917.2.1 by John Arbash Meinel
Fix bug #152360. The xml5 serializer should be using
379
    def test_deserialise_sets_root_revision(self):
380
        """We must have a inventory.root.revision
381
382
        Old versions of the XML5 serializer did not set the revision_id for
383
        the whole inventory. So we grab the one from the expected text. Which
384
        is valid when the api is not being abused.
385
        """
386
        repo = self.make_repository('.',
387
                format=bzrdir.format_registry.get('knit')())
388
        inv_xml = '<inventory format="5">\n</inventory>\n'
389
        inv = repo.deserialise_inventory('test-rev-id', inv_xml)
390
        self.assertEqual('test-rev-id', inv.root.revision)
391
392
    def test_deserialise_uses_global_revision_id(self):
393
        """If it is set, then we re-use the global revision id"""
394
        repo = self.make_repository('.',
395
                format=bzrdir.format_registry.get('knit')())
396
        inv_xml = ('<inventory format="5" revision_id="other-rev-id">\n'
397
                   '</inventory>\n')
398
        # Arguably, the deserialise_inventory should detect a mismatch, and
399
        # raise an error, rather than silently using one revision_id over the
400
        # 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.
401
        self.assertRaises(AssertionError, repo.deserialise_inventory,
402
            'test-rev-id', inv_xml)
403
        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
404
        self.assertEqual('other-rev-id', inv.root.revision)
405
2305.2.3 by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures.
406
2535.3.53 by Andrew Bennetts
Remove get_stream_as_bytes from KnitVersionedFile's API, make it a function in knitrepo.py instead.
407
class KnitRepositoryStreamTests(test_knit.KnitTests):
408
    """Tests for knitrepo._get_stream_as_bytes."""
409
410
    def test_get_stream_as_bytes(self):
411
        # Make a simple knit
412
        k1 = self.make_test_knit()
413
        k1.add_lines('text-a', [], test_knit.split_lines(test_knit.TEXT_1))
414
        
415
        # Serialise it, check the output.
416
        bytes = knitrepo._get_stream_as_bytes(k1, ['text-a'])
417
        data = bencode.bdecode(bytes)
418
        format, record = data
419
        self.assertEqual('knit-plain', format)
420
        self.assertEqual(['text-a', ['fulltext'], []], record[:3])
421
        self.assertRecordContentEqual(k1, 'text-a', record[3])
422
423
    def test_get_stream_as_bytes_all(self):
424
        """Get a serialised data stream for all the records in a knit.
425
426
        Much like test_get_stream_all, except for get_stream_as_bytes.
427
        """
428
        k1 = self.make_test_knit()
429
        # Insert the same data as BasicKnitTests.test_knit_join, as they seem
430
        # to cover a range of cases (no parents, one parent, multiple parents).
431
        test_data = [
432
            ('text-a', [], test_knit.TEXT_1),
433
            ('text-b', ['text-a'], test_knit.TEXT_1),
434
            ('text-c', [], test_knit.TEXT_1),
435
            ('text-d', ['text-c'], test_knit.TEXT_1),
436
            ('text-m', ['text-b', 'text-d'], test_knit.TEXT_1),
437
           ]
3023.2.3 by Martin Pool
Update tests for new ordering of results from get_data_stream - the order is not defined by the interface, but is stable
438
        # This test is actually a bit strict as the order in which they're
439
        # returned is not defined.  This matches the current (deterministic)
440
        # behaviour.
2535.3.53 by Andrew Bennetts
Remove get_stream_as_bytes from KnitVersionedFile's API, make it a function in knitrepo.py instead.
441
        expected_data_list = [
442
            # version, options, parents
443
            ('text-a', ['fulltext'], []),
444
            ('text-b', ['line-delta'], ['text-a']),
3023.2.3 by Martin Pool
Update tests for new ordering of results from get_data_stream - the order is not defined by the interface, but is stable
445
            ('text-m', ['line-delta'], ['text-b', 'text-d']),
2535.3.53 by Andrew Bennetts
Remove get_stream_as_bytes from KnitVersionedFile's API, make it a function in knitrepo.py instead.
446
            ('text-c', ['fulltext'], []),
447
            ('text-d', ['line-delta'], ['text-c']),
448
            ]
449
        for version_id, parents, lines in test_data:
450
            k1.add_lines(version_id, parents, test_knit.split_lines(lines))
451
452
        bytes = knitrepo._get_stream_as_bytes(
3023.2.3 by Martin Pool
Update tests for new ordering of results from get_data_stream - the order is not defined by the interface, but is stable
453
            k1, ['text-a', 'text-b', 'text-m', 'text-c', 'text-d', ])
2535.3.53 by Andrew Bennetts
Remove get_stream_as_bytes from KnitVersionedFile's API, make it a function in knitrepo.py instead.
454
455
        data = bencode.bdecode(bytes)
456
        format = data.pop(0)
457
        self.assertEqual('knit-plain', format)
458
459
        for expected, actual in zip(expected_data_list, data):
460
            expected_version = expected[0]
461
            expected_options = expected[1]
462
            expected_parents = expected[2]
463
            version, options, parents, bytes = actual
464
            self.assertEqual(expected_version, version)
465
            self.assertEqual(expected_options, options)
466
            self.assertEqual(expected_parents, parents)
467
            self.assertRecordContentEqual(k1, version, bytes)
468
469
2305.2.3 by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures.
470
class DummyRepository(object):
471
    """A dummy repository for testing."""
472
473
    _serializer = None
474
475
    def supports_rich_root(self):
476
        return False
477
478
479
class InterDummy(repository.InterRepository):
480
    """An inter-repository optimised code path for DummyRepository.
481
482
    This is for use during testing where we use DummyRepository as repositories
1534.1.28 by Robert Collins
Allow for optimised InterRepository selection.
483
    so that none of the default regsitered inter-repository classes will
2818.4.2 by Robert Collins
Review feedback.
484
    MATCH.
1534.1.28 by Robert Collins
Allow for optimised InterRepository selection.
485
    """
486
487
    @staticmethod
488
    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.
489
        """InterDummy is compatible with DummyRepository."""
490
        return (isinstance(repo_source, DummyRepository) and 
491
            isinstance(repo_target, DummyRepository))
1534.1.28 by Robert Collins
Allow for optimised InterRepository selection.
492
493
1534.1.27 by Robert Collins
Start InterRepository with InterRepository.get.
494
class TestInterRepository(TestCaseWithTransport):
495
496
    def test_get_default_inter_repository(self):
497
        # test that the InterRepository.get(repo_a, repo_b) probes
498
        # for a inter_repo class where is_compatible(repo_a, repo_b) returns
499
        # true and returns a default inter_repo otherwise.
500
        # This also tests that the default registered optimised interrepository
501
        # classes do not barf inappropriately when a surprising repository type
502
        # 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.
503
        dummy_a = DummyRepository()
504
        dummy_b = DummyRepository()
1534.1.28 by Robert Collins
Allow for optimised InterRepository selection.
505
        self.assertGetsDefaultInterRepository(dummy_a, dummy_b)
506
507
    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.
508
        """Asserts that InterRepository.get(repo_a, repo_b) -> the default.
509
        
510
        The effective default is now InterSameDataRepository because there is
511
        no actual sane default in the presence of incompatible data models.
512
        """
1534.1.28 by Robert Collins
Allow for optimised InterRepository selection.
513
        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.
514
        self.assertEqual(repository.InterSameDataRepository,
1534.1.27 by Robert Collins
Start InterRepository with InterRepository.get.
515
                         inter_repo.__class__)
1534.1.28 by Robert Collins
Allow for optimised InterRepository selection.
516
        self.assertEqual(repo_a, inter_repo.source)
517
        self.assertEqual(repo_b, inter_repo.target)
518
519
    def test_register_inter_repository_class(self):
520
        # test that a optimised code path provider - a
521
        # InterRepository subclass can be registered and unregistered
522
        # and that it is correctly selected when given a repository
523
        # pair that it returns true on for the is_compatible static method
524
        # check
2305.2.3 by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures.
525
        dummy_a = DummyRepository()
526
        dummy_b = DummyRepository()
527
        repo = self.make_repository('.')
528
        # hack dummies to look like repo somewhat.
529
        dummy_a._serializer = repo._serializer
530
        dummy_b._serializer = repo._serializer
531
        repository.InterRepository.register_optimiser(InterDummy)
1534.1.28 by Robert Collins
Allow for optimised InterRepository selection.
532
        try:
2305.2.3 by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures.
533
            # we should get the default for something InterDummy returns False
1534.1.28 by Robert Collins
Allow for optimised InterRepository selection.
534
            # to
2305.2.3 by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures.
535
            self.assertFalse(InterDummy.is_compatible(dummy_a, repo))
536
            self.assertGetsDefaultInterRepository(dummy_a, repo)
537
            # and we should get an InterDummy for a pair it 'likes'
538
            self.assertTrue(InterDummy.is_compatible(dummy_a, dummy_b))
1534.1.28 by Robert Collins
Allow for optimised InterRepository selection.
539
            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.
540
            self.assertEqual(InterDummy, inter_repo.__class__)
1534.1.28 by Robert Collins
Allow for optimised InterRepository selection.
541
            self.assertEqual(dummy_a, inter_repo.source)
542
            self.assertEqual(dummy_b, inter_repo.target)
543
        finally:
2305.2.3 by Andrew Bennetts
Bring across test_repository improvements from the hpss branch to fix the last test failures.
544
            repository.InterRepository.unregister_optimiser(InterDummy)
1534.1.28 by Robert Collins
Allow for optimised InterRepository selection.
545
        # now we should get the default InterRepository object again.
546
        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.
547
2241.1.17 by Martin Pool
Restore old InterWeave tests
548
549
class TestInterWeaveRepo(TestCaseWithTransport):
550
551
    def test_is_compatible_and_registered(self):
552
        # InterWeaveRepo is compatible when either side
553
        # is a format 5/6/7 branch
2241.1.20 by mbp at sourcefrog
update tests for new locations of weave repos
554
        from bzrlib.repofmt import knitrepo, weaverepo
555
        formats = [weaverepo.RepositoryFormat5(),
556
                   weaverepo.RepositoryFormat6(),
557
                   weaverepo.RepositoryFormat7()]
558
        incompatible_formats = [weaverepo.RepositoryFormat4(),
559
                                knitrepo.RepositoryFormatKnit1(),
2241.1.17 by Martin Pool
Restore old InterWeave tests
560
                                ]
561
        repo_a = self.make_repository('a')
562
        repo_b = self.make_repository('b')
563
        is_compatible = repository.InterWeaveRepo.is_compatible
564
        for source in incompatible_formats:
565
            # force incompatible left then right
566
            repo_a._format = source
567
            repo_b._format = formats[0]
568
            self.assertFalse(is_compatible(repo_a, repo_b))
569
            self.assertFalse(is_compatible(repo_b, repo_a))
570
        for source in formats:
571
            repo_a._format = source
572
            for target in formats:
573
                repo_b._format = target
574
                self.assertTrue(is_compatible(repo_a, repo_b))
575
        self.assertEqual(repository.InterWeaveRepo,
576
                         repository.InterRepository.get(repo_a,
577
                                                        repo_b).__class__)
578
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.
579
2535.3.41 by Andrew Bennetts
Add tests for InterRemoteToOther.is_compatible.
580
class TestInterRemoteToOther(TestCaseWithTransport):
581
582
    def make_remote_repository(self, path, backing_format=None):
583
        """Make a RemoteRepository object backed by a real repository that will
584
        be created at the given path."""
585
        self.make_repository(path, format=backing_format)
586
        smart_server = server.SmartTCPServer_for_testing()
587
        smart_server.setUp()
588
        remote_transport = get_transport(smart_server.get_url()).clone(path)
589
        self.addCleanup(smart_server.tearDown)
590
        remote_bzrdir = bzrdir.BzrDir.open_from_transport(remote_transport)
591
        remote_repo = remote_bzrdir.open_repository()
592
        return remote_repo
593
594
    def test_is_compatible_same_format(self):
595
        """InterRemoteToOther is compatible with a remote repository and a
596
        second repository that have the same format."""
597
        local_repo = self.make_repository('local')
598
        remote_repo = self.make_remote_repository('remote')
2535.3.62 by Andrew Bennetts
Cosmetic changes.
599
        is_compatible = repository.InterRemoteToOther.is_compatible
2535.3.41 by Andrew Bennetts
Add tests for InterRemoteToOther.is_compatible.
600
        self.assertTrue(
2535.3.62 by Andrew Bennetts
Cosmetic changes.
601
            is_compatible(remote_repo, local_repo),
2535.3.41 by Andrew Bennetts
Add tests for InterRemoteToOther.is_compatible.
602
            "InterRemoteToOther(%r, %r) is false" % (remote_repo, local_repo))
603
          
604
    def test_is_incompatible_different_format(self):
605
        local_repo = self.make_repository('local', 'dirstate')
606
        remote_repo = self.make_remote_repository('a', 'dirstate-with-subtree')
2535.3.62 by Andrew Bennetts
Cosmetic changes.
607
        is_compatible = repository.InterRemoteToOther.is_compatible
2535.3.65 by Andrew Bennetts
Correct test failure caused by typo.
608
        self.assertFalse(
2535.3.62 by Andrew Bennetts
Cosmetic changes.
609
            is_compatible(remote_repo, local_repo),
2535.3.65 by Andrew Bennetts
Correct test failure caused by typo.
610
            "InterRemoteToOther(%r, %r) is true" % (local_repo, remote_repo))
2535.3.41 by Andrew Bennetts
Add tests for InterRemoteToOther.is_compatible.
611
612
    def test_is_incompatible_different_format_both_remote(self):
2535.3.66 by Andrew Bennetts
Tidy a couple more long lines.
613
        remote_repo_a = self.make_remote_repository(
614
            'a', 'dirstate-with-subtree')
2535.3.41 by Andrew Bennetts
Add tests for InterRemoteToOther.is_compatible.
615
        remote_repo_b = self.make_remote_repository('b', 'dirstate')
2535.3.62 by Andrew Bennetts
Cosmetic changes.
616
        is_compatible = repository.InterRemoteToOther.is_compatible
2535.3.41 by Andrew Bennetts
Add tests for InterRemoteToOther.is_compatible.
617
        self.assertFalse(
2535.3.62 by Andrew Bennetts
Cosmetic changes.
618
            is_compatible(remote_repo_a, remote_repo_b),
2535.3.66 by Andrew Bennetts
Tidy a couple more long lines.
619
            "InterRemoteToOther(%r, %r) is true"
620
            % (remote_repo_a, remote_repo_b))
2535.3.41 by Andrew Bennetts
Add tests for InterRemoteToOther.is_compatible.
621
622
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.
623
class TestRepositoryConverter(TestCaseWithTransport):
624
625
    def test_convert_empty(self):
626
        t = get_transport(self.get_url('.'))
627
        t.mkdir('repository')
628
        repo_dir = bzrdir.BzrDirMetaFormat1().initialize('repository')
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
629
        repo = weaverepo.RepositoryFormat7().initialize(repo_dir)
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
630
        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.
631
        converter = repository.CopyConverter(target_format)
1594.1.3 by Robert Collins
Fixup pb usage to use nested_progress_bar.
632
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
633
        try:
634
            converter.convert(repo, pb)
635
        finally:
636
            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.
637
        repo = repo_dir.open_repository()
638
        self.assertTrue(isinstance(target_format, repo._format.__class__))
1843.2.5 by Aaron Bentley
Add test of _unescape_xml
639
640
641
class TestMisc(TestCase):
642
    
643
    def test_unescape_xml(self):
644
        """We get some kind of error when malformed entities are passed"""
645
        self.assertRaises(KeyError, repository._unescape_xml, 'foo&bar;') 
1910.2.13 by Aaron Bentley
Start work on converter
646
647
2255.2.211 by Robert Collins
Remove knit2 repository format- it has never been supported.
648
class TestRepositoryFormatKnit3(TestCaseWithTransport):
1910.2.13 by Aaron Bentley
Start work on converter
649
650
    def test_convert(self):
651
        """Ensure the upgrade adds weaves for roots"""
1910.2.35 by Aaron Bentley
Better fix for convesion test
652
        format = bzrdir.BzrDirMetaFormat1()
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
653
        format.repository_format = knitrepo.RepositoryFormatKnit1()
1910.2.35 by Aaron Bentley
Better fix for convesion test
654
        tree = self.make_branch_and_tree('.', format)
1910.2.13 by Aaron Bentley
Start work on converter
655
        tree.commit("Dull commit", rev_id="dull")
656
        revision_tree = tree.branch.repository.revision_tree('dull')
657
        self.assertRaises(errors.NoSuchFile, revision_tree.get_file_lines,
658
            revision_tree.inventory.root.file_id)
659
        format = bzrdir.BzrDirMetaFormat1()
2255.2.211 by Robert Collins
Remove knit2 repository format- it has never been supported.
660
        format.repository_format = knitrepo.RepositoryFormatKnit3()
1910.2.13 by Aaron Bentley
Start work on converter
661
        upgrade.Convert('.', format)
1910.2.27 by Aaron Bentley
Fixed conversion test
662
        tree = workingtree.WorkingTree.open('.')
1910.2.13 by Aaron Bentley
Start work on converter
663
        revision_tree = tree.branch.repository.revision_tree('dull')
664
        revision_tree.get_file_lines(revision_tree.inventory.root.file_id)
1910.2.27 by Aaron Bentley
Fixed conversion test
665
        tree.commit("Another dull commit", rev_id='dull2')
666
        revision_tree = tree.branch.repository.revision_tree('dull2')
667
        self.assertEqual('dull', revision_tree.inventory.root.revision)
2220.2.2 by Martin Pool
Add tag command and basic implementation
668
2818.4.2 by Robert Collins
Review feedback.
669
    def test_exposed_versioned_files_are_marked_dirty(self):
670
        format = bzrdir.BzrDirMetaFormat1()
671
        format.repository_format = knitrepo.RepositoryFormatKnit3()
672
        repo = self.make_repository('.', format=format)
673
        repo.lock_write()
674
        inv = repo.get_inventory_weave()
675
        repo.unlock()
676
        self.assertRaises(errors.OutSideTransaction,
677
            inv.add_lines, 'foo', [], [])
2535.4.9 by Andrew Bennetts
Merge from bzr.dev
678
2535.3.57 by Andrew Bennetts
Perform some sanity checking of data streams rather than blindly inserting them into our repository.
679
680
class TestWithBrokenRepo(TestCaseWithTransport):
2592.3.214 by Robert Collins
Merge bzr.dev.
681
    """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.
682
683
    def make_broken_repository(self):
684
        # XXX: This function is borrowed from Aaron's "Reconcile can fix bad
685
        # parent references" branch which is due to land in bzr.dev soon.  Once
686
        # it does, this duplication should be removed.
687
        repo = self.make_repository('broken-repo')
688
        cleanups = []
689
        try:
690
            repo.lock_write()
691
            cleanups.append(repo.unlock)
692
            repo.start_write_group()
693
            cleanups.append(repo.commit_write_group)
694
            # make rev1a: A well-formed revision, containing 'file1'
695
            inv = inventory.Inventory(revision_id='rev1a')
696
            inv.root.revision = 'rev1a'
697
            self.add_file(repo, inv, 'file1', 'rev1a', [])
698
            repo.add_inventory('rev1a', inv, [])
699
            revision = _mod_revision.Revision('rev1a',
700
                committer='jrandom@example.com', timestamp=0,
701
                inventory_sha1='', timezone=0, message='foo', parent_ids=[])
702
            repo.add_revision('rev1a',revision, inv)
703
704
            # make rev1b, which has no Revision, but has an Inventory, and
705
            # file1
706
            inv = inventory.Inventory(revision_id='rev1b')
707
            inv.root.revision = 'rev1b'
708
            self.add_file(repo, inv, 'file1', 'rev1b', [])
709
            repo.add_inventory('rev1b', inv, [])
710
711
            # make rev2, with file1 and file2
712
            # file2 is sane
713
            # file1 has 'rev1b' as an ancestor, even though this is not
714
            # mentioned by 'rev1a', making it an unreferenced ancestor
715
            inv = inventory.Inventory()
716
            self.add_file(repo, inv, 'file1', 'rev2', ['rev1a', 'rev1b'])
717
            self.add_file(repo, inv, 'file2', 'rev2', [])
718
            self.add_revision(repo, 'rev2', inv, ['rev1a'])
719
720
            # make ghost revision rev1c
721
            inv = inventory.Inventory()
722
            self.add_file(repo, inv, 'file2', 'rev1c', [])
723
724
            # make rev3 with file2
725
            # file2 refers to 'rev1c', which is a ghost in this repository, so
726
            # file2 cannot have rev1c as its ancestor.
727
            inv = inventory.Inventory()
728
            self.add_file(repo, inv, 'file2', 'rev3', ['rev1c'])
729
            self.add_revision(repo, 'rev3', inv, ['rev1c'])
730
            return repo
731
        finally:
732
            for cleanup in reversed(cleanups):
733
                cleanup()
734
735
    def add_revision(self, repo, revision_id, inv, parent_ids):
736
        inv.revision_id = revision_id
737
        inv.root.revision = revision_id
738
        repo.add_inventory(revision_id, inv, parent_ids)
739
        revision = _mod_revision.Revision(revision_id,
740
            committer='jrandom@example.com', timestamp=0, inventory_sha1='',
741
            timezone=0, message='foo', parent_ids=parent_ids)
742
        repo.add_revision(revision_id,revision, inv)
743
744
    def add_file(self, repo, inv, filename, revision, parents):
745
        file_id = filename + '-id'
746
        entry = inventory.InventoryFile(file_id, filename, 'TREE_ROOT')
747
        entry.revision = revision
2535.4.10 by Andrew Bennetts
Fix one failing test, disable another.
748
        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.
749
        inv.add(entry)
750
        vf = repo.weave_store.get_weave_or_empty(file_id,
751
                                                 repo.get_transaction())
752
        vf.add_lines(revision, parents, ['line\n'])
753
754
    def test_insert_from_broken_repo(self):
755
        """Inserting a data stream from a broken repository won't silently
756
        corrupt the target repository.
757
        """
758
        broken_repo = self.make_broken_repository()
759
        empty_repo = self.make_repository('empty-repo')
760
        stream = broken_repo.get_data_stream(['rev1a', 'rev2', 'rev3'])
2592.3.214 by Robert Collins
Merge bzr.dev.
761
        empty_repo.lock_write()
762
        self.addCleanup(empty_repo.unlock)
763
        empty_repo.start_write_group()
764
        try:
765
            self.assertRaises(
766
                errors.KnitCorrupt, empty_repo.insert_data_stream, stream)
767
        finally:
768
            empty_repo.abort_write_group()
769
770
2939.2.1 by Ian Clatworthy
use 'knitpack' naming instead of 'experimental' for pack formats
771
class TestKnitPackNoSubtrees(TestCaseWithTransport):
2592.3.24 by Robert Collins
Knit1 disk layout specified.
772
773
    def get_format(self):
3010.3.3 by Martin Pool
Merge trunk
774
        return bzrdir.format_registry.make_bzrdir('pack-0.92')
2592.3.24 by Robert Collins
Knit1 disk layout specified.
775
776
    def test_disk_layout(self):
777
        format = self.get_format()
2592.3.36 by Robert Collins
Change the revision index name to NAME.rix.
778
        repo = self.make_repository('.', format=format)
2592.3.24 by Robert Collins
Knit1 disk layout specified.
779
        # in case of side effects of locking.
780
        repo.lock_write()
781
        repo.unlock()
782
        t = repo.bzrdir.get_repository_transport(None)
783
        self.check_format(t)
784
        # XXX: no locks left when unlocked at the moment
785
        # self.assertEqualDiff('', t.get('lock').read())
786
        self.check_databases(t)
787
788
    def check_format(self, t):
2939.2.5 by Ian Clatworthy
review feedback from lifeless
789
        self.assertEqualDiff(
2939.2.7 by Ian Clatworthy
fix strings used in on-disk unit tests
790
            "Bazaar pack repository format 1 (needs bzr 0.92)\n",
2592.3.24 by Robert Collins
Knit1 disk layout specified.
791
                             t.get('format').read())
792
793
    def assertHasKndx(self, t, knit_name):
794
        """Assert that knit_name exists on t."""
795
        self.assertEqualDiff('# bzr knit index 8\n',
796
                             t.get(knit_name + '.kndx').read())
797
798
    def assertHasNoKndx(self, t, knit_name):
799
        """Assert that knit_name has no index on t."""
800
        self.assertFalse(t.has(knit_name + '.kndx'))
801
2592.3.81 by Robert Collins
Merge FileName allocation change, leading to hash based pack file names.
802
    def assertHasNoKnit(self, t, knit_name):
2592.3.24 by Robert Collins
Knit1 disk layout specified.
803
        """Assert that knit_name exists on t."""
804
        # no default content
2592.3.81 by Robert Collins
Merge FileName allocation change, leading to hash based pack file names.
805
        self.assertFalse(t.has(knit_name + '.knit'))
2592.3.24 by Robert Collins
Knit1 disk layout specified.
806
807
    def check_databases(self, t):
808
        """check knit content for a repository."""
2592.3.81 by Robert Collins
Merge FileName allocation change, leading to hash based pack file names.
809
        # check conversion worked
2592.3.61 by Robert Collins
Remove inventory.kndx.
810
        self.assertHasNoKndx(t, 'inventory')
2592.3.81 by Robert Collins
Merge FileName allocation change, leading to hash based pack file names.
811
        self.assertHasNoKnit(t, 'inventory')
2592.3.24 by Robert Collins
Knit1 disk layout specified.
812
        self.assertHasNoKndx(t, 'revisions')
2592.3.81 by Robert Collins
Merge FileName allocation change, leading to hash based pack file names.
813
        self.assertHasNoKnit(t, 'revisions')
2592.3.39 by Robert Collins
Fugly version to remove signatures.kndx
814
        self.assertHasNoKndx(t, 'signatures')
2592.3.81 by Robert Collins
Merge FileName allocation change, leading to hash based pack file names.
815
        self.assertHasNoKnit(t, 'signatures')
816
        self.assertFalse(t.has('knits'))
2592.3.24 by Robert Collins
Knit1 disk layout specified.
817
        # revision-indexes file-container directory
2592.3.83 by Robert Collins
Merge bzr.dev, dropping FileNames for a trivial GraphIndex layer.
818
        self.assertEqual([],
2592.3.175 by Robert Collins
Update for GraphIndex constructor changes.
819
            list(GraphIndex(t, 'pack-names', None).iter_all_entries()))
2592.3.81 by Robert Collins
Merge FileName allocation change, leading to hash based pack file names.
820
        self.assertTrue(S_ISDIR(t.stat('packs').st_mode))
821
        self.assertTrue(S_ISDIR(t.stat('upload').st_mode))
2592.3.219 by Robert Collins
Review feedback.
822
        self.assertTrue(S_ISDIR(t.stat('indices').st_mode))
823
        self.assertTrue(S_ISDIR(t.stat('obsolete_packs').st_mode))
2592.3.24 by Robert Collins
Knit1 disk layout specified.
824
825
    def test_shared_disk_layout(self):
826
        format = self.get_format()
2592.3.36 by Robert Collins
Change the revision index name to NAME.rix.
827
        repo = self.make_repository('.', shared=True, format=format)
2592.3.24 by Robert Collins
Knit1 disk layout specified.
828
        # we want:
829
        t = repo.bzrdir.get_repository_transport(None)
830
        self.check_format(t)
831
        # XXX: no locks left when unlocked at the moment
832
        # self.assertEqualDiff('', t.get('lock').read())
2592.3.219 by Robert Collins
Review feedback.
833
        # We should have a 'shared-storage' marker file.
2592.3.24 by Robert Collins
Knit1 disk layout specified.
834
        self.assertEqualDiff('', t.get('shared-storage').read())
835
        self.check_databases(t)
836
837
    def test_shared_no_tree_disk_layout(self):
838
        format = self.get_format()
2592.3.36 by Robert Collins
Change the revision index name to NAME.rix.
839
        repo = self.make_repository('.', shared=True, format=format)
2592.3.24 by Robert Collins
Knit1 disk layout specified.
840
        repo.set_make_working_trees(False)
841
        # we want:
842
        t = repo.bzrdir.get_repository_transport(None)
843
        self.check_format(t)
844
        # XXX: no locks left when unlocked at the moment
845
        # self.assertEqualDiff('', t.get('lock').read())
2592.3.219 by Robert Collins
Review feedback.
846
        # We should have a 'shared-storage' marker file.
2592.3.24 by Robert Collins
Knit1 disk layout specified.
847
        self.assertEqualDiff('', t.get('shared-storage').read())
2592.3.219 by Robert Collins
Review feedback.
848
        # We should have a marker for the no-working-trees flag.
2592.3.24 by Robert Collins
Knit1 disk layout specified.
849
        self.assertEqualDiff('', t.get('no-working-trees').read())
2592.3.219 by Robert Collins
Review feedback.
850
        # The marker should go when we toggle the setting.
2592.3.24 by Robert Collins
Knit1 disk layout specified.
851
        repo.set_make_working_trees(True)
852
        self.assertFalse(t.has('no-working-trees'))
853
        self.check_databases(t)
2592.3.25 by Robert Collins
experimental-subtrees layout defined.
854
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
855
    def test_adding_revision_creates_pack_indices(self):
2592.3.118 by Robert Collins
Record the size of the index files in the pack-names index.
856
        format = self.get_format()
857
        tree = self.make_branch_and_tree('.', format=format)
858
        trans = tree.branch.repository.bzrdir.get_repository_transport(None)
859
        self.assertEqual([],
2592.3.175 by Robert Collins
Update for GraphIndex constructor changes.
860
            list(GraphIndex(trans, 'pack-names', None).iter_all_entries()))
2592.3.118 by Robert Collins
Record the size of the index files in the pack-names index.
861
        tree.commit('foobarbaz')
2592.3.175 by Robert Collins
Update for GraphIndex constructor changes.
862
        index = GraphIndex(trans, 'pack-names', None)
2592.3.219 by Robert Collins
Review feedback.
863
        index_nodes = list(index.iter_all_entries())
864
        self.assertEqual(1, len(index_nodes))
865
        node = index_nodes[0]
2592.3.118 by Robert Collins
Record the size of the index files in the pack-names index.
866
        name = node[1][0]
867
        # the pack sizes should be listed in the index
868
        pack_value = node[2]
869
        sizes = [int(digits) for digits in pack_value.split(' ')]
870
        for size, suffix in zip(sizes, ['.rix', '.iix', '.tix', '.six']):
871
            stat = trans.stat('indices/%s%s' % (name, suffix))
872
            self.assertEqual(size, stat.st_size)
2592.3.60 by Robert Collins
Nuke per-fileid indices for a single unified index.
873
2592.3.52 by Robert Collins
Stop allocating new names unless new data has been inserted.
874
    def test_pulling_nothing_leads_to_no_new_names(self):
875
        format = self.get_format()
876
        tree1 = self.make_branch_and_tree('1', format=format)
877
        tree2 = self.make_branch_and_tree('2', format=format)
878
        tree1.branch.repository.fetch(tree2.branch.repository)
879
        trans = tree1.branch.repository.bzrdir.get_repository_transport(None)
2592.3.83 by Robert Collins
Merge bzr.dev, dropping FileNames for a trivial GraphIndex layer.
880
        self.assertEqual([],
2592.3.175 by Robert Collins
Update for GraphIndex constructor changes.
881
            list(GraphIndex(trans, 'pack-names', None).iter_all_entries()))
2592.3.39 by Robert Collins
Fugly version to remove signatures.kndx
882
2592.3.84 by Robert Collins
Start of autopacking logic.
883
    def test_commit_across_pack_shape_boundary_autopacks(self):
884
        format = self.get_format()
885
        tree = self.make_branch_and_tree('.', format=format)
886
        trans = tree.branch.repository.bzrdir.get_repository_transport(None)
887
        # This test could be a little cheaper by replacing the packs
888
        # attribute on the repository to allow a different pack distribution
2592.3.219 by Robert Collins
Review feedback.
889
        # and max packs policy - so we are checking the policy is honoured
2592.3.84 by Robert Collins
Start of autopacking logic.
890
        # in the test. But for now 11 commits is not a big deal in a single
891
        # test.
892
        for x in range(9):
893
            tree.commit('commit %s' % x)
894
        # there should be 9 packs:
2592.3.175 by Robert Collins
Update for GraphIndex constructor changes.
895
        index = GraphIndex(trans, 'pack-names', None)
2592.3.84 by Robert Collins
Start of autopacking logic.
896
        self.assertEqual(9, len(list(index.iter_all_entries())))
2948.1.1 by Robert Collins
* Obsolete packs are now cleaned up by pack and autopack operations.
897
        # insert some files in obsolete_packs which should be removed by pack.
898
        trans.put_bytes('obsolete_packs/foo', '123')
899
        trans.put_bytes('obsolete_packs/bar', '321')
2592.3.84 by Robert Collins
Start of autopacking logic.
900
        # committing one more should coalesce to 1 of 10.
901
        tree.commit('commit triggering pack')
2592.3.175 by Robert Collins
Update for GraphIndex constructor changes.
902
        index = GraphIndex(trans, 'pack-names', None)
2592.3.84 by Robert Collins
Start of autopacking logic.
903
        self.assertEqual(1, len(list(index.iter_all_entries())))
904
        # packing should not damage data
905
        tree = tree.bzrdir.open_workingtree()
906
        check_result = tree.branch.repository.check(
907
            [tree.branch.last_revision()])
2948.1.1 by Robert Collins
* Obsolete packs are now cleaned up by pack and autopack operations.
908
        # We should have 50 (10x5) files in the obsolete_packs directory.
909
        obsolete_files = list(trans.list_dir('obsolete_packs'))
910
        self.assertFalse('foo' in obsolete_files)
911
        self.assertFalse('bar' in obsolete_files)
912
        self.assertEqual(50, len(obsolete_files))
2592.3.84 by Robert Collins
Start of autopacking logic.
913
        # XXX: Todo check packs obsoleted correctly - old packs and indices
914
        # in the obsolete_packs directory.
915
        large_pack_name = list(index.iter_all_entries())[0][1][0]
916
        # finally, committing again should not touch the large pack.
917
        tree.commit('commit not triggering pack')
2592.3.175 by Robert Collins
Update for GraphIndex constructor changes.
918
        index = GraphIndex(trans, 'pack-names', None)
2592.3.84 by Robert Collins
Start of autopacking logic.
919
        self.assertEqual(2, len(list(index.iter_all_entries())))
920
        pack_names = [node[1][0] for node in index.iter_all_entries()]
921
        self.assertTrue(large_pack_name in pack_names)
922
2592.3.86 by Robert Collins
Implement the pack commands for knit repositories.
923
    def test_pack_after_two_commits_packs_everything(self):
924
        format = self.get_format()
925
        tree = self.make_branch_and_tree('.', format=format)
926
        trans = tree.branch.repository.bzrdir.get_repository_transport(None)
927
        tree.commit('start')
928
        tree.commit('more work')
929
        tree.branch.repository.pack()
2592.3.219 by Robert Collins
Review feedback.
930
        # there should be 1 pack:
2592.3.175 by Robert Collins
Update for GraphIndex constructor changes.
931
        index = GraphIndex(trans, 'pack-names', None)
2592.3.86 by Robert Collins
Implement the pack commands for knit repositories.
932
        self.assertEqual(1, len(list(index.iter_all_entries())))
933
        self.assertEqual(2, len(tree.branch.repository.all_revision_ids()))
934
3070.1.1 by Robert Collins
* ``bzr pack`` now orders revision texts in topological order, with newest
935
    def test_pack_layout(self):
936
        format = self.get_format()
937
        tree = self.make_branch_and_tree('.', format=format)
938
        trans = tree.branch.repository.bzrdir.get_repository_transport(None)
939
        tree.commit('start', rev_id='1')
940
        tree.commit('more work', rev_id='2')
941
        tree.branch.repository.pack()
942
        tree.lock_read()
943
        self.addCleanup(tree.unlock)
944
        pack = tree.branch.repository._pack_collection.get_pack_by_name(
945
            tree.branch.repository._pack_collection.names()[0])
946
        # revision access tends to be tip->ancestor, so ordering that way on 
947
        # disk is a good idea.
948
        for _1, key, val, refs in pack.revision_index.iter_all_entries():
949
            if key == ('1',):
950
                pos_1 = int(val[1:].split()[0])
951
            else:
952
                pos_2 = int(val[1:].split()[0])
953
        self.assertTrue(pos_2 < pos_1)
954
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
955
    def test_pack_repositories_support_multiple_write_locks(self):
956
        format = self.get_format()
957
        self.make_repository('.', shared=True, format=format)
958
        r1 = repository.Repository.open('.')
959
        r2 = repository.Repository.open('.')
960
        r1.lock_write()
961
        self.addCleanup(r1.unlock)
962
        r2.lock_write()
963
        r2.unlock()
964
965
    def _add_text(self, repo, fileid):
966
        """Add a text to the repository within a write group."""
967
        vf =repo.weave_store.get_weave(fileid, repo.get_transaction())
968
        vf.add_lines('samplerev+' + fileid, [], [])
969
970
    def test_concurrent_writers_merge_new_packs(self):
971
        format = self.get_format()
972
        self.make_repository('.', shared=True, format=format)
973
        r1 = repository.Repository.open('.')
974
        r2 = repository.Repository.open('.')
975
        r1.lock_write()
976
        try:
977
            # access enough data to load the names list
978
            list(r1.all_revision_ids())
979
            r2.lock_write()
980
            try:
981
                # access enough data to load the names list
982
                list(r2.all_revision_ids())
983
                r1.start_write_group()
984
                try:
985
                    r2.start_write_group()
986
                    try:
987
                        self._add_text(r1, 'fileidr1')
988
                        self._add_text(r2, 'fileidr2')
989
                    except:
990
                        r2.abort_write_group()
991
                        raise
992
                except:
993
                    r1.abort_write_group()
994
                    raise
995
                # both r1 and r2 have open write groups with data in them
996
                # created while the other's write group was open.
997
                # Commit both which requires a merge to the pack-names.
998
                try:
999
                    r1.commit_write_group()
1000
                except:
2592.3.219 by Robert Collins
Review feedback.
1001
                    r1.abort_write_group()
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
1002
                    r2.abort_write_group()
1003
                    raise
1004
                r2.commit_write_group()
2592.3.213 by Robert Collins
Retain packs and indices in memory within a lock, even when write groups are entered and exited.
1005
                # tell r1 to reload from disk
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1006
                r1._pack_collection.reset()
2592.3.219 by Robert Collins
Review feedback.
1007
                # Now both repositories should know about both names
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1008
                r1._pack_collection.ensure_loaded()
1009
                r2._pack_collection.ensure_loaded()
1010
                self.assertEqual(r1._pack_collection.names(), r2._pack_collection.names())
1011
                self.assertEqual(2, len(r1._pack_collection.names()))
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
1012
            finally:
2939.1.1 by Martin Pool
Fix up mismatched lock/unlock pairs.
1013
                r2.unlock()
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
1014
        finally:
2939.1.1 by Martin Pool
Fix up mismatched lock/unlock pairs.
1015
            r1.unlock()
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
1016
1017
    def test_concurrent_writer_second_preserves_dropping_a_pack(self):
1018
        format = self.get_format()
1019
        self.make_repository('.', shared=True, format=format)
1020
        r1 = repository.Repository.open('.')
1021
        r2 = repository.Repository.open('.')
1022
        # add a pack to drop
1023
        r1.lock_write()
1024
        try:
1025
            r1.start_write_group()
1026
            try:
1027
                self._add_text(r1, 'fileidr1')
1028
            except:
1029
                r1.abort_write_group()
1030
                raise
1031
            else:
1032
                r1.commit_write_group()
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1033
            r1._pack_collection.ensure_loaded()
1034
            name_to_drop = r1._pack_collection.all_packs()[0].name
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
1035
        finally:
1036
            r1.unlock()
1037
        r1.lock_write()
1038
        try:
1039
            # access enough data to load the names list
1040
            list(r1.all_revision_ids())
1041
            r2.lock_write()
1042
            try:
1043
                # access enough data to load the names list
1044
                list(r2.all_revision_ids())
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1045
                r1._pack_collection.ensure_loaded()
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
1046
                try:
1047
                    r2.start_write_group()
1048
                    try:
1049
                        # in r1, drop the pack
2592.3.236 by Martin Pool
Make RepositoryPackCollection.remove_pack_from_memory private
1050
                        r1._pack_collection._remove_pack_from_memory(
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1051
                            r1._pack_collection.get_pack_by_name(name_to_drop))
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
1052
                        # in r2, add a pack
1053
                        self._add_text(r2, 'fileidr2')
1054
                    except:
1055
                        r2.abort_write_group()
1056
                        raise
1057
                except:
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1058
                    r1._pack_collection.reset()
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
1059
                    raise
1060
                # r1 has a changed names list, and r2 an open write groups with
1061
                # changes.
2592.3.208 by Robert Collins
Start refactoring the knit-pack thunking to be clearer.
1062
                # save r1, and then commit the r2 write group, which requires a
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
1063
                # merge to the pack-names, which should not reinstate
1064
                # name_to_drop
1065
                try:
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1066
                    r1._pack_collection._save_pack_names()
1067
                    r1._pack_collection.reset()
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
1068
                except:
1069
                    r2.abort_write_group()
1070
                    raise
1071
                try:
1072
                    r2.commit_write_group()
1073
                except:
1074
                    r2.abort_write_group()
1075
                    raise
1076
                # Now both repositories should now about just one name.
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1077
                r1._pack_collection.ensure_loaded()
1078
                r2._pack_collection.ensure_loaded()
1079
                self.assertEqual(r1._pack_collection.names(), r2._pack_collection.names())
1080
                self.assertEqual(1, len(r1._pack_collection.names()))
1081
                self.assertFalse(name_to_drop in r1._pack_collection.names())
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
1082
            finally:
2939.1.1 by Martin Pool
Fix up mismatched lock/unlock pairs.
1083
                r2.unlock()
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
1084
        finally:
2939.1.1 by Martin Pool
Fix up mismatched lock/unlock pairs.
1085
            r1.unlock()
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
1086
1087
    def test_lock_write_does_not_physically_lock(self):
1088
        repo = self.make_repository('.', format=self.get_format())
1089
        repo.lock_write()
1090
        self.addCleanup(repo.unlock)
1091
        self.assertFalse(repo.get_physical_lock_status())
1092
1093
    def prepare_for_break_lock(self):
2592.3.219 by Robert Collins
Review feedback.
1094
        # Setup the global ui factory state so that a break-lock method call
1095
        # will find usable input in the input stream.
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
1096
        old_factory = bzrlib.ui.ui_factory
1097
        def restoreFactory():
1098
            bzrlib.ui.ui_factory = old_factory
1099
        self.addCleanup(restoreFactory)
1100
        bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
1101
        bzrlib.ui.ui_factory.stdin = StringIO("y\n")
1102
1103
    def test_break_lock_breaks_physical_lock(self):
1104
        repo = self.make_repository('.', format=self.get_format())
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1105
        repo._pack_collection.lock_names()
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
1106
        repo2 = repository.Repository.open('.')
1107
        self.assertTrue(repo.get_physical_lock_status())
1108
        self.prepare_for_break_lock()
1109
        repo2.break_lock()
1110
        self.assertFalse(repo.get_physical_lock_status())
1111
2592.3.240 by Martin Pool
Rename RepositoryPackCollection.release_names to _unlock_names
1112
    def test_broken_physical_locks_error_on__unlock_names_lock(self):
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
1113
        repo = self.make_repository('.', format=self.get_format())
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1114
        repo._pack_collection.lock_names()
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
1115
        self.assertTrue(repo.get_physical_lock_status())
1116
        repo2 = repository.Repository.open('.')
1117
        self.prepare_for_break_lock()
1118
        repo2.break_lock()
2592.3.240 by Martin Pool
Rename RepositoryPackCollection.release_names to _unlock_names
1119
        self.assertRaises(errors.LockBroken, repo._pack_collection._unlock_names)
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
1120
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
1121
    def test_fetch_without_find_ghosts_ignores_ghosts(self):
1122
        # we want two repositories at this point:
1123
        # one with a revision that is a ghost in the other
1124
        # repository.
1125
        # 'ghost' is present in has_ghost, 'ghost' is absent in 'missing_ghost'.
1126
        # 'references' is present in both repositories, and 'tip' is present
1127
        # just in has_ghost.
1128
        # has_ghost       missing_ghost
1129
        #------------------------------
1130
        # 'ghost'             -
1131
        # 'references'    'references'
1132
        # 'tip'               -
1133
        # In this test we fetch 'tip' which should not fetch 'ghost'
1134
        has_ghost = self.make_repository('has_ghost', format=self.get_format())
1135
        missing_ghost = self.make_repository('missing_ghost',
1136
            format=self.get_format())
1137
1138
        def add_commit(repo, revision_id, parent_ids):
1139
            repo.lock_write()
1140
            repo.start_write_group()
1141
            inv = inventory.Inventory(revision_id=revision_id)
1142
            inv.root.revision = revision_id
1143
            root_id = inv.root.file_id
1144
            sha1 = repo.add_inventory(revision_id, inv, [])
1145
            vf = repo.weave_store.get_weave_or_empty(root_id,
1146
                repo.get_transaction())
1147
            vf.add_lines(revision_id, [], [])
1148
            rev = bzrlib.revision.Revision(timestamp=0,
1149
                                           timezone=None,
1150
                                           committer="Foo Bar <foo@example.com>",
1151
                                           message="Message",
1152
                                           inventory_sha1=sha1,
1153
                                           revision_id=revision_id)
1154
            rev.parent_ids = parent_ids
1155
            repo.add_revision(revision_id, rev)
1156
            repo.commit_write_group()
1157
            repo.unlock()
1158
        add_commit(has_ghost, 'ghost', [])
1159
        add_commit(has_ghost, 'references', ['ghost'])
1160
        add_commit(missing_ghost, 'references', ['ghost'])
1161
        add_commit(has_ghost, 'tip', ['references'])
1162
        missing_ghost.fetch(has_ghost, 'tip')
1163
        # missing ghost now has tip and not ghost.
1164
        rev = missing_ghost.get_revision('tip')
1165
        inv = missing_ghost.get_inventory('tip')
1166
        self.assertRaises(errors.NoSuchRevision,
1167
            missing_ghost.get_revision, 'ghost')
1168
        self.assertRaises(errors.RevisionNotPresent,
1169
            missing_ghost.get_inventory, 'ghost')
1170
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
1171
2939.2.1 by Ian Clatworthy
use 'knitpack' naming instead of 'experimental' for pack formats
1172
class TestKnitPackSubtrees(TestKnitPackNoSubtrees):
2592.3.173 by Robert Collins
Basic implementation of all_packs.
1173
1174
    def get_format(self):
2939.2.5 by Ian Clatworthy
review feedback from lifeless
1175
        return bzrdir.format_registry.make_bzrdir(
3010.3.3 by Martin Pool
Merge trunk
1176
            'pack-0.92-subtree')
2592.3.173 by Robert Collins
Basic implementation of all_packs.
1177
1178
    def check_format(self, t):
2939.2.5 by Ian Clatworthy
review feedback from lifeless
1179
        self.assertEqualDiff(
2939.2.7 by Ian Clatworthy
fix strings used in on-disk unit tests
1180
            "Bazaar pack repository format 1 with subtree support (needs bzr 0.92)\n",
2939.2.5 by Ian Clatworthy
review feedback from lifeless
1181
            t.get('format').read())
2592.3.173 by Robert Collins
Basic implementation of all_packs.
1182
1183
2592.3.84 by Robert Collins
Start of autopacking logic.
1184
class TestRepositoryPackCollection(TestCaseWithTransport):
1185
1186
    def get_format(self):
3010.3.3 by Martin Pool
Merge trunk
1187
        return bzrdir.format_registry.make_bzrdir('pack-0.92')
2592.3.84 by Robert Collins
Start of autopacking logic.
1188
1189
    def test__max_pack_count(self):
2592.3.219 by Robert Collins
Review feedback.
1190
        """The maximum pack count is a function of the number of revisions."""
2592.3.84 by Robert Collins
Start of autopacking logic.
1191
        format = self.get_format()
1192
        repo = self.make_repository('.', format=format)
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1193
        packs = repo._pack_collection
2592.3.84 by Robert Collins
Start of autopacking logic.
1194
        # no revisions - one pack, so that we can have a revision free repo
1195
        # without it blowing up
1196
        self.assertEqual(1, packs._max_pack_count(0))
1197
        # after that the sum of the digits, - check the first 1-9
1198
        self.assertEqual(1, packs._max_pack_count(1))
1199
        self.assertEqual(2, packs._max_pack_count(2))
1200
        self.assertEqual(3, packs._max_pack_count(3))
1201
        self.assertEqual(4, packs._max_pack_count(4))
1202
        self.assertEqual(5, packs._max_pack_count(5))
1203
        self.assertEqual(6, packs._max_pack_count(6))
1204
        self.assertEqual(7, packs._max_pack_count(7))
1205
        self.assertEqual(8, packs._max_pack_count(8))
1206
        self.assertEqual(9, packs._max_pack_count(9))
1207
        # check the boundary cases with two digits for the next decade
1208
        self.assertEqual(1, packs._max_pack_count(10))
1209
        self.assertEqual(2, packs._max_pack_count(11))
1210
        self.assertEqual(10, packs._max_pack_count(19))
1211
        self.assertEqual(2, packs._max_pack_count(20))
1212
        self.assertEqual(3, packs._max_pack_count(21))
1213
        # check some arbitrary big numbers
1214
        self.assertEqual(25, packs._max_pack_count(112894))
1215
1216
    def test_pack_distribution_zero(self):
1217
        format = self.get_format()
1218
        repo = self.make_repository('.', format=format)
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1219
        packs = repo._pack_collection
2592.3.84 by Robert Collins
Start of autopacking logic.
1220
        self.assertEqual([0], packs.pack_distribution(0))
3052.1.6 by John Arbash Meinel
Change the lock check to raise ObjectNotLocked.
1221
1222
    def test_ensure_loaded_unlocked(self):
1223
        format = self.get_format()
1224
        repo = self.make_repository('.', format=format)
1225
        self.assertRaises(errors.ObjectNotLocked,
1226
                          repo._pack_collection.ensure_loaded)
1227
2592.3.84 by Robert Collins
Start of autopacking logic.
1228
    def test_pack_distribution_one_to_nine(self):
1229
        format = self.get_format()
1230
        repo = self.make_repository('.', format=format)
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1231
        packs = repo._pack_collection
2592.3.84 by Robert Collins
Start of autopacking logic.
1232
        self.assertEqual([1],
1233
            packs.pack_distribution(1))
1234
        self.assertEqual([1, 1],
1235
            packs.pack_distribution(2))
1236
        self.assertEqual([1, 1, 1],
1237
            packs.pack_distribution(3))
1238
        self.assertEqual([1, 1, 1, 1],
1239
            packs.pack_distribution(4))
1240
        self.assertEqual([1, 1, 1, 1, 1],
1241
            packs.pack_distribution(5))
1242
        self.assertEqual([1, 1, 1, 1, 1, 1],
1243
            packs.pack_distribution(6))
1244
        self.assertEqual([1, 1, 1, 1, 1, 1, 1],
1245
            packs.pack_distribution(7))
1246
        self.assertEqual([1, 1, 1, 1, 1, 1, 1, 1],
1247
            packs.pack_distribution(8))
1248
        self.assertEqual([1, 1, 1, 1, 1, 1, 1, 1, 1],
1249
            packs.pack_distribution(9))
1250
1251
    def test_pack_distribution_stable_at_boundaries(self):
1252
        """When there are multi-rev packs the counts are stable."""
1253
        format = self.get_format()
1254
        repo = self.make_repository('.', format=format)
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1255
        packs = repo._pack_collection
2592.3.84 by Robert Collins
Start of autopacking logic.
1256
        # in 10s:
1257
        self.assertEqual([10], packs.pack_distribution(10))
1258
        self.assertEqual([10, 1], packs.pack_distribution(11))
1259
        self.assertEqual([10, 10], packs.pack_distribution(20))
1260
        self.assertEqual([10, 10, 1], packs.pack_distribution(21))
1261
        # 100s
1262
        self.assertEqual([100], packs.pack_distribution(100))
1263
        self.assertEqual([100, 1], packs.pack_distribution(101))
1264
        self.assertEqual([100, 10, 1], packs.pack_distribution(111))
1265
        self.assertEqual([100, 100], packs.pack_distribution(200))
1266
        self.assertEqual([100, 100, 1], packs.pack_distribution(201))
1267
        self.assertEqual([100, 100, 10, 1], packs.pack_distribution(211))
1268
2592.3.85 by Robert Collins
Finish autopack corner cases.
1269
    def test_plan_pack_operations_2009_revisions_skip_all_packs(self):
1270
        format = self.get_format()
1271
        repo = self.make_repository('.', format=format)
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1272
        packs = repo._pack_collection
2592.3.85 by Robert Collins
Finish autopack corner cases.
1273
        existing_packs = [(2000, "big"), (9, "medium")]
1274
        # rev count - 2009 -> 2x1000 + 9x1
1275
        pack_operations = packs.plan_autopack_combinations(
1276
            existing_packs, [1000, 1000, 1, 1, 1, 1, 1, 1, 1, 1, 1])
1277
        self.assertEqual([], pack_operations)
1278
1279
    def test_plan_pack_operations_2010_revisions_skip_all_packs(self):
1280
        format = self.get_format()
1281
        repo = self.make_repository('.', format=format)
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1282
        packs = repo._pack_collection
2592.3.85 by Robert Collins
Finish autopack corner cases.
1283
        existing_packs = [(2000, "big"), (9, "medium"), (1, "single")]
1284
        # rev count - 2010 -> 2x1000 + 1x10
1285
        pack_operations = packs.plan_autopack_combinations(
1286
            existing_packs, [1000, 1000, 10])
1287
        self.assertEqual([], pack_operations)
1288
1289
    def test_plan_pack_operations_2010_combines_smallest_two(self):
1290
        format = self.get_format()
1291
        repo = self.make_repository('.', format=format)
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1292
        packs = repo._pack_collection
2592.3.85 by Robert Collins
Finish autopack corner cases.
1293
        existing_packs = [(1999, "big"), (9, "medium"), (1, "single2"),
1294
            (1, "single1")]
1295
        # rev count - 2010 -> 2x1000 + 1x10 (3)
1296
        pack_operations = packs.plan_autopack_combinations(
1297
            existing_packs, [1000, 1000, 10])
1298
        self.assertEqual([[2, ["single2", "single1"]], [0, []]], pack_operations)
1299
2592.3.173 by Robert Collins
Basic implementation of all_packs.
1300
    def test_all_packs_none(self):
1301
        format = self.get_format()
1302
        tree = self.make_branch_and_tree('.', format=format)
1303
        tree.lock_read()
1304
        self.addCleanup(tree.unlock)
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1305
        packs = tree.branch.repository._pack_collection
2592.3.173 by Robert Collins
Basic implementation of all_packs.
1306
        packs.ensure_loaded()
1307
        self.assertEqual([], packs.all_packs())
1308
1309
    def test_all_packs_one(self):
1310
        format = self.get_format()
1311
        tree = self.make_branch_and_tree('.', format=format)
1312
        tree.commit('start')
1313
        tree.lock_read()
1314
        self.addCleanup(tree.unlock)
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1315
        packs = tree.branch.repository._pack_collection
2592.3.173 by Robert Collins
Basic implementation of all_packs.
1316
        packs.ensure_loaded()
2592.3.176 by Robert Collins
Various pack refactorings.
1317
        self.assertEqual([
1318
            packs.get_pack_by_name(packs.names()[0])],
1319
            packs.all_packs())
2592.3.173 by Robert Collins
Basic implementation of all_packs.
1320
1321
    def test_all_packs_two(self):
1322
        format = self.get_format()
1323
        tree = self.make_branch_and_tree('.', format=format)
1324
        tree.commit('start')
1325
        tree.commit('continue')
1326
        tree.lock_read()
1327
        self.addCleanup(tree.unlock)
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1328
        packs = tree.branch.repository._pack_collection
2592.3.173 by Robert Collins
Basic implementation of all_packs.
1329
        packs.ensure_loaded()
1330
        self.assertEqual([
2592.3.176 by Robert Collins
Various pack refactorings.
1331
            packs.get_pack_by_name(packs.names()[0]),
1332
            packs.get_pack_by_name(packs.names()[1]),
2592.3.173 by Robert Collins
Basic implementation of all_packs.
1333
            ], packs.all_packs())
1334
2592.3.176 by Robert Collins
Various pack refactorings.
1335
    def test_get_pack_by_name(self):
1336
        format = self.get_format()
1337
        tree = self.make_branch_and_tree('.', format=format)
1338
        tree.commit('start')
1339
        tree.lock_read()
1340
        self.addCleanup(tree.unlock)
2592.3.232 by Martin Pool
Disambiguate two member variables called _packs into _packs_by_name and _pack_collection
1341
        packs = tree.branch.repository._pack_collection
2592.3.176 by Robert Collins
Various pack refactorings.
1342
        packs.ensure_loaded()
1343
        name = packs.names()[0]
1344
        pack_1 = packs.get_pack_by_name(name)
1345
        # the pack should be correctly initialised
1346
        rev_index = GraphIndex(packs._index_transport, name + '.rix',
1347
            packs._names[name][0])
1348
        inv_index = GraphIndex(packs._index_transport, name + '.iix',
1349
            packs._names[name][1])
1350
        txt_index = GraphIndex(packs._index_transport, name + '.tix',
1351
            packs._names[name][2])
1352
        sig_index = GraphIndex(packs._index_transport, name + '.six',
1353
            packs._names[name][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.
1354
        self.assertEqual(pack_repo.ExistingPack(packs._pack_transport,
2592.3.219 by Robert Collins
Review feedback.
1355
            name, rev_index, inv_index, txt_index, sig_index), pack_1)
2592.3.176 by Robert Collins
Various pack refactorings.
1356
        # and the same instance should be returned on successive calls.
1357
        self.assertTrue(pack_1 is packs.get_pack_by_name(name))
1358
2592.3.173 by Robert Collins
Basic implementation of all_packs.
1359
1360
class TestPack(TestCaseWithTransport):
1361
    """Tests for the Pack object."""
1362
1363
    def assertCurrentlyEqual(self, left, right):
1364
        self.assertTrue(left == right)
1365
        self.assertTrue(right == left)
1366
        self.assertFalse(left != right)
1367
        self.assertFalse(right != left)
1368
1369
    def assertCurrentlyNotEqual(self, left, right):
1370
        self.assertFalse(left == right)
1371
        self.assertFalse(right == left)
1372
        self.assertTrue(left != right)
1373
        self.assertTrue(right != left)
1374
1375
    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.
1376
        left = pack_repo.ExistingPack('', '', '', '', '', '')
1377
        right = pack_repo.ExistingPack('', '', '', '', '', '')
2592.3.173 by Robert Collins
Basic implementation of all_packs.
1378
        self.assertCurrentlyEqual(left, right)
1379
        # change all attributes and ensure equality changes as we do.
1380
        left.revision_index = 'a'
1381
        self.assertCurrentlyNotEqual(left, right)
1382
        right.revision_index = 'a'
1383
        self.assertCurrentlyEqual(left, right)
1384
        left.inventory_index = 'a'
1385
        self.assertCurrentlyNotEqual(left, right)
1386
        right.inventory_index = 'a'
1387
        self.assertCurrentlyEqual(left, right)
1388
        left.text_index = 'a'
1389
        self.assertCurrentlyNotEqual(left, right)
1390
        right.text_index = 'a'
1391
        self.assertCurrentlyEqual(left, right)
1392
        left.signature_index = 'a'
1393
        self.assertCurrentlyNotEqual(left, right)
1394
        right.signature_index = 'a'
1395
        self.assertCurrentlyEqual(left, right)
1396
        left.name = 'a'
1397
        self.assertCurrentlyNotEqual(left, right)
1398
        right.name = 'a'
1399
        self.assertCurrentlyEqual(left, right)
1400
        left.transport = 'a'
1401
        self.assertCurrentlyNotEqual(left, right)
1402
        right.transport = 'a'
1403
        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.
1404
1405
    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.
1406
        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.
1407
        self.assertEqual('a_name.pack', pack.file_name())
2592.3.192 by Robert Collins
Move new revision index management to NewPack.
1408
1409
1410
class TestNewPack(TestCaseWithTransport):
1411
    """Tests for pack_repo.NewPack."""
1412
2592.3.193 by Robert Collins
Move hash tracking of new packs into NewPack.
1413
    def test_new_instance_attributes(self):
2592.3.194 by Robert Collins
Output the revision index from NewPack.finish
1414
        upload_transport = self.get_transport('upload')
1415
        pack_transport = self.get_transport('pack')
1416
        index_transport = self.get_transport('index')
1417
        upload_transport.mkdir('.')
1418
        pack = pack_repo.NewPack(upload_transport, index_transport,
1419
            pack_transport)
2592.3.192 by Robert Collins
Move new revision index management to NewPack.
1420
        self.assertIsInstance(pack.revision_index, InMemoryGraphIndex)
2592.3.195 by Robert Collins
Move some inventory index logic to NewPack.
1421
        self.assertIsInstance(pack.inventory_index, InMemoryGraphIndex)
2592.3.193 by Robert Collins
Move hash tracking of new packs into NewPack.
1422
        self.assertIsInstance(pack._hash, type(md5.new()))
2592.3.194 by Robert Collins
Output the revision index from NewPack.finish
1423
        self.assertTrue(pack.upload_transport is upload_transport)
1424
        self.assertTrue(pack.index_transport is index_transport)
1425
        self.assertTrue(pack.pack_transport is pack_transport)
1426
        self.assertEqual(None, pack.index_sizes)
1427
        self.assertEqual(20, len(pack.random_name))
1428
        self.assertIsInstance(pack.random_name, str)
1429
        self.assertIsInstance(pack.start_time, float)
2951.1.2 by Robert Collins
Partial refactoring of pack_repo to create a Packer object for packing.
1430
1431
1432
class TestPacker(TestCaseWithTransport):
1433
    """Tests for the packs repository Packer class."""
2951.1.10 by Robert Collins
Peer review feedback with Ian.
1434
1435
    # To date, this class has been factored out and nothing new added to it;
1436
    # thus there are not yet any tests.
3146.6.1 by Aaron Bentley
InterDifferingSerializer shows a progress bar
1437
1438
1439
class TestInterDifferingSerializer(TestCaseWithTransport):
1440
1441
    def test_progress_bar(self):
1442
        tree = self.make_branch_and_tree('tree')
1443
        tree.commit('rev1', rev_id='rev-1')
1444
        tree.commit('rev2', rev_id='rev-2')
1445
        tree.commit('rev3', rev_id='rev-3')
1446
        repo = self.make_repository('repo')
1447
        inter_repo = repository.InterDifferingSerializer(
1448
            tree.branch.repository, repo)
1449
        pb = progress.InstrumentedProgress(to_file=StringIO())
1450
        pb.never_throttle = True
1451
        inter_repo.fetch('rev-1', pb)
1452
        self.assertEqual('Transferring revisions', pb.last_msg)
1453
        self.assertEqual(1, pb.last_cnt)
1454
        self.assertEqual(1, pb.last_total)
1455
        inter_repo.fetch('rev-3', pb)
1456
        self.assertEqual(2, pb.last_cnt)
1457
        self.assertEqual(2, pb.last_total)