/brz/remove-bazaar

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