/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.15 by John Arbash Meinel
Merge bzr.dev 5597 to resolve NEWS, aka bzr-2.3.txt
1
# Copyright (C) 2006-2009, 2011 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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
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.errors as errors
3302.5.3 by Vincent Ladeuil
Fix another test bug revealed when run alone.
23
import bzrlib.gpg
1731.1.1 by Aaron Bentley
Make root entry an InventoryDirectory, make EmptyTree really empty
24
from bzrlib.inventory import Inventory
5582.4.3 by Jelmer Vernooij
remove more unused imports, avoid relying on a specific set of working tree formats that support references.
25
from bzrlib.revision import NULL_REVISION
2814.1.1 by Robert Collins
* Pushing, pulling and branching branches with subtree references was not
26
from bzrlib.tests import (
27
    TestNotApplicable,
28
    TestSkipped,
29
    )
4523.1.3 by Martin Pool
Rename to per_interrepository
30
from bzrlib.tests.per_interrepository import (
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
31
    TestCaseWithInterRepository,
32
    )
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
33
34
2240.1.3 by Alexander Belchenko
win32: skip tests that try to use funky chars in fileid in Weave-based repositories
35
def check_repo_format_for_funky_id_on_win32(repo):
5582.9.1 by Jelmer Vernooij
Add flag for 'supports_funky_characters'.
36
    if not repo._format.supports_funky_characters and sys.platform == 'win32':
37
        raise TestSkipped("funky chars not allowed on this platform in repository"
38
                          " %s" % repo.__class__.__name__)
2240.1.3 by Alexander Belchenko
win32: skip tests that try to use funky chars in fileid in Weave-based repositories
39
40
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
41
class TestInterRepository(TestCaseWithInterRepository):
42
1534.1.30 by Robert Collins
Test that we get the right optimiser back in the InterRepository tests.
43
    def test_interrepository_get_returns_correct_optimiser(self):
44
        # we assume the optimising code paths are triggered
45
        # by the type of the repo not the transport - at this point.
46
        # 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.
47
        #
48
        # XXX: This code tests that we get an InterRepository when we try to
49
        # convert between the two repositories that it wants to be tested with
50
        # -- but that's not necessarily correct.  So for now this is disabled.
51
        # mbp 20070206
52
        ## source_repo = self.make_repository("source")
53
        ## target_repo = self.make_to_repository("target")
54
        ## interrepo = repository.InterRepository.get(source_repo, target_repo)
55
        ## self.assertEqual(self.interrepo_class, interrepo.__class__)
56
        pass
1534.1.30 by Robert Collins
Test that we get the right optimiser back in the InterRepository tests.
57
1843.2.1 by Aaron Bentley
Add failing tests for funky ids
58
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
59
class TestCaseWithComplexRepository(TestCaseWithInterRepository):
60
61
    def setUp(self):
62
        super(TestCaseWithComplexRepository, self).setUp()
63
        tree_a = self.make_branch_and_tree('a')
64
        self.bzrdir = tree_a.branch.bzrdir
65
        # add a corrupt inventory 'orphan'
2592.3.91 by Robert Collins
Incrementally closing in on a correct fetch for packs.
66
        tree_a.branch.repository.lock_write()
67
        tree_a.branch.repository.start_write_group()
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
68
        inv_file = tree_a.branch.repository.inventories
69
        inv_file.add_lines(('orphan',), [], [])
2592.3.91 by Robert Collins
Incrementally closing in on a correct fetch for packs.
70
        tree_a.branch.repository.commit_write_group()
71
        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.
72
        # add a real revision 'rev1'
73
        tree_a.commit('rev1', rev_id='rev1', allow_pointless=True)
74
        # add a real revision 'rev2' based on rev1
75
        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.
76
        # and sign 'rev2'
2592.3.96 by Robert Collins
Merge index improvements (includes bzr.dev).
77
        tree_a.branch.repository.lock_write()
78
        tree_a.branch.repository.start_write_group()
5582.9.1 by Jelmer Vernooij
Add flag for 'supports_funky_characters'.
79
        tree_a.branch.repository.sign_revision('rev2',
80
            bzrlib.gpg.LoopbackGPGStrategy(None))
2592.3.96 by Robert Collins
Merge index improvements (includes bzr.dev).
81
        tree_a.branch.repository.commit_write_group()
82
        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.
83
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
84
    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.
85
        # revision ids in repository A but not B are returned, fake ones
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
86
        # are stripped. (fake meaning no revision object, but an inventory
2592.3.146 by Robert Collins
Typo.
87
        # 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.
88
        # make a repository to compare against that claims to have rev1
89
        repo_b = self.make_to_repository('rev1_only')
90
        repo_a = self.bzrdir.open_repository()
91
        repo_b.fetch(repo_a, 'rev1')
92
        # check the test will be valid
93
        self.assertFalse(repo_b.has_revision('rev2'))
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
94
        result = repo_b.search_missing_revision_ids(repo_a)
95
        self.assertEqual(set(['rev2']), result.get_keys())
4152.1.2 by Robert Collins
Add streaming from a stacked branch when the sort order is compatible with doing so.
96
        self.assertEqual(('search', set(['rev2']), set(['rev1']), 1),
97
            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.
98
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
99
    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.
100
        # Asking for missing revisions with a tip that is itself absent in the
101
        # source raises NoSuchRevision.
102
        repo_b = self.make_to_repository('target')
103
        repo_a = self.bzrdir.open_repository()
104
        # No pizza revisions anywhere
105
        self.assertFalse(repo_a.has_revision('pizza'))
106
        self.assertFalse(repo_b.has_revision('pizza'))
107
        # Asking specifically for an absent revision errors.
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
108
        self.assertRaises(errors.NoSuchRevision,
5539.2.10 by Andrew Bennetts
s/NotInOtherForRev/NotInOtherForRevs/, and allow passing multiple revision_ids to search_missing_revision_ids.
109
            repo_b.search_missing_revision_ids, repo_a, revision_ids=['pizza'],
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
110
            find_ghosts=True)
111
        self.assertRaises(errors.NoSuchRevision,
5539.2.10 by Andrew Bennetts
s/NotInOtherForRev/NotInOtherForRevs/, and allow passing multiple revision_ids to search_missing_revision_ids.
112
            repo_b.search_missing_revision_ids, repo_a, revision_ids=['pizza'],
113
            find_ghosts=False)
114
        self.callDeprecated(
115
            ['search_missing_revision_ids(revision_id=...) was deprecated in '
5536.3.4 by Andrew Bennetts
Update an occurrence of '2.3' that should be '2.4'.
116
             '2.4.  Use revision_ids=[...] instead.'],
5539.2.10 by Andrew Bennetts
s/NotInOtherForRev/NotInOtherForRevs/, and allow passing multiple revision_ids to search_missing_revision_ids.
117
            self.assertRaises, errors.NoSuchRevision,
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
118
            repo_b.search_missing_revision_ids, repo_a, revision_id='pizza',
119
            find_ghosts=False)
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.
120
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
121
    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.
122
        # revision ids in repository A that are not referenced by the
123
        # requested revision are not returned.
124
        # make a repository to compare against that is empty
125
        repo_b = self.make_to_repository('empty')
126
        repo_a = self.bzrdir.open_repository()
5539.2.10 by Andrew Bennetts
s/NotInOtherForRev/NotInOtherForRevs/, and allow passing multiple revision_ids to search_missing_revision_ids.
127
        result = repo_b.search_missing_revision_ids(
128
            repo_a, revision_ids=['rev1'])
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
129
        self.assertEqual(set(['rev1']), result.get_keys())
4152.1.2 by Robert Collins
Add streaming from a stacked branch when the sort order is compatible with doing so.
130
        self.assertEqual(('search', set(['rev1']), set([NULL_REVISION]), 1),
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
131
            result.get_recipe())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
132
5852.1.6 by Jelmer Vernooij
Add extra test for Repository.search_missing_revision_ids.
133
    def test_search_missing_revision_ids_limit(self):
134
        # The limit= argument makes fetch() limit
135
        # the results to the first X topo-sorted revisions.
136
        repo_b = self.make_to_repository('rev1_only')
137
        repo_a = self.bzrdir.open_repository()
138
        # check the test will be valid
139
        self.assertFalse(repo_b.has_revision('rev2'))
140
        result = repo_b.search_missing_revision_ids(repo_a, limit=1)
5852.1.10 by Jelmer Vernooij
Use get_recipe.
141
        self.assertEqual(('search', set(['rev1']), set(['null:']), 1),
142
            result.get_recipe())
5852.1.6 by Jelmer Vernooij
Add extra test for Repository.search_missing_revision_ids.
143
2592.3.91 by Robert Collins
Incrementally closing in on a correct fetch for packs.
144
    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.
145
        from_repo = self.bzrdir.open_repository()
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
146
        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.
147
        to_repo = self.make_to_repository('target')
148
        to_repo.fetch(from_repo)
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
149
        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.
150
        self.assertEqual(from_signature, to_signature)
151
1570.1.14 by Robert Collins
Enforce repository consistency during 'fetch' operations.
152
153
class TestCaseWithGhosts(TestCaseWithInterRepository):
154
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
155
    def test_fetch_all_fixes_up_ghost(self):
156
        # we want two repositories at this point:
1570.1.14 by Robert Collins
Enforce repository consistency during 'fetch' operations.
157
        # one with a revision that is a ghost in the other
158
        # repository.
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
159
        # 'ghost' is present in has_ghost, 'ghost' is absent in 'missing_ghost'.
160
        # 'references' is present in both repositories, and 'tip' is present
161
        # just in has_ghost.
162
        # has_ghost       missing_ghost
163
        #------------------------------
164
        # 'ghost'             -
165
        # 'references'    'references'
166
        # 'tip'               -
167
        # In this test we fetch 'tip' which should not fetch 'ghost'
168
        has_ghost = self.make_repository('has_ghost')
169
        missing_ghost = self.make_repository('missing_ghost')
170
        if [True, True] != [repo._format.supports_ghosts for repo in
171
            (has_ghost, missing_ghost)]:
172
            raise TestNotApplicable("Need ghost support.")
173
174
        def add_commit(repo, revision_id, parent_ids):
175
            repo.lock_write()
176
            repo.start_write_group()
177
            inv = Inventory(revision_id=revision_id)
178
            inv.root.revision = revision_id
179
            root_id = inv.root.file_id
180
            sha1 = repo.add_inventory(revision_id, inv, parent_ids)
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
181
            repo.texts.add_lines((root_id, revision_id), [], [])
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
182
            rev = bzrlib.revision.Revision(timestamp=0,
183
                                           timezone=None,
184
                                           committer="Foo Bar <foo@example.com>",
185
                                           message="Message",
186
                                           inventory_sha1=sha1,
187
                                           revision_id=revision_id)
188
            rev.parent_ids = parent_ids
189
            repo.add_revision(revision_id, rev)
190
            repo.commit_write_group()
191
            repo.unlock()
192
        add_commit(has_ghost, 'ghost', [])
193
        add_commit(has_ghost, 'references', ['ghost'])
194
        add_commit(missing_ghost, 'references', ['ghost'])
195
        add_commit(has_ghost, 'tip', ['references'])
196
        missing_ghost.fetch(has_ghost, 'tip', find_ghosts=True)
197
        # missing ghost now has tip and ghost.
198
        rev = missing_ghost.get_revision('tip')
199
        inv = missing_ghost.get_inventory('tip')
200
        rev = missing_ghost.get_revision('ghost')
201
        inv = missing_ghost.get_inventory('ghost')
1570.1.14 by Robert Collins
Enforce repository consistency during 'fetch' operations.
202
        # rev must not be corrupt now
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
203
        self.assertEqual([None, 'ghost', 'references', 'tip'],
204
            missing_ghost.get_ancestry('tip'))