/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4543.2.2 by John Arbash Meinel
work out some tests that expose that bundles don't work w/ 2a formats.
1
# Copyright (C) 2006, 2007, 2008, 2009 Canonical Ltd
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
2
# Authors: Robert Collins <robert.collins@canonical.com>
2241.1.1 by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary
3
#          and others
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
4
#
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
9
#
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
14
#
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
18
19
1904.2.5 by Martin Pool
Fix format warning inside test suite and add test
20
"""Repository implementation tests for bzr.
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
21
22
These test the conformance of all the repository variations to the expected API.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
23
Specific tests for individual formats are in the tests/test_repository.py file
4523.1.1 by Martin Pool
Rename tests.branch_implementations to per_branch
24
rather than in tests/per_branch/*.py.
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
25
"""
26
2241.1.2 by Martin Pool
change to using external Repository format registry
27
from bzrlib import (
28
    repository,
29
    )
2988.1.3 by Robert Collins
Add a new repositoy method _generate_text_key_index for use by reconcile/check.
30
from bzrlib.revision import NULL_REVISION
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
31
from bzrlib.repofmt import (
32
    weaverepo,
33
    )
2745.6.54 by Andrew Bennetts
Tidy test parameterisation in repository_implementations.
34
from bzrlib.remote import RemoteBzrDirFormat, RemoteRepositoryFormat
35
from bzrlib.smart.server import (
3453.5.1 by Andrew Bennetts
Add {bzrdir,repository,branch}_implementations tests for Remote objects using protocol v2 and pre-1.6 RPCs.
36
    ReadonlySmartTCPServer_for_testing,
37
    ReadonlySmartTCPServer_for_testing_v2_only,
2745.6.54 by Andrew Bennetts
Tidy test parameterisation in repository_implementations.
38
    SmartTCPServer_for_testing,
3453.5.1 by Andrew Bennetts
Add {bzrdir,repository,branch}_implementations tests for Remote objects using protocol v2 and pre-1.6 RPCs.
39
    SmartTCPServer_for_testing_v2_only,
2745.6.54 by Andrew Bennetts
Tidy test parameterisation in repository_implementations.
40
    )
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
41
from bzrlib.tests import (
42
                          default_transport,
2745.6.58 by Andrew Bennetts
Slightly neater test parameterisation in repository_implementations; extract a 'multiply_scenarios' function.
43
                          multiply_scenarios,
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
44
                          multiply_tests,
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
45
                          )
4523.1.2 by Martin Pool
Rename bzrdir_implementations to per_bzrdir
46
from bzrlib.tests.per_bzrdir.test_bzrdir import TestCaseWithBzrDir
2018.5.66 by Wouter van Heyst
Fix repository test parameterization for RemoteRepository.
47
from bzrlib.transport.memory import MemoryServer
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
48
49
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
50
def formats_to_scenarios(formats, transport_server, transport_readonly_server,
51
    vfs_transport_factory=None):
52
    """Transform the input formats to a list of scenarios.
2553.2.2 by Robert Collins
Move RepositoryTestProviderAdapter into the tests part of the code base.
53
3543.1.1 by Michael Hudson
change the scenario multiplication to get the bzrdir format from the tree and
54
    :param formats: A list of (scenario_name_suffix, repo_format)
3543.1.3 by Martin Pool
Better docstring for formats_to_scenarios
55
        where the scenario_name_suffix is to be appended to the format
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
56
        name, and the repo_format is a RepositoryFormat subclass
3543.1.3 by Martin Pool
Better docstring for formats_to_scenarios
57
        instance.
58
    :returns: Scenarios of [(scenario_name, {parameter_name: value})]
2553.2.2 by Robert Collins
Move RepositoryTestProviderAdapter into the tests part of the code base.
59
    """
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
60
    result = []
3543.1.1 by Michael Hudson
change the scenario multiplication to get the bzrdir format from the tree and
61
    for scenario_name_suffix, repository_format in formats:
3453.5.3 by Andrew Bennetts
Merge make-branch-and-tree-fix.
62
        scenario_name = repository_format.__class__.__name__
63
        scenario_name += scenario_name_suffix
64
        scenario = (scenario_name,
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
65
            {"transport_server":transport_server,
66
             "transport_readonly_server":transport_readonly_server,
3543.1.1 by Michael Hudson
change the scenario multiplication to get the bzrdir format from the tree and
67
             "bzrdir_format":repository_format._matchingbzrdir,
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
68
             "repository_format":repository_format,
69
             })
70
        # Only override the test's vfs_transport_factory if one was
71
        # specified, otherwise just leave the default in place.
72
        if vfs_transport_factory:
73
            scenario[1]['vfs_transport_factory'] = vfs_transport_factory
74
        result.append(scenario)
75
    return result
76
77
78
def all_repository_format_scenarios():
3474.2.1 by Martin Pool
Merge and cleanup pre-external-reference-repository tests
79
    """Return a list of test scenarios for parameterising repository tests.
80
    """
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
81
    registry = repository.format_registry
82
    all_formats = [registry.get(k) for k in registry.keys()]
83
    all_formats.extend(weaverepo._legacy_formats)
84
    # format_scenarios is all the implementations of Repository; i.e. all disk
85
    # formats plus RemoteRepository.
86
    format_scenarios = formats_to_scenarios(
3543.1.1 by Michael Hudson
change the scenario multiplication to get the bzrdir format from the tree and
87
        [('', format) for format in all_formats],
3825.4.3 by Andrew Bennetts
Conditionally replace LocalURLServer in the test rather than changing the default_transport behaviour of per_repository tests.
88
        default_transport,
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
89
        # None here will cause a readonly decorator to be created
90
        # by the TestCaseWithTransport.get_readonly_transport method.
91
        None)
92
    format_scenarios.extend(formats_to_scenarios(
3543.1.1 by Michael Hudson
change the scenario multiplication to get the bzrdir format from the tree and
93
        [('-default', RemoteRepositoryFormat())],
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
94
        SmartTCPServer_for_testing,
95
        ReadonlySmartTCPServer_for_testing,
96
        MemoryServer))
3453.5.3 by Andrew Bennetts
Merge make-branch-and-tree-fix.
97
    format_scenarios.extend(formats_to_scenarios(
3543.1.1 by Michael Hudson
change the scenario multiplication to get the bzrdir format from the tree and
98
        [('-v2', RemoteRepositoryFormat())],
3453.5.3 by Andrew Bennetts
Merge make-branch-and-tree-fix.
99
        SmartTCPServer_for_testing_v2_only,
100
        ReadonlySmartTCPServer_for_testing_v2_only,
101
        MemoryServer))
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
102
    return format_scenarios
2553.2.2 by Robert Collins
Move RepositoryTestProviderAdapter into the tests part of the code base.
103
104
2485.7.1 by Robert Collins
Relocate TestCaseWithRepository to be more central.
105
class TestCaseWithRepository(TestCaseWithBzrDir):
106
3697.6.2 by Andrew Bennetts
Add test for preserving shared repository format when sprouting from a smart server.
107
    def make_repository(self, relpath, shared=False, format=None):
2485.7.1 by Robert Collins
Relocate TestCaseWithRepository to be more central.
108
        if format is None:
109
            # Create a repository of the type we are trying to test.
110
            made_control = self.make_bzrdir(relpath)
3697.6.2 by Andrew Bennetts
Add test for preserving shared repository format when sprouting from a smart server.
111
            repo = self.repository_format.initialize(made_control,
112
                    shared=shared)
2553.2.2 by Robert Collins
Move RepositoryTestProviderAdapter into the tests part of the code base.
113
            if getattr(self, "repository_to_test_repository", None):
2553.2.1 by Robert Collins
Overhaul RepositoryTestAdapter to be cleaner and more modular.
114
                repo = self.repository_to_test_repository(repo)
115
            return repo
2485.7.1 by Robert Collins
Relocate TestCaseWithRepository to be more central.
116
        else:
117
            return super(TestCaseWithRepository, self).make_repository(
3697.6.2 by Andrew Bennetts
Add test for preserving shared repository format when sprouting from a smart server.
118
                relpath, shared=shared, format=format)
2485.7.1 by Robert Collins
Relocate TestCaseWithRepository to be more central.
119
120
2745.6.43 by Andrew Bennetts
Tidy imports, docstrings, comments and variable names.
121
class BrokenRepoScenario(object):
122
    """Base class for defining scenarios for testing check and reconcile.
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
123
2745.6.43 by Andrew Bennetts
Tidy imports, docstrings, comments and variable names.
124
    A subclass needs to define the following methods:
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
125
        :populate_repository: a method to use to populate a repository with
126
            sample revisions, inventories and file versions.
2927.2.14 by Andrew Bennetts
Tweaks suggested by review.
127
        :all_versions_after_reconcile: all the versions in repository after
128
            reconcile.  run_test verifies that the text of each of these
129
            versions of the file is unchanged by the reconcile.
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
130
        :populated_parents: a list of (parents list, revision).  Each version
131
            of the file is verified to have the given parents before running
132
            the reconcile.  i.e. this is used to assert that the repo from the
133
            factory is what we expect.
134
        :corrected_parents: a list of (parents list, revision).  Each version
135
            of the file is verified to have the given parents after the
136
            reconcile.  i.e. this is used to assert that reconcile made the
137
            changes we expect it to make.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
138
2927.2.5 by Andrew Bennetts
Remove corrected_inventories, add proper description of corrected_fulltexts.
139
    A subclass may define the following optional method as well:
140
        :corrected_fulltexts: a list of file versions that should be stored as
141
            fulltexts (not deltas) after reconcile.  run_test will verify that
142
            this occurs.
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
143
    """
144
145
    def __init__(self, test_case):
146
        self.test_case = test_case
147
148
    def make_one_file_inventory(self, repo, revision, parents,
2927.2.3 by Andrew Bennetts
Add fulltexts to avoid bug 155730.
149
                                inv_revision=None, root_revision=None,
2927.2.4 by Andrew Bennetts
Don't create a 'rev3' file version in the test.
150
                                file_contents=None, make_file_version=True):
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
151
        return self.test_case.make_one_file_inventory(
152
            repo, revision, parents, inv_revision=inv_revision,
2927.2.4 by Andrew Bennetts
Don't create a 'rev3' file version in the test.
153
            root_revision=root_revision, file_contents=file_contents,
154
            make_file_version=make_file_version)
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
155
156
    def add_revision(self, repo, revision_id, inv, parent_ids):
157
        return self.test_case.add_revision(repo, revision_id, inv, parent_ids)
158
2927.2.3 by Andrew Bennetts
Add fulltexts to avoid bug 155730.
159
    def corrected_fulltexts(self):
160
        return []
161
2988.1.3 by Robert Collins
Add a new repositoy method _generate_text_key_index for use by reconcile/check.
162
    def repository_text_key_index(self):
163
        result = {}
164
        if self.versioned_root:
165
            result.update(self.versioned_repository_text_keys())
166
        result.update(self.repository_text_keys())
167
        return result
168
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
169
2745.6.50 by Andrew Bennetts
Remove find_bad_ancestors; it's not needed anymore.
170
class UndamagedRepositoryScenario(BrokenRepoScenario):
171
    """A scenario where the repository has no damage.
172
173
    It has a single revision, 'rev1a', with a single file.
174
    """
175
2927.2.14 by Andrew Bennetts
Tweaks suggested by review.
176
    def all_versions_after_reconcile(self):
2592.3.214 by Robert Collins
Merge bzr.dev.
177
        return ('rev1a', )
2745.6.50 by Andrew Bennetts
Remove find_bad_ancestors; it's not needed anymore.
178
179
    def populated_parents(self):
2592.3.214 by Robert Collins
Merge bzr.dev.
180
        return (((), 'rev1a'), )
2745.6.50 by Andrew Bennetts
Remove find_bad_ancestors; it's not needed anymore.
181
182
    def corrected_parents(self):
183
        # Same as the populated parents, because there was nothing wrong.
184
        return self.populated_parents()
185
2951.1.6 by Robert Collins
All check/reconcile tests passing now.
186
    def check_regexes(self, repo):
2988.1.8 by Robert Collins
Change check and reconcile to use the new _generate_text_key_index rather
187
        return ["0 unreferenced text versions"]
2745.6.50 by Andrew Bennetts
Remove find_bad_ancestors; it's not needed anymore.
188
189
    def populate_repository(self, repo):
190
        # make rev1a: A well-formed revision, containing 'a-file'
191
        inv = self.make_one_file_inventory(
192
            repo, 'rev1a', [], root_revision='rev1a')
193
        self.add_revision(repo, 'rev1a', inv, [])
2988.1.2 by Robert Collins
New Repository API find_text_key_references for use by reconcile and check.
194
        self.versioned_root = repo.supports_rich_root()
195
196
    def repository_text_key_references(self):
197
        result = {}
198
        if self.versioned_root:
199
            result.update({('TREE_ROOT', 'rev1a'): True})
200
        result.update({('a-file-id', 'rev1a'): True})
201
        return result
2745.6.50 by Andrew Bennetts
Remove find_bad_ancestors; it's not needed anymore.
202
2988.1.3 by Robert Collins
Add a new repositoy method _generate_text_key_index for use by reconcile/check.
203
    def repository_text_keys(self):
204
        return {('a-file-id', 'rev1a'):[NULL_REVISION]}
205
206
    def versioned_repository_text_keys(self):
207
        return {('TREE_ROOT', 'rev1a'):[NULL_REVISION]}
208
2745.6.50 by Andrew Bennetts
Remove find_bad_ancestors; it's not needed anymore.
209
2745.6.43 by Andrew Bennetts
Tidy imports, docstrings, comments and variable names.
210
class FileParentIsNotInRevisionAncestryScenario(BrokenRepoScenario):
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
211
    """A scenario where a revision 'rev2' has 'a-file' with a
212
    parent 'rev1b' that is not in the revision ancestry.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
213
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
214
    Reconcile should remove 'rev1b' from the parents list of 'a-file' in
215
    'rev2', preserving 'rev1a' as a parent.
216
    """
217
2927.2.14 by Andrew Bennetts
Tweaks suggested by review.
218
    def all_versions_after_reconcile(self):
2988.1.8 by Robert Collins
Change check and reconcile to use the new _generate_text_key_index rather
219
        return ('rev1a', 'rev2')
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
220
221
    def populated_parents(self):
2592.3.214 by Robert Collins
Merge bzr.dev.
222
        return (
223
            ((), 'rev1a'),
2988.1.8 by Robert Collins
Change check and reconcile to use the new _generate_text_key_index rather
224
            ((), 'rev1b'), # Will be gc'd
225
            (('rev1a', 'rev1b'), 'rev2')) # Will have parents trimmed
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
226
227
    def corrected_parents(self):
2592.3.214 by Robert Collins
Merge bzr.dev.
228
        return (
229
            ((), 'rev1a'),
2988.1.8 by Robert Collins
Change check and reconcile to use the new _generate_text_key_index rather
230
            (None, 'rev1b'),
2592.3.214 by Robert Collins
Merge bzr.dev.
231
            (('rev1a',), 'rev2'))
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
232
2951.1.6 by Robert Collins
All check/reconcile tests passing now.
233
    def check_regexes(self, repo):
2592.3.214 by Robert Collins
Merge bzr.dev.
234
        return [r"\* a-file-id version rev2 has parents \('rev1a', 'rev1b'\) "
235
                r"but should have \('rev1a',\)",
3036.1.4 by Robert Collins
Fix failing test due to correct check code.
236
                "1 unreferenced text versions",
2745.6.50 by Andrew Bennetts
Remove find_bad_ancestors; it's not needed anymore.
237
                ]
2745.6.41 by Andrew Bennetts
Test repo.check against all_scenarios.
238
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
239
    def populate_repository(self, repo):
240
        # make rev1a: A well-formed revision, containing 'a-file'
241
        inv = self.make_one_file_inventory(
242
            repo, 'rev1a', [], root_revision='rev1a')
243
        self.add_revision(repo, 'rev1a', inv, [])
244
245
        # make rev1b, which has no Revision, but has an Inventory, and
246
        # a-file
247
        inv = self.make_one_file_inventory(
248
            repo, 'rev1b', [], root_revision='rev1b')
249
        repo.add_inventory('rev1b', inv, [])
250
251
        # make rev2, with a-file.
252
        # a-file has 'rev1b' as an ancestor, even though this is not
253
        # mentioned by 'rev1a', making it an unreferenced ancestor
254
        inv = self.make_one_file_inventory(
255
            repo, 'rev2', ['rev1a', 'rev1b'])
256
        self.add_revision(repo, 'rev2', inv, ['rev1a'])
2988.1.2 by Robert Collins
New Repository API find_text_key_references for use by reconcile and check.
257
        self.versioned_root = repo.supports_rich_root()
258
259
    def repository_text_key_references(self):
260
        result = {}
261
        if self.versioned_root:
262
            result.update({('TREE_ROOT', 'rev1a'): True,
263
                           ('TREE_ROOT', 'rev2'): True})
264
        result.update({('a-file-id', 'rev1a'): True,
265
                       ('a-file-id', 'rev2'): True})
266
        return result
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
267
2988.1.3 by Robert Collins
Add a new repositoy method _generate_text_key_index for use by reconcile/check.
268
    def repository_text_keys(self):
269
        return {('a-file-id', 'rev1a'):[NULL_REVISION],
270
                ('a-file-id', 'rev2'):[('a-file-id', 'rev1a')]}
271
272
    def versioned_repository_text_keys(self):
273
        return {('TREE_ROOT', 'rev1a'):[NULL_REVISION],
274
                ('TREE_ROOT', 'rev2'):[('TREE_ROOT', 'rev1a')]}
275
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
276
2745.6.43 by Andrew Bennetts
Tidy imports, docstrings, comments and variable names.
277
class FileParentHasInaccessibleInventoryScenario(BrokenRepoScenario):
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
278
    """A scenario where a revision 'rev3' containing 'a-file' modified in
279
    'rev3', and with a parent which is in the revision ancestory, but whose
280
    inventory cannot be accessed at all.
281
282
    Reconcile should remove the file version parent whose inventory is
283
    inaccessbile (i.e. remove 'rev1c' from the parents of a-file's rev3).
284
    """
285
2927.2.14 by Andrew Bennetts
Tweaks suggested by review.
286
    def all_versions_after_reconcile(self):
2592.3.214 by Robert Collins
Merge bzr.dev.
287
        return ('rev2', 'rev3')
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
288
289
    def populated_parents(self):
2592.3.214 by Robert Collins
Merge bzr.dev.
290
        return (
291
            ((), 'rev2'),
292
            (('rev1c',), 'rev3'))
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
293
294
    def corrected_parents(self):
2592.3.214 by Robert Collins
Merge bzr.dev.
295
        return (
296
            ((), 'rev2'),
297
            ((), 'rev3'))
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
298
2951.1.6 by Robert Collins
All check/reconcile tests passing now.
299
    def check_regexes(self, repo):
2745.6.43 by Andrew Bennetts
Tidy imports, docstrings, comments and variable names.
300
        return [r"\* a-file-id version rev3 has parents "
2592.3.214 by Robert Collins
Merge bzr.dev.
301
                r"\('rev1c',\) but should have \(\)",
2745.6.50 by Andrew Bennetts
Remove find_bad_ancestors; it's not needed anymore.
302
                ]
2745.6.41 by Andrew Bennetts
Test repo.check against all_scenarios.
303
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
304
    def populate_repository(self, repo):
305
        # make rev2, with a-file
306
        # a-file is sane
307
        inv = self.make_one_file_inventory(repo, 'rev2', [])
308
        self.add_revision(repo, 'rev2', inv, [])
309
310
        # make ghost revision rev1c, with a version of a-file present so
311
        # that we generate a knit delta against this version.  In real life
312
        # the ghost might never have been present or rev3 might have been
313
        # generated against a revision that was present at the time.  So
314
        # currently we have the full history of a-file present even though
315
        # the inventory and revision objects are not.
316
        self.make_one_file_inventory(repo, 'rev1c', [])
317
318
        # make rev3 with a-file
319
        # a-file refers to 'rev1c', which is a ghost in this repository, so
320
        # a-file cannot have rev1c as its ancestor.
321
        inv = self.make_one_file_inventory(repo, 'rev3', ['rev1c'])
322
        self.add_revision(repo, 'rev3', inv, ['rev1c', 'rev1a'])
2988.1.2 by Robert Collins
New Repository API find_text_key_references for use by reconcile and check.
323
        self.versioned_root = repo.supports_rich_root()
324
325
    def repository_text_key_references(self):
326
        result = {}
327
        if self.versioned_root:
328
            result.update({('TREE_ROOT', 'rev2'): True,
329
                           ('TREE_ROOT', 'rev3'): True})
330
        result.update({('a-file-id', 'rev2'): True,
331
                       ('a-file-id', 'rev3'): True})
332
        return result
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
333
2988.1.3 by Robert Collins
Add a new repositoy method _generate_text_key_index for use by reconcile/check.
334
    def repository_text_keys(self):
335
        return {('a-file-id', 'rev2'):[NULL_REVISION],
336
                ('a-file-id', 'rev3'):[NULL_REVISION]}
337
338
    def versioned_repository_text_keys(self):
339
        return {('TREE_ROOT', 'rev2'):[NULL_REVISION],
340
                ('TREE_ROOT', 'rev3'):[NULL_REVISION]}
341
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
342
2745.6.43 by Andrew Bennetts
Tidy imports, docstrings, comments and variable names.
343
class FileParentsNotReferencedByAnyInventoryScenario(BrokenRepoScenario):
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
344
    """A scenario where a repository with file 'a-file' which has extra
345
    per-file versions that are not referenced by any inventory (even though
346
    they have the same ID as actual revisions).  The inventory of 'rev2'
347
    references 'rev1a' of 'a-file', but there is a 'rev2' of 'some-file' stored
348
    and erroneously referenced by later per-file versions (revisions 'rev4' and
349
    'rev5').
350
351
    Reconcile should remove the file parents that are not referenced by any
352
    inventory.
353
    """
354
2927.2.14 by Andrew Bennetts
Tweaks suggested by review.
355
    def all_versions_after_reconcile(self):
2927.2.11 by Andrew Bennetts
Merge from bzr.dev.
356
        return ('rev1a', 'rev2c', 'rev4', 'rev5')
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
357
358
    def populated_parents(self):
359
        return [
2927.2.11 by Andrew Bennetts
Merge from bzr.dev.
360
            (('rev1a',), 'rev2'),
361
            (('rev1a',), 'rev2b'),
2592.3.214 by Robert Collins
Merge bzr.dev.
362
            (('rev2',), 'rev3'),
363
            (('rev2',), 'rev4'),
2927.2.11 by Andrew Bennetts
Merge from bzr.dev.
364
            (('rev2', 'rev2c'), 'rev5')]
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
365
366
    def corrected_parents(self):
2592.3.214 by Robert Collins
Merge bzr.dev.
367
        return (
2927.2.8 by Andrew Bennetts
Remove totally unreferenced file versions. All reconcile tests passing.
368
            # rev2 and rev2b have been removed.
369
            (None, 'rev2'),
370
            (None, 'rev2b'),
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
371
            # rev3's accessible parent inventories all have rev1a as the last
372
            # modifier.
2592.3.214 by Robert Collins
Merge bzr.dev.
373
            (('rev1a',), 'rev3'),
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
374
            # rev1a features in both rev4's parents but should only appear once
375
            # in the result
2592.3.214 by Robert Collins
Merge bzr.dev.
376
            (('rev1a',), 'rev4'),
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
377
            # rev2c is the head of rev1a and rev2c, the inventory provided
378
            # per-file last-modified revisions.
2592.3.214 by Robert Collins
Merge bzr.dev.
379
            (('rev2c',), 'rev5'))
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
380
2951.1.6 by Robert Collins
All check/reconcile tests passing now.
381
    def check_regexes(self, repo):
382
        if repo.supports_rich_root():
383
            # TREE_ROOT will be wrong; but we're not testing it. so just adjust
384
            # the expected count of errors.
2988.1.8 by Robert Collins
Change check and reconcile to use the new _generate_text_key_index rather
385
            count = 9
2951.1.6 by Robert Collins
All check/reconcile tests passing now.
386
        else:
2988.1.8 by Robert Collins
Change check and reconcile to use the new _generate_text_key_index rather
387
            count = 3
2745.6.41 by Andrew Bennetts
Test repo.check against all_scenarios.
388
        return [
2988.1.8 by Robert Collins
Change check and reconcile to use the new _generate_text_key_index rather
389
            # will be gc'd
390
            r"unreferenced version: {rev2} in a-file-id",
391
            r"unreferenced version: {rev2b} in a-file-id",
392
            # will be corrected
2592.3.214 by Robert Collins
Merge bzr.dev.
393
            r"a-file-id version rev3 has parents \('rev2',\) "
394
            r"but should have \('rev1a',\)",
395
            r"a-file-id version rev5 has parents \('rev2', 'rev2c'\) "
396
            r"but should have \('rev2c',\)",
397
            r"a-file-id version rev4 has parents \('rev2',\) "
398
            r"but should have \('rev1a',\)",
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.
399
            "%d inconsistent parents" % count,
2745.6.41 by Andrew Bennetts
Test repo.check against all_scenarios.
400
            ]
401
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
402
    def populate_repository(self, repo):
403
        # make rev1a: A well-formed revision, containing 'a-file'
404
        inv = self.make_one_file_inventory(
405
            repo, 'rev1a', [], root_revision='rev1a')
406
        self.add_revision(repo, 'rev1a', inv, [])
407
408
        # make rev2, with a-file.
2927.2.3 by Andrew Bennetts
Add fulltexts to avoid bug 155730.
409
        # a-file is unmodified from rev1a, and an unreferenced rev2 file
410
        # version is present in the repository.
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
411
        self.make_one_file_inventory(
412
            repo, 'rev2', ['rev1a'], inv_revision='rev1a')
413
        self.add_revision(repo, 'rev2', inv, ['rev1a'])
414
415
        # make rev3 with a-file
416
        # a-file has 'rev2' as its ancestor, but the revision in 'rev2' was
417
        # rev1a so this is inconsistent with rev2's inventory - it should
418
        # be rev1a, and at the revision level 1c is not present - it is a
419
        # ghost, so only the details from rev1a are available for
420
        # determining whether a delta is acceptable, or a full is needed,
2745.6.43 by Andrew Bennetts
Tidy imports, docstrings, comments and variable names.
421
        # and what the correct parents are.
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
422
        inv = self.make_one_file_inventory(repo, 'rev3', ['rev2'])
2745.6.43 by Andrew Bennetts
Tidy imports, docstrings, comments and variable names.
423
        self.add_revision(repo, 'rev3', inv, ['rev1c', 'rev1a'])
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
424
425
        # In rev2b, the true last-modifying-revision of a-file is rev1a,
426
        # inherited from rev2, but there is a version rev2b of the file, which
427
        # reconcile could remove, leaving no rev2b.  Most importantly,
428
        # revisions descending from rev2b should not have per-file parents of
429
        # a-file-rev2b.
430
        # ??? This is to test deduplication in fixing rev4
431
        inv = self.make_one_file_inventory(
432
            repo, 'rev2b', ['rev1a'], inv_revision='rev1a')
433
        self.add_revision(repo, 'rev2b', inv, ['rev1a'])
434
435
        # rev4 is for testing that when the last modified of a file in
436
        # multiple parent revisions is the same, that it only appears once
437
        # in the generated per file parents list: rev2 and rev2b both
438
        # descend from 1a and do not change the file a-file, so there should
439
        # be no version of a-file 'rev2' or 'rev2b', but rev4 does change
440
        # a-file, and is a merge of rev2 and rev2b, so it should end up with
441
        # a parent of just rev1a - the starting file parents list is simply
442
        # completely wrong.
443
        inv = self.make_one_file_inventory(repo, 'rev4', ['rev2'])
444
        self.add_revision(repo, 'rev4', inv, ['rev2', 'rev2b'])
445
446
        # rev2c changes a-file from rev1a, so the version it of a-file it
447
        # introduces is a head revision when rev5 is checked.
448
        inv = self.make_one_file_inventory(repo, 'rev2c', ['rev1a'])
449
        self.add_revision(repo, 'rev2c', inv, ['rev1a'])
450
451
        # rev5 descends from rev2 and rev2c; as rev2 does not alter a-file,
452
        # but rev2c does, this should use rev2c as the parent for the per
453
        # file history, even though more than one per-file parent is
454
        # available, because we use the heads of the revision parents for
455
        # the inventory modification revisions of the file to determine the
456
        # parents for the per file graph.
457
        inv = self.make_one_file_inventory(repo, 'rev5', ['rev2', 'rev2c'])
458
        self.add_revision(repo, 'rev5', inv, ['rev2', 'rev2c'])
2988.1.2 by Robert Collins
New Repository API find_text_key_references for use by reconcile and check.
459
        self.versioned_root = repo.supports_rich_root()
460
461
    def repository_text_key_references(self):
462
        result = {}
463
        if self.versioned_root:
464
            result.update({('TREE_ROOT', 'rev1a'): True,
465
                           ('TREE_ROOT', 'rev2'): True,
466
                           ('TREE_ROOT', 'rev2b'): True,
467
                           ('TREE_ROOT', 'rev2c'): True,
468
                           ('TREE_ROOT', 'rev3'): True,
469
                           ('TREE_ROOT', 'rev4'): True,
470
                           ('TREE_ROOT', 'rev5'): True})
471
        result.update({('a-file-id', 'rev1a'): True,
472
                       ('a-file-id', 'rev2c'): True,
473
                       ('a-file-id', 'rev3'): True,
474
                       ('a-file-id', 'rev4'): True,
475
                       ('a-file-id', 'rev5'): True})
476
        return result
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
477
2988.1.3 by Robert Collins
Add a new repositoy method _generate_text_key_index for use by reconcile/check.
478
    def repository_text_keys(self):
479
        return {('a-file-id', 'rev1a'): [NULL_REVISION],
480
                 ('a-file-id', 'rev2c'): [('a-file-id', 'rev1a')],
481
                 ('a-file-id', 'rev3'): [('a-file-id', 'rev1a')],
482
                 ('a-file-id', 'rev4'): [('a-file-id', 'rev1a')],
483
                 ('a-file-id', 'rev5'): [('a-file-id', 'rev2c')]}
484
485
    def versioned_repository_text_keys(self):
486
        return {('TREE_ROOT', 'rev1a'): [NULL_REVISION],
487
                ('TREE_ROOT', 'rev2'): [('TREE_ROOT', 'rev1a')],
488
                ('TREE_ROOT', 'rev2b'): [('TREE_ROOT', 'rev1a')],
489
                ('TREE_ROOT', 'rev2c'): [('TREE_ROOT', 'rev1a')],
490
                ('TREE_ROOT', 'rev3'): [('TREE_ROOT', 'rev1a')],
491
                ('TREE_ROOT', 'rev4'):
492
                    [('TREE_ROOT', 'rev2'), ('TREE_ROOT', 'rev2b')],
493
                ('TREE_ROOT', 'rev5'):
494
                    [('TREE_ROOT', 'rev2'), ('TREE_ROOT', 'rev2c')]}
495
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
496
2927.2.3 by Andrew Bennetts
Add fulltexts to avoid bug 155730.
497
class UnreferencedFileParentsFromNoOpMergeScenario(BrokenRepoScenario):
498
    """
499
    rev1a and rev1b with identical contents
500
    rev2 revision has parents of [rev1a, rev1b]
501
    There is a a-file:rev2 file version, not referenced by the inventory.
502
    """
503
2927.2.14 by Andrew Bennetts
Tweaks suggested by review.
504
    def all_versions_after_reconcile(self):
2927.2.11 by Andrew Bennetts
Merge from bzr.dev.
505
        return ('rev1a', 'rev1b', 'rev2', 'rev4')
2927.2.3 by Andrew Bennetts
Add fulltexts to avoid bug 155730.
506
507
    def populated_parents(self):
2927.2.11 by Andrew Bennetts
Merge from bzr.dev.
508
        return (
509
            ((), 'rev1a'),
510
            ((), 'rev1b'),
511
            (('rev1a', 'rev1b'), 'rev2'),
2927.2.4 by Andrew Bennetts
Don't create a 'rev3' file version in the test.
512
            (None, 'rev3'),
2927.2.11 by Andrew Bennetts
Merge from bzr.dev.
513
            (('rev2',), 'rev4'),
514
            )
2927.2.3 by Andrew Bennetts
Add fulltexts to avoid bug 155730.
515
516
    def corrected_parents(self):
2927.2.11 by Andrew Bennetts
Merge from bzr.dev.
517
        return (
518
            ((), 'rev1a'),
519
            ((), 'rev1b'),
520
            ((), 'rev2'),
2927.2.4 by Andrew Bennetts
Don't create a 'rev3' file version in the test.
521
            (None, 'rev3'),
2927.2.11 by Andrew Bennetts
Merge from bzr.dev.
522
            (('rev2',), 'rev4'),
523
            )
2927.2.3 by Andrew Bennetts
Add fulltexts to avoid bug 155730.
524
525
    def corrected_fulltexts(self):
2988.1.8 by Robert Collins
Change check and reconcile to use the new _generate_text_key_index rather
526
        return ['rev2']
2927.2.3 by Andrew Bennetts
Add fulltexts to avoid bug 155730.
527
2951.1.6 by Robert Collins
All check/reconcile tests passing now.
528
    def check_regexes(self, repo):
2927.2.3 by Andrew Bennetts
Add fulltexts to avoid bug 155730.
529
        return []
530
531
    def populate_repository(self, repo):
532
        # make rev1a: A well-formed revision, containing 'a-file'
533
        inv1a = self.make_one_file_inventory(
534
            repo, 'rev1a', [], root_revision='rev1a')
535
        self.add_revision(repo, 'rev1a', inv1a, [])
536
537
        # make rev1b: A well-formed revision, containing 'a-file'
538
        # rev1b of a-file has the exact same contents as rev1a.
539
        file_contents = repo.revision_tree('rev1a').get_file_text('a-file-id')
540
        inv = self.make_one_file_inventory(
541
            repo, 'rev1b', [], root_revision='rev1b',
542
            file_contents=file_contents)
543
        self.add_revision(repo, 'rev1b', inv, [])
544
545
        # make rev2, a merge of rev1a and rev1b, with a-file.
546
        # a-file is unmodified from rev1a and rev1b, but a new version is
547
        # wrongly present anyway.
548
        inv = self.make_one_file_inventory(
549
            repo, 'rev2', ['rev1a', 'rev1b'], inv_revision='rev1a',
550
            file_contents=file_contents)
551
        self.add_revision(repo, 'rev2', inv, ['rev1a', 'rev1b'])
552
553
        # rev3: a-file unchanged from rev2, but wrongly referencing rev2 of the
554
        # file in its inventory.
555
        inv = self.make_one_file_inventory(
556
            repo, 'rev3', ['rev2'], inv_revision='rev2',
2927.2.4 by Andrew Bennetts
Don't create a 'rev3' file version in the test.
557
            file_contents=file_contents, make_file_version=False)
2927.2.3 by Andrew Bennetts
Add fulltexts to avoid bug 155730.
558
        self.add_revision(repo, 'rev3', inv, ['rev2'])
559
560
        # rev4: a modification of a-file on top of rev3.
2927.2.4 by Andrew Bennetts
Don't create a 'rev3' file version in the test.
561
        inv = self.make_one_file_inventory(repo, 'rev4', ['rev2'])
2927.2.3 by Andrew Bennetts
Add fulltexts to avoid bug 155730.
562
        self.add_revision(repo, 'rev4', inv, ['rev3'])
2988.1.2 by Robert Collins
New Repository API find_text_key_references for use by reconcile and check.
563
        self.versioned_root = repo.supports_rich_root()
564
565
    def repository_text_key_references(self):
566
        result = {}
567
        if self.versioned_root:
568
            result.update({('TREE_ROOT', 'rev1a'): True,
569
                           ('TREE_ROOT', 'rev1b'): True,
570
                           ('TREE_ROOT', 'rev2'): True,
571
                           ('TREE_ROOT', 'rev3'): True,
572
                           ('TREE_ROOT', 'rev4'): True})
573
        result.update({('a-file-id', 'rev1a'): True,
574
                       ('a-file-id', 'rev1b'): True,
575
                       ('a-file-id', 'rev2'): False,
576
                       ('a-file-id', 'rev4'): True})
577
        return result
2927.2.3 by Andrew Bennetts
Add fulltexts to avoid bug 155730.
578
2988.1.3 by Robert Collins
Add a new repositoy method _generate_text_key_index for use by reconcile/check.
579
    def repository_text_keys(self):
580
        return {('a-file-id', 'rev1a'): [NULL_REVISION],
581
                ('a-file-id', 'rev1b'): [NULL_REVISION],
582
                ('a-file-id', 'rev2'): [NULL_REVISION],
583
                ('a-file-id', 'rev4'): [('a-file-id', 'rev2')]}
584
585
    def versioned_repository_text_keys(self):
586
        return {('TREE_ROOT', 'rev1a'): [NULL_REVISION],
587
                ('TREE_ROOT', 'rev1b'): [NULL_REVISION],
588
                ('TREE_ROOT', 'rev2'):
589
                    [('TREE_ROOT', 'rev1a'), ('TREE_ROOT', 'rev1b')],
590
                ('TREE_ROOT', 'rev3'): [('TREE_ROOT', 'rev2')],
591
                ('TREE_ROOT', 'rev4'): [('TREE_ROOT', 'rev3')]}
592
2927.2.3 by Andrew Bennetts
Add fulltexts to avoid bug 155730.
593
2745.6.43 by Andrew Bennetts
Tidy imports, docstrings, comments and variable names.
594
class TooManyParentsScenario(BrokenRepoScenario):
2745.6.39 by Andrew Bennetts
Use scenario in test_check too, and make check actually report inconsistent parents to the end user.
595
    """A scenario where 'broken-revision' of 'a-file' claims to have parents
596
    ['good-parent', 'bad-parent'].  However 'bad-parent' is in the ancestry of
597
    'good-parent', so the correct parent list for that file version are is just
598
    ['good-parent'].
599
    """
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
600
2927.2.14 by Andrew Bennetts
Tweaks suggested by review.
601
    def all_versions_after_reconcile(self):
2592.3.214 by Robert Collins
Merge bzr.dev.
602
        return ('bad-parent', 'good-parent', 'broken-revision')
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
603
604
    def populated_parents(self):
2592.3.214 by Robert Collins
Merge bzr.dev.
605
        return (
606
            ((), 'bad-parent'),
607
            (('bad-parent',), 'good-parent'),
608
            (('good-parent', 'bad-parent'), 'broken-revision'))
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
609
610
    def corrected_parents(self):
2592.3.214 by Robert Collins
Merge bzr.dev.
611
        return (
612
            ((), 'bad-parent'),
613
            (('bad-parent',), 'good-parent'),
614
            (('good-parent',), 'broken-revision'))
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
615
2951.1.6 by Robert Collins
All check/reconcile tests passing now.
616
    def check_regexes(self, repo):
617
        if repo.supports_rich_root():
618
            # TREE_ROOT will be wrong; but we're not testing it. so just adjust
619
            # the expected count of errors.
620
            count = 3
621
        else:
622
            count = 1
2592.3.214 by Robert Collins
Merge bzr.dev.
623
        return (
2951.1.6 by Robert Collins
All check/reconcile tests passing now.
624
            '     %d inconsistent parents' % count,
2745.6.39 by Andrew Bennetts
Use scenario in test_check too, and make check actually report inconsistent parents to the end user.
625
            (r"      \* a-file-id version broken-revision has parents "
2592.3.214 by Robert Collins
Merge bzr.dev.
626
             r"\('good-parent', 'bad-parent'\) but "
627
             r"should have \('good-parent',\)"))
2745.6.39 by Andrew Bennetts
Use scenario in test_check too, and make check actually report inconsistent parents to the end user.
628
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
629
    def populate_repository(self, repo):
630
        inv = self.make_one_file_inventory(
2592.3.214 by Robert Collins
Merge bzr.dev.
631
            repo, 'bad-parent', (), root_revision='bad-parent')
632
        self.add_revision(repo, 'bad-parent', inv, ())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
633
2592.3.214 by Robert Collins
Merge bzr.dev.
634
        inv = self.make_one_file_inventory(
635
            repo, 'good-parent', ('bad-parent',))
636
        self.add_revision(repo, 'good-parent', inv, ('bad-parent',))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
637
2592.3.214 by Robert Collins
Merge bzr.dev.
638
        inv = self.make_one_file_inventory(
639
            repo, 'broken-revision', ('good-parent', 'bad-parent'))
640
        self.add_revision(repo, 'broken-revision', inv, ('good-parent',))
2988.1.2 by Robert Collins
New Repository API find_text_key_references for use by reconcile and check.
641
        self.versioned_root = repo.supports_rich_root()
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
642
2988.1.2 by Robert Collins
New Repository API find_text_key_references for use by reconcile and check.
643
    def repository_text_key_references(self):
644
        result = {}
645
        if self.versioned_root:
646
            result.update({('TREE_ROOT', 'bad-parent'): True,
647
                           ('TREE_ROOT', 'broken-revision'): True,
648
                           ('TREE_ROOT', 'good-parent'): True})
649
        result.update({('a-file-id', 'bad-parent'): True,
650
                       ('a-file-id', 'broken-revision'): True,
651
                       ('a-file-id', 'good-parent'): True})
652
        return result
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
653
2988.1.3 by Robert Collins
Add a new repositoy method _generate_text_key_index for use by reconcile/check.
654
    def repository_text_keys(self):
655
        return {('a-file-id', 'bad-parent'): [NULL_REVISION],
656
                ('a-file-id', 'broken-revision'):
657
                    [('a-file-id', 'good-parent')],
658
                ('a-file-id', 'good-parent'): [('a-file-id', 'bad-parent')]}
659
660
    def versioned_repository_text_keys(self):
661
        return {('TREE_ROOT', 'bad-parent'): [NULL_REVISION],
662
                ('TREE_ROOT', 'broken-revision'):
663
                    [('TREE_ROOT', 'good-parent')],
664
                ('TREE_ROOT', 'good-parent'): [('TREE_ROOT', 'bad-parent')]}
665
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
666
2745.6.43 by Andrew Bennetts
Tidy imports, docstrings, comments and variable names.
667
class ClaimedFileParentDidNotModifyFileScenario(BrokenRepoScenario):
668
    """A scenario where the file parent is the same as the revision parent, but
669
    should not be because that revision did not modify the file.
670
671
    Specifically, the parent revision of 'current' is
672
    'modified-something-else', which does not modify 'a-file', but the
673
    'current' version of 'a-file' erroneously claims that
674
    'modified-something-else' is the parent file version.
675
    """
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
676
2927.2.14 by Andrew Bennetts
Tweaks suggested by review.
677
    def all_versions_after_reconcile(self):
2927.2.11 by Andrew Bennetts
Merge from bzr.dev.
678
        return ('basis', 'current')
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
679
680
    def populated_parents(self):
2592.3.214 by Robert Collins
Merge bzr.dev.
681
        return (
682
            ((), 'basis'),
683
            (('basis',), 'modified-something-else'),
684
            (('modified-something-else',), 'current'))
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
685
686
    def corrected_parents(self):
2592.3.214 by Robert Collins
Merge bzr.dev.
687
        return (
688
            ((), 'basis'),
2927.2.8 by Andrew Bennetts
Remove totally unreferenced file versions. All reconcile tests passing.
689
            (None, 'modified-something-else'),
2592.3.214 by Robert Collins
Merge bzr.dev.
690
            (('basis',), 'current'))
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
691
2951.1.6 by Robert Collins
All check/reconcile tests passing now.
692
    def check_regexes(self, repo):
693
        if repo.supports_rich_root():
694
            # TREE_ROOT will be wrong; but we're not testing it. so just adjust
695
            # the expected count of errors.
2988.1.8 by Robert Collins
Change check and reconcile to use the new _generate_text_key_index rather
696
            count = 3
2951.1.6 by Robert Collins
All check/reconcile tests passing now.
697
        else:
2988.1.8 by Robert Collins
Change check and reconcile to use the new _generate_text_key_index rather
698
            count = 1
2592.3.214 by Robert Collins
Merge bzr.dev.
699
        return (
2951.1.6 by Robert Collins
All check/reconcile tests passing now.
700
            "%d inconsistent parents" % count,
2745.6.41 by Andrew Bennetts
Test repo.check against all_scenarios.
701
            r"\* a-file-id version current has parents "
2927.2.11 by Andrew Bennetts
Merge from bzr.dev.
702
            r"\('modified-something-else',\) but should have \('basis',\)",
703
            )
2745.6.41 by Andrew Bennetts
Test repo.check against all_scenarios.
704
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
705
    def populate_repository(self, repo):
2592.3.214 by Robert Collins
Merge bzr.dev.
706
        inv = self.make_one_file_inventory(repo, 'basis', ())
707
        self.add_revision(repo, 'basis', inv, ())
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
708
2745.6.43 by Andrew Bennetts
Tidy imports, docstrings, comments and variable names.
709
        # 'modified-something-else' is a correctly recorded revision, but it
710
        # does not modify the file we are looking at, so the inventory for that
711
        # file in this revision points to 'basis'.
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
712
        inv = self.make_one_file_inventory(
2592.3.214 by Robert Collins
Merge bzr.dev.
713
            repo, 'modified-something-else', ('basis',), inv_revision='basis')
714
        self.add_revision(repo, 'modified-something-else', inv, ('basis',))
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
715
2745.6.43 by Andrew Bennetts
Tidy imports, docstrings, comments and variable names.
716
        # The 'current' revision has 'modified-something-else' as its parent,
717
        # but the 'current' version of 'a-file' should have 'basis' as its
718
        # parent.
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
719
        inv = self.make_one_file_inventory(
2592.3.214 by Robert Collins
Merge bzr.dev.
720
            repo, 'current', ('modified-something-else',))
721
        self.add_revision(repo, 'current', inv, ('modified-something-else',))
2988.1.2 by Robert Collins
New Repository API find_text_key_references for use by reconcile and check.
722
        self.versioned_root = repo.supports_rich_root()
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
723
2988.1.2 by Robert Collins
New Repository API find_text_key_references for use by reconcile and check.
724
    def repository_text_key_references(self):
725
        result = {}
726
        if self.versioned_root:
727
            result.update({('TREE_ROOT', 'basis'): True,
728
                           ('TREE_ROOT', 'current'): True,
729
                           ('TREE_ROOT', 'modified-something-else'): True})
730
        result.update({('a-file-id', 'basis'): True,
731
                       ('a-file-id', 'current'): True})
732
        return result
2988.1.3 by Robert Collins
Add a new repositoy method _generate_text_key_index for use by reconcile/check.
733
734
    def repository_text_keys(self):
735
        return {('a-file-id', 'basis'): [NULL_REVISION],
736
                ('a-file-id', 'current'): [('a-file-id', 'basis')]}
737
738
    def versioned_repository_text_keys(self):
739
        return {('TREE_ROOT', 'basis'): ['null:'],
740
                ('TREE_ROOT', 'current'):
741
                    [('TREE_ROOT', 'modified-something-else')],
742
                ('TREE_ROOT', 'modified-something-else'):
743
                    [('TREE_ROOT', 'basis')]}
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
744
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
745
2745.6.43 by Andrew Bennetts
Tidy imports, docstrings, comments and variable names.
746
class IncorrectlyOrderedParentsScenario(BrokenRepoScenario):
747
    """A scenario where the set parents of a version of a file are correct, but
748
    the order of those parents is incorrect.
749
750
    This defines a 'broken-revision-1-2' and a 'broken-revision-2-1' which both
751
    have their file version parents reversed compared to the revision parents,
752
    which is invalid.  (We use two revisions with opposite orderings of the
753
    same parents to make sure that accidentally relying on dictionary/set
754
    ordering cannot make the test pass; the assumption is that while dict/set
755
    iteration order is arbitrary, it is also consistent within a single test).
756
    """
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
757
2927.2.14 by Andrew Bennetts
Tweaks suggested by review.
758
    def all_versions_after_reconcile(self):
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
759
        return ['parent-1', 'parent-2', 'broken-revision-1-2',
760
                'broken-revision-2-1']
761
762
    def populated_parents(self):
2592.3.214 by Robert Collins
Merge bzr.dev.
763
        return (
764
            ((), 'parent-1'),
765
            ((), 'parent-2'),
766
            (('parent-2', 'parent-1'), 'broken-revision-1-2'),
767
            (('parent-1', 'parent-2'), 'broken-revision-2-1'))
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
768
769
    def corrected_parents(self):
2592.3.214 by Robert Collins
Merge bzr.dev.
770
        return (
771
            ((), 'parent-1'),
772
            ((), 'parent-2'),
773
            (('parent-1', 'parent-2'), 'broken-revision-1-2'),
774
            (('parent-2', 'parent-1'), 'broken-revision-2-1'))
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
775
2951.1.6 by Robert Collins
All check/reconcile tests passing now.
776
    def check_regexes(self, repo):
777
        if repo.supports_rich_root():
778
            # TREE_ROOT will be wrong; but we're not testing it. so just adjust
779
            # the expected count of errors.
780
            count = 4
781
        else:
782
            count = 2
2592.3.214 by Robert Collins
Merge bzr.dev.
783
        return (
2951.1.6 by Robert Collins
All check/reconcile tests passing now.
784
            "%d inconsistent parents" % count,
2745.6.41 by Andrew Bennetts
Test repo.check against all_scenarios.
785
            r"\* a-file-id version broken-revision-1-2 has parents "
2592.3.214 by Robert Collins
Merge bzr.dev.
786
            r"\('parent-2', 'parent-1'\) but should have "
787
            r"\('parent-1', 'parent-2'\)",
2745.6.41 by Andrew Bennetts
Test repo.check against all_scenarios.
788
            r"\* a-file-id version broken-revision-2-1 has parents "
2592.3.214 by Robert Collins
Merge bzr.dev.
789
            r"\('parent-1', 'parent-2'\) but should have "
790
            r"\('parent-2', 'parent-1'\)")
2745.6.41 by Andrew Bennetts
Test repo.check against all_scenarios.
791
2745.6.38 by Andrew Bennetts
Create explicit scenario objects for test_reconcile.
792
    def populate_repository(self, repo):
793
        inv = self.make_one_file_inventory(repo, 'parent-1', [])
794
        self.add_revision(repo, 'parent-1', inv, [])
795
796
        inv = self.make_one_file_inventory(repo, 'parent-2', [])
797
        self.add_revision(repo, 'parent-2', inv, [])
798
799
        inv = self.make_one_file_inventory(
800
            repo, 'broken-revision-1-2', ['parent-2', 'parent-1'])
801
        self.add_revision(
802
            repo, 'broken-revision-1-2', inv, ['parent-1', 'parent-2'])
803
804
        inv = self.make_one_file_inventory(
805
            repo, 'broken-revision-2-1', ['parent-1', 'parent-2'])
806
        self.add_revision(
807
            repo, 'broken-revision-2-1', inv, ['parent-2', 'parent-1'])
2988.1.2 by Robert Collins
New Repository API find_text_key_references for use by reconcile and check.
808
        self.versioned_root = repo.supports_rich_root()
2745.6.32 by Andrew Bennetts
Some testing notes, test reorganisation, XXX comments and some failing tests.
809
2988.1.2 by Robert Collins
New Repository API find_text_key_references for use by reconcile and check.
810
    def repository_text_key_references(self):
811
        result = {}
812
        if self.versioned_root:
813
            result.update({('TREE_ROOT', 'broken-revision-1-2'): True,
814
                           ('TREE_ROOT', 'broken-revision-2-1'): True,
815
                           ('TREE_ROOT', 'parent-1'): True,
816
                           ('TREE_ROOT', 'parent-2'): True})
817
        result.update({('a-file-id', 'broken-revision-1-2'): True,
818
                       ('a-file-id', 'broken-revision-2-1'): True,
819
                       ('a-file-id', 'parent-1'): True,
820
                       ('a-file-id', 'parent-2'): True})
821
        return result
2988.1.3 by Robert Collins
Add a new repositoy method _generate_text_key_index for use by reconcile/check.
822
823
    def repository_text_keys(self):
824
        return {('a-file-id', 'broken-revision-1-2'):
825
                    [('a-file-id', 'parent-1'), ('a-file-id', 'parent-2')],
826
                ('a-file-id', 'broken-revision-2-1'):
827
                    [('a-file-id', 'parent-2'), ('a-file-id', 'parent-1')],
828
                ('a-file-id', 'parent-1'): [NULL_REVISION],
829
                ('a-file-id', 'parent-2'): [NULL_REVISION]}
830
831
    def versioned_repository_text_keys(self):
832
        return {('TREE_ROOT', 'broken-revision-1-2'):
833
                    [('TREE_ROOT', 'parent-1'), ('TREE_ROOT', 'parent-2')],
834
                ('TREE_ROOT', 'broken-revision-2-1'):
835
                    [('TREE_ROOT', 'parent-2'), ('TREE_ROOT', 'parent-1')],
836
                ('TREE_ROOT', 'parent-1'): [NULL_REVISION],
837
                ('TREE_ROOT', 'parent-2'): [NULL_REVISION]}
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
838
2485.7.1 by Robert Collins
Relocate TestCaseWithRepository to be more central.
839
2745.6.58 by Andrew Bennetts
Slightly neater test parameterisation in repository_implementations; extract a 'multiply_scenarios' function.
840
all_broken_scenario_classes = [
2745.6.54 by Andrew Bennetts
Tidy test parameterisation in repository_implementations.
841
    UndamagedRepositoryScenario,
842
    FileParentIsNotInRevisionAncestryScenario,
843
    FileParentHasInaccessibleInventoryScenario,
844
    FileParentsNotReferencedByAnyInventoryScenario,
845
    TooManyParentsScenario,
846
    ClaimedFileParentDidNotModifyFileScenario,
847
    IncorrectlyOrderedParentsScenario,
2927.2.3 by Andrew Bennetts
Add fulltexts to avoid bug 155730.
848
    UnreferencedFileParentsFromNoOpMergeScenario,
2745.6.54 by Andrew Bennetts
Tidy test parameterisation in repository_implementations.
849
    ]
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
850
2745.6.42 by Andrew Bennetts
Use TestScenarioApplier to more cleanly parameterise check and reconcile tests.
851
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
852
def load_tests(standard_tests, module, loader):
3689.1.1 by John Arbash Meinel
Rename repository_implementations tests into per_repository tests
853
    prefix = 'bzrlib.tests.per_repository.'
2745.6.58 by Andrew Bennetts
Slightly neater test parameterisation in repository_implementations; extract a 'multiply_scenarios' function.
854
    test_repository_modules = [
3221.12.1 by Robert Collins
Backport development1 format (stackable packs) to before-shallow-branches.
855
        'test_add_fallback_repository',
3879.2.2 by John Arbash Meinel
Rename add_inventory_delta to add_inventory_by_delta.
856
        'test_add_inventory_by_delta',
2745.6.57 by Andrew Bennetts
Some improvements suggested by Martin's review.
857
        'test_break_lock',
858
        'test_check',
2745.6.58 by Andrew Bennetts
Slightly neater test parameterisation in repository_implementations; extract a 'multiply_scenarios' function.
859
        # test_check_reconcile is intentionally omitted, see below.
2745.6.57 by Andrew Bennetts
Some improvements suggested by Martin's review.
860
        'test_commit_builder',
861
        'test_fetch',
862
        'test_fileid_involved',
2988.1.2 by Robert Collins
New Repository API find_text_key_references for use by reconcile and check.
863
        'test_find_text_key_references',
2988.1.3 by Robert Collins
Add a new repositoy method _generate_text_key_index for use by reconcile/check.
864
        'test__generate_text_key_index',
3373.5.2 by John Arbash Meinel
Add repository_implementation tests for get_parent_map
865
        'test_get_parent_map',
2745.6.57 by Andrew Bennetts
Some improvements suggested by Martin's review.
866
        'test_has_same_location',
3172.3.1 by Robert Collins
Repository has a new method ``has_revisions`` which signals the presence
867
        'test_has_revisions',
2904.1.2 by Robert Collins
Merge bzr.dev
868
        'test_is_write_locked',
2745.6.57 by Andrew Bennetts
Some improvements suggested by Martin's review.
869
        'test_iter_reverse_revision_history',
4543.2.3 by John Arbash Meinel
Change the name to test_merge_directive
870
        'test_merge_directive',
2745.6.57 by Andrew Bennetts
Some improvements suggested by Martin's review.
871
        'test_pack',
872
        'test_reconcile',
4145.1.2 by Robert Collins
Add a refresh_data method on Repository allowing cleaner handling of insertions into RemoteRepository objects with _real_repository instances.
873
        'test_refresh_data',
2745.6.57 by Andrew Bennetts
Some improvements suggested by Martin's review.
874
        'test_repository',
875
        'test_revision',
876
        'test_statistics',
877
        'test_write_group',
2745.6.54 by Andrew Bennetts
Tidy test parameterisation in repository_implementations.
878
        ]
3689.1.1 by John Arbash Meinel
Rename repository_implementations tests into per_repository tests
879
    # Parameterize per_repository test modules by format.
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
880
    submod_tests = loader.loadTestsFromModuleNames(
881
        [prefix + module_name for module_name in test_repository_modules])
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
882
    format_scenarios = all_repository_format_scenarios()
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
883
    multiply_tests(submod_tests, format_scenarios, standard_tests)
2745.6.58 by Andrew Bennetts
Slightly neater test parameterisation in repository_implementations; extract a 'multiply_scenarios' function.
884
3128.1.3 by Vincent Ladeuil
Since we are there s/parameteris.*/parameteriz&/.
885
    # test_check_reconcile needs to be parameterized by format *and* by broken
2745.6.58 by Andrew Bennetts
Slightly neater test parameterisation in repository_implementations; extract a 'multiply_scenarios' function.
886
    # repository scenario.
887
    broken_scenarios = [(s.__name__, {'scenario_class': s})
888
                        for s in all_broken_scenario_classes]
889
    broken_scenarios_for_all_formats = multiply_scenarios(
890
        format_scenarios, broken_scenarios)
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
891
    return multiply_tests(
892
        loader.loadTestsFromModuleNames([prefix + 'test_check_reconcile']),
893
        broken_scenarios_for_all_formats, standard_tests)