/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
1
# Copyright (C) 2005, 2006 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
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 InterRepository implementastions."""
18
1711.7.18 by John Arbash Meinel
Old repository formats didn't support double locking on win32, don't raise errors
19
import sys
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
20
1534.1.31 by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo.
21
import bzrlib
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
22
import bzrlib.bzrdir as bzrdir
23
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
24
import bzrlib.errors as errors
25
from bzrlib.errors import (FileExists,
26
                           NoSuchRevision,
27
                           NoSuchFile,
28
                           UninitializableFormat,
29
                           NotBranchError,
30
                           )
3302.5.3 by Vincent Ladeuil
Fix another test bug revealed when run alone.
31
import bzrlib.gpg
1731.1.1 by Aaron Bentley
Make root entry an InventoryDirectory, make EmptyTree really empty
32
from bzrlib.inventory import Inventory
2321.2.3 by Alexander Belchenko
fix for check_repo_format_for_funky_id_on_win32 after Martin's refactoring of repository format
33
import bzrlib.repofmt.weaverepo as weaverepo
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
34
import bzrlib.repository as repository
1694.2.6 by Martin Pool
[merge] bzr.dev
35
from bzrlib.revision import NULL_REVISION, Revision
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
36
from bzrlib.symbol_versioning import one_two
2814.1.1 by Robert Collins
* Pushing, pulling and branching branches with subtree references was not
37
from bzrlib.tests import (
38
    TestCase,
39
    TestCaseWithTransport,
40
    TestNotApplicable,
41
    TestSkipped,
42
    )
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
43
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
44
from bzrlib.transport import get_transport
45
46
47
class TestCaseWithInterRepository(TestCaseWithBzrDir):
48
49
    def setUp(self):
50
        super(TestCaseWithInterRepository, self).setUp()
51
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
52
    def make_branch(self, relpath, format=None):
53
        repo = self.make_repository(relpath, format=format)
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
54
        return repo.bzrdir.create_branch()
55
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
56
    def make_bzrdir(self, relpath, format=None):
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
57
        try:
58
            url = self.get_url(relpath)
59
            segments = url.split('/')
60
            if segments and segments[-1] not in ('', '.'):
61
                parent = '/'.join(segments[:-1])
62
                t = get_transport(parent)
63
                try:
64
                    t.mkdir(segments[-1])
65
                except FileExists:
66
                    pass
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
67
            if format is None:
68
                format = self.repository_format._matchingbzrdir
69
            return format.initialize(url)
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
70
        except UninitializableFormat:
1684.1.4 by Martin Pool
(patch) better warnings when tests are skipped (Alexander)
71
            raise TestSkipped("Format %s is not initializable." % format)
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
72
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
73
    def make_repository(self, relpath, format=None):
74
        made_control = self.make_bzrdir(relpath, format=format)
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
75
        return self.repository_format.initialize(made_control)
76
77
    def make_to_repository(self, relpath):
78
        made_control = self.make_bzrdir(relpath,
79
            self.repository_format_to._matchingbzrdir)
1534.1.30 by Robert Collins
Test that we get the right optimiser back in the InterRepository tests.
80
        return self.repository_format_to.initialize(made_control)
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
81
82
1711.7.18 by John Arbash Meinel
Old repository formats didn't support double locking on win32, don't raise errors
83
def check_old_format_lock_error(repository_format):
84
    """Potentially ignore LockError on old formats.
85
86
    On win32, with the old OS locks, we get a failure of double-lock when
87
    we open a object in 2 objects and try to lock both.
88
89
    On new formats, LockError would be invalid, but for old formats
90
    this was not supported on Win32.
91
    """
92
    if sys.platform != 'win32':
93
        raise
94
95
    description = repository_format.get_format_description()
96
    if description in ("Repository format 4",
97
                       "Weave repository format 5",
98
                       "Weave repository format 6"):
1711.7.30 by John Arbash Meinel
Switch to using TestSkipped for old win32 problems
99
        # jam 20060701
100
        # win32 OS locks are not re-entrant. So one process cannot
101
        # open the same repository twice and lock them both.
102
        raise TestSkipped('%s on win32 cannot open the same'
103
                          ' repository twice in different objects'
104
                          % description)
1711.7.18 by John Arbash Meinel
Old repository formats didn't support double locking on win32, don't raise errors
105
    raise
106
107
2240.1.3 by Alexander Belchenko
win32: skip tests that try to use funky chars in fileid in Weave-based repositories
108
def check_repo_format_for_funky_id_on_win32(repo):
2321.2.3 by Alexander Belchenko
fix for check_repo_format_for_funky_id_on_win32 after Martin's refactoring of repository format
109
    if (isinstance(repo, (weaverepo.AllInOneRepository,
110
                          weaverepo.WeaveMetaDirRepository))
111
        and sys.platform == 'win32'):
2240.1.3 by Alexander Belchenko
win32: skip tests that try to use funky chars in fileid in Weave-based repositories
112
            raise TestSkipped("funky chars does not permitted"
113
                              " on this platform in repository"
114
                              " %s" % repo.__class__.__name__)
115
116
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
117
class TestInterRepository(TestCaseWithInterRepository):
118
1534.1.30 by Robert Collins
Test that we get the right optimiser back in the InterRepository tests.
119
    def test_interrepository_get_returns_correct_optimiser(self):
120
        # we assume the optimising code paths are triggered
121
        # by the type of the repo not the transport - at this point.
122
        # we may need to update this test if this changes.
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
123
        #
124
        # XXX: This code tests that we get an InterRepository when we try to
125
        # convert between the two repositories that it wants to be tested with
126
        # -- but that's not necessarily correct.  So for now this is disabled.
127
        # mbp 20070206
128
        ## source_repo = self.make_repository("source")
129
        ## target_repo = self.make_to_repository("target")
130
        ## interrepo = repository.InterRepository.get(source_repo, target_repo)
131
        ## self.assertEqual(self.interrepo_class, interrepo.__class__)
132
        pass
1534.1.30 by Robert Collins
Test that we get the right optimiser back in the InterRepository tests.
133
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
134
    def test_fetch(self):
135
        tree_a = self.make_branch_and_tree('a')
136
        self.build_tree(['a/foo'])
137
        tree_a.add('foo', 'file1')
138
        tree_a.commit('rev1', rev_id='rev1')
139
        def check_push_rev1(repo):
140
            # ensure the revision is missing.
141
            self.assertRaises(NoSuchRevision, repo.get_revision, 'rev1')
1534.1.31 by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo.
142
            # fetch with a limit of NULL_REVISION and an explicit progress bar.
143
            repo.fetch(tree_a.branch.repository,
144
                       revision_id=NULL_REVISION,
145
                       pb=bzrlib.progress.DummyProgress())
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
146
            # nothing should have been pushed
147
            self.assertFalse(repo.has_revision('rev1'))
148
            # fetch with a default limit (grab everything)
149
            repo.fetch(tree_a.branch.repository)
150
            # check that b now has all the data from a's first commit.
151
            rev = repo.get_revision('rev1')
152
            tree = repo.revision_tree('rev1')
2592.3.214 by Robert Collins
Merge bzr.dev.
153
            tree.lock_read()
154
            self.addCleanup(tree.unlock)
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
155
            tree.get_file_text('file1')
156
            for file_id in tree:
157
                if tree.inventory[file_id].kind == "file":
158
                    tree.get_file(file_id).read()
159
1534.1.31 by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo.
160
        # makes a target version repo 
161
        repo_b = self.make_to_repository('b')
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
162
        check_push_rev1(repo_b)
3035.2.2 by John Arbash Meinel
Add an interrepository test that when we are missing a basis text,
163
164
    def test_fetch_missing_basis_text(self):
165
        """If fetching a delta, we should die if a basis is not present."""
166
        tree = self.make_branch_and_tree('tree')
167
        self.build_tree(['tree/a'])
168
        tree.add(['a'], ['a-id'])
169
        tree.commit('one', rev_id='rev-one')
170
        self.build_tree_contents([('tree/a', 'new contents\n')])
171
        tree.commit('two', rev_id='rev-two')
172
173
        to_repo = self.make_to_repository('to_repo')
174
        # We build a broken revision so that we can test the fetch code dies
175
        # properly. So copy the inventory and revision, but not the text.
176
        to_repo.lock_write()
177
        try:
178
            to_repo.start_write_group()
179
            inv = tree.branch.repository.get_inventory('rev-one')
180
            to_repo.add_inventory('rev-one', inv, [])
181
            rev = tree.branch.repository.get_revision('rev-one')
182
            to_repo.add_revision('rev-one', rev, inv=inv)
183
            to_repo.commit_write_group()
184
        finally:
185
            to_repo.unlock()
186
187
        # Implementations can either copy the missing basis text, or raise an
188
        # exception
189
        try:
190
            to_repo.fetch(tree.branch.repository, 'rev-two')
3035.2.6 by John Arbash Meinel
Suggested by Robert: Move the missing externals check into part of Packer.pack()
191
        except errors.RevisionNotPresent, e:
3035.2.2 by John Arbash Meinel
Add an interrepository test that when we are missing a basis text,
192
            # If an exception is raised, the revision should not be in the
193
            # target.
194
            self.assertRaises((errors.NoSuchRevision, errors.RevisionNotPresent),
195
                              to_repo.revision_tree, 'rev-two')
196
        else:
197
            # If not exception is raised, then the basis text should be
198
            # available.
199
            to_repo.lock_read()
200
            try:
201
                rt = to_repo.revision_tree('rev-one')
202
                self.assertEqual('contents of tree/a\n',
203
                                 rt.get_file_text('a-id'))
204
            finally:
205
                to_repo.unlock()
206
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
207
    def test_fetch_missing_revision_same_location_fails(self):
208
        repo_a = self.make_repository('.')
209
        repo_b = repository.Repository.open('.')
1711.7.18 by John Arbash Meinel
Old repository formats didn't support double locking on win32, don't raise errors
210
        try:
211
            self.assertRaises(errors.NoSuchRevision, repo_b.fetch, repo_a, revision_id='XXX')
212
        except errors.LockError, e:
213
            check_old_format_lock_error(self.repository_format)
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
214
215
    def test_fetch_same_location_trivial_works(self):
216
        repo_a = self.make_repository('.')
217
        repo_b = repository.Repository.open('.')
1711.7.18 by John Arbash Meinel
Old repository formats didn't support double locking on win32, don't raise errors
218
        try:
219
            repo_a.fetch(repo_b)
220
        except errors.LockError, e:
221
            check_old_format_lock_error(self.repository_format)
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
222
1694.2.6 by Martin Pool
[merge] bzr.dev
223
    def test_fetch_missing_text_other_location_fails(self):
224
        source_tree = self.make_branch_and_tree('source')
225
        source = source_tree.branch.repository
226
        target = self.make_to_repository('target')
227
    
2592.3.145 by Robert Collins
Fix test_fetch_missing_text_other_location_fails for pack repositories.
228
        # start by adding a file so the data knit for the file exists in
229
        # repositories that have specific files for each fileid.
1694.2.6 by Martin Pool
[merge] bzr.dev
230
        self.build_tree(['source/id'])
231
        source_tree.add(['id'], ['id'])
232
        source_tree.commit('a', rev_id='a')
233
        # now we manually insert a revision with an inventory referencing
234
        # 'id' at revision 'b', but we do not insert revision b.
235
        # this should ensure that the new versions of files are being checked
236
        # for during pull operations
237
        inv = source.get_inventory('a')
2617.6.2 by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit.
238
        source.lock_write()
3381.1.2 by Aaron Bentley
Cleanup
239
        self.addCleanup(source.unlock)
2617.6.2 by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit.
240
        source.start_write_group()
1694.2.6 by Martin Pool
[merge] bzr.dev
241
        inv['id'].revision = 'b'
1740.2.6 by Aaron Bentley
Update test for new interface
242
        inv.revision_id = 'b'
2592.3.119 by Robert Collins
Merge some test fixes from Martin.
243
        sha1 = source.add_inventory('b', inv, ['a'])
1694.2.6 by Martin Pool
[merge] bzr.dev
244
        rev = Revision(timestamp=0,
245
                       timezone=None,
246
                       committer="Foo Bar <foo@example.com>",
247
                       message="Message",
248
                       inventory_sha1=sha1,
249
                       revision_id='b')
250
        rev.parent_ids = ['a']
251
        source.add_revision('b', rev)
2617.6.2 by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit.
252
        source.commit_write_group()
1694.2.6 by Martin Pool
[merge] bzr.dev
253
        self.assertRaises(errors.RevisionNotPresent, target.fetch, source)
254
        self.assertFalse(target.has_revision('b'))
255
1843.2.1 by Aaron Bentley
Add failing tests for funky ids
256
    def test_fetch_funky_file_id(self):
257
        from_tree = self.make_branch_and_tree('tree')
2240.1.3 by Alexander Belchenko
win32: skip tests that try to use funky chars in fileid in Weave-based repositories
258
        if sys.platform == 'win32':
259
            from_repo = from_tree.branch.repository
260
            check_repo_format_for_funky_id_on_win32(from_repo)
1843.2.1 by Aaron Bentley
Add failing tests for funky ids
261
        self.build_tree(['tree/filename'])
262
        from_tree.add('filename', 'funky-chars<>%&;"\'')
263
        from_tree.commit('commit filename')
264
        to_repo = self.make_to_repository('to')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
265
        to_repo.fetch(from_tree.branch.repository, from_tree.get_parent_ids()[0])
1843.2.1 by Aaron Bentley
Add failing tests for funky ids
266
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
267
268
class TestCaseWithComplexRepository(TestCaseWithInterRepository):
269
270
    def setUp(self):
271
        super(TestCaseWithComplexRepository, self).setUp()
272
        tree_a = self.make_branch_and_tree('a')
273
        self.bzrdir = tree_a.branch.bzrdir
274
        # add a corrupt inventory 'orphan'
2592.3.91 by Robert Collins
Incrementally closing in on a correct fetch for packs.
275
        tree_a.branch.repository.lock_write()
276
        tree_a.branch.repository.start_write_group()
277
        inv_file = tree_a.branch.repository.get_inventory_weave()
1563.2.10 by Robert Collins
Change weave store to be a versioned store, using WeaveFiles which maintain integrity without needing explicit 'put' operations.
278
        inv_file.add_lines('orphan', [], [])
2592.3.91 by Robert Collins
Incrementally closing in on a correct fetch for packs.
279
        tree_a.branch.repository.commit_write_group()
280
        tree_a.branch.repository.unlock()
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
281
        # add a real revision 'rev1'
282
        tree_a.commit('rev1', rev_id='rev1', allow_pointless=True)
283
        # add a real revision 'rev2' based on rev1
284
        tree_a.commit('rev2', rev_id='rev2', allow_pointless=True)
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.
285
        # and sign 'rev2'
2592.3.96 by Robert Collins
Merge index improvements (includes bzr.dev).
286
        tree_a.branch.repository.lock_write()
287
        tree_a.branch.repository.start_write_group()
288
        tree_a.branch.repository.sign_revision('rev2', bzrlib.gpg.LoopbackGPGStrategy(None))
289
        tree_a.branch.repository.commit_write_group()
290
        tree_a.branch.repository.unlock()
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
291
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
292
    def test_missing_revision_ids_is_deprecated(self):
293
        repo_b = self.make_to_repository('rev1_only')
294
        repo_a = self.bzrdir.open_repository()
295
        repo_b.fetch(repo_a, 'rev1')
296
        # check the test will be valid
297
        self.assertFalse(repo_b.has_revision('rev2'))
298
        self.assertEqual(['rev2'],
299
            self.applyDeprecated(one_two, repo_b.missing_revision_ids, repo_a))
300
        inter = repository.InterRepository.get(repo_a, repo_b)
301
        self.assertEqual(['rev2'],
302
            self.applyDeprecated(one_two, inter.missing_revision_ids, None,
303
                True))
304
305
    def test_search_missing_revision_ids(self):
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
306
        # revision ids in repository A but not B are returned, fake ones
307
        # are stripped. (fake meaning no revision object, but an inventory 
2592.3.146 by Robert Collins
Typo.
308
        # as some formats keyed off inventory data in the past.)
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
309
        # make a repository to compare against that claims to have rev1
310
        repo_b = self.make_to_repository('rev1_only')
311
        repo_a = self.bzrdir.open_repository()
312
        repo_b.fetch(repo_a, 'rev1')
313
        # check the test will be valid
314
        self.assertFalse(repo_b.has_revision('rev2'))
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
315
        result = repo_b.search_missing_revision_ids(repo_a)
316
        self.assertEqual(set(['rev2']), result.get_keys())
317
        self.assertEqual((set(['rev2']), set(['rev1']), 1), result.get_recipe())
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
318
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
319
    def test_search_missing_revision_ids_absent_requested_raises(self):
3010.1.5 by Robert Collins
Test that missing_revision_ids handles the case of the source not having the requested revision correctly with and without find_ghosts.
320
        # Asking for missing revisions with a tip that is itself absent in the
321
        # source raises NoSuchRevision.
322
        repo_b = self.make_to_repository('target')
323
        repo_a = self.bzrdir.open_repository()
324
        # No pizza revisions anywhere
325
        self.assertFalse(repo_a.has_revision('pizza'))
326
        self.assertFalse(repo_b.has_revision('pizza'))
327
        # Asking specifically for an absent revision errors.
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
328
        self.assertRaises(NoSuchRevision, repo_b.search_missing_revision_ids, repo_a,
3010.1.5 by Robert Collins
Test that missing_revision_ids handles the case of the source not having the requested revision correctly with and without find_ghosts.
329
            revision_id='pizza', find_ghosts=True)
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
330
        self.assertRaises(NoSuchRevision, repo_b.search_missing_revision_ids, repo_a,
3010.1.5 by Robert Collins
Test that missing_revision_ids handles the case of the source not having the requested revision correctly with and without find_ghosts.
331
            revision_id='pizza', find_ghosts=False)
332
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
333
    def test_search_missing_revision_ids_revision_limited(self):
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
334
        # revision ids in repository A that are not referenced by the
335
        # requested revision are not returned.
336
        # make a repository to compare against that is empty
337
        repo_b = self.make_to_repository('empty')
338
        repo_a = self.bzrdir.open_repository()
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
339
        result = repo_b.search_missing_revision_ids(repo_a, revision_id='rev1')
340
        self.assertEqual(set(['rev1']), result.get_keys())
341
        self.assertEqual((set(['rev1']), set([NULL_REVISION]), 1),
342
            result.get_recipe())
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.
343
        
2592.3.91 by Robert Collins
Incrementally closing in on a correct fetch for packs.
344
    def test_fetch_fetches_signatures_too(self):
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.
345
        from_repo = self.bzrdir.open_repository()
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
346
        from_signature = from_repo.get_signature_text('rev2')
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.
347
        to_repo = self.make_to_repository('target')
348
        to_repo.fetch(from_repo)
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
349
        to_signature = to_repo.get_signature_text('rev2')
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.
350
        self.assertEqual(from_signature, to_signature)
351
1570.1.14 by Robert Collins
Enforce repository consistency during 'fetch' operations.
352
353
class TestCaseWithGhosts(TestCaseWithInterRepository):
354
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
355
    def test_fetch_all_fixes_up_ghost(self):
356
        # we want two repositories at this point:
1570.1.14 by Robert Collins
Enforce repository consistency during 'fetch' operations.
357
        # one with a revision that is a ghost in the other
358
        # repository.
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
359
        # 'ghost' is present in has_ghost, 'ghost' is absent in 'missing_ghost'.
360
        # 'references' is present in both repositories, and 'tip' is present
361
        # just in has_ghost.
362
        # has_ghost       missing_ghost
363
        #------------------------------
364
        # 'ghost'             -
365
        # 'references'    'references'
366
        # 'tip'               -
367
        # In this test we fetch 'tip' which should not fetch 'ghost'
368
        has_ghost = self.make_repository('has_ghost')
369
        missing_ghost = self.make_repository('missing_ghost')
370
        if [True, True] != [repo._format.supports_ghosts for repo in
371
            (has_ghost, missing_ghost)]:
372
            raise TestNotApplicable("Need ghost support.")
373
374
        def add_commit(repo, revision_id, parent_ids):
375
            repo.lock_write()
376
            repo.start_write_group()
377
            inv = Inventory(revision_id=revision_id)
378
            inv.root.revision = revision_id
379
            root_id = inv.root.file_id
380
            sha1 = repo.add_inventory(revision_id, inv, parent_ids)
381
            vf = repo.weave_store.get_weave_or_empty(root_id,
382
                repo.get_transaction())
383
            vf.add_lines(revision_id, [], [])
384
            rev = bzrlib.revision.Revision(timestamp=0,
385
                                           timezone=None,
386
                                           committer="Foo Bar <foo@example.com>",
387
                                           message="Message",
388
                                           inventory_sha1=sha1,
389
                                           revision_id=revision_id)
390
            rev.parent_ids = parent_ids
391
            repo.add_revision(revision_id, rev)
392
            repo.commit_write_group()
393
            repo.unlock()
394
        add_commit(has_ghost, 'ghost', [])
395
        add_commit(has_ghost, 'references', ['ghost'])
396
        add_commit(missing_ghost, 'references', ['ghost'])
397
        add_commit(has_ghost, 'tip', ['references'])
398
        missing_ghost.fetch(has_ghost, 'tip', find_ghosts=True)
399
        # missing ghost now has tip and ghost.
400
        rev = missing_ghost.get_revision('tip')
401
        inv = missing_ghost.get_inventory('tip')
402
        rev = missing_ghost.get_revision('ghost')
403
        inv = missing_ghost.get_inventory('ghost')
1570.1.14 by Robert Collins
Enforce repository consistency during 'fetch' operations.
404
        # rev must not be corrupt now
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
405
        self.assertEqual([None, 'ghost', 'references', 'tip'],
406
            missing_ghost.get_ancestry('tip'))
2814.1.1 by Robert Collins
* Pushing, pulling and branching branches with subtree references was not
407
408
409
class TestFetchDependentData(TestCaseWithInterRepository):
410
411
    def test_reference(self):
412
        from_tree = self.make_branch_and_tree('tree')
413
        to_repo = self.make_to_repository('to')
414
        if (not from_tree.supports_tree_reference() or
415
            not from_tree.branch.repository._format.supports_tree_reference or
416
            not to_repo._format.supports_tree_reference):
417
            raise TestNotApplicable("Need subtree support.")
418
        subtree = self.make_branch_and_tree('tree/subtree')
419
        subtree.commit('subrev 1')
420
        from_tree.add_reference(subtree)
421
        tree_rev = from_tree.commit('foo')
422
        # now from_tree has a last-modified of subtree of the rev id of the
423
        # commit for foo, and a reference revision of the rev id of the commit
424
        # for subrev 1
425
        to_repo.fetch(from_tree.branch.repository, tree_rev)
426
        # to_repo should have a file_graph for from_tree.path2id('subtree') and
427
        # revid tree_rev.
2998.2.2 by John Arbash Meinel
implement a faster path for copying from packs back to knits.
428
        to_repo.lock_read()
429
        try:
430
            file_vf = to_repo.weave_store.get_weave(
431
                from_tree.path2id('subtree'), to_repo.get_transaction())
432
            self.assertEqual([tree_rev], file_vf.get_ancestry([tree_rev]))
433
        finally:
434
            to_repo.unlock()