/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2005 Canonical Ltd
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
2
#
3
# Authors:
4
#   Johan Rydberg <jrydberg@gnu.org>
5
#
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
10
#
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
15
#
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20
1704.2.15 by Martin Pool
Remove TODO about knit testing printed from test suite
21
# TODO: might be nice to create a versionedfile with some type of corruption
22
# considered typical and check that it can be detected/corrected.
23
3350.3.16 by Robert Collins
Add test that out of order insertion fails with a clean error/does not fail.
24
from itertools import chain
1664.2.9 by Aaron Bentley
Ported weave merge test to versionedfile
25
from StringIO import StringIO
26
1563.2.6 by Robert Collins
Start check tests for knits (pending), and remove dead code.
27
import bzrlib
2039.1.1 by Aaron Bentley
Clean up progress properly when interrupted during fetch (#54000)
28
from bzrlib import (
29
    errors,
2309.4.7 by John Arbash Meinel
Update VersionedFile tests to ensure that they can take Unicode,
30
    osutils,
2039.1.1 by Aaron Bentley
Clean up progress properly when interrupted during fetch (#54000)
31
    progress,
32
    )
1563.2.11 by Robert Collins
Consolidate reweave and join as we have no separate usage, make reweave tests apply to all versionedfile implementations and deprecate the old reweave apis.
33
from bzrlib.errors import (
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
34
                           RevisionNotPresent,
1563.2.11 by Robert Collins
Consolidate reweave and join as we have no separate usage, make reweave tests apply to all versionedfile implementations and deprecate the old reweave apis.
35
                           RevisionAlreadyPresent,
36
                           WeaveParentMismatch
37
                           )
3350.3.4 by Robert Collins
Finish adapters for annotated knits to unannotated knits and full texts.
38
from bzrlib import knit as _mod_knit
2770.1.1 by Aaron Bentley
Initial implmentation of plain knit annotation
39
from bzrlib.knit import (
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
40
    make_file_knit,
2770.1.1 by Aaron Bentley
Initial implmentation of plain knit annotation
41
    KnitAnnotateFactory,
2770.1.10 by Aaron Bentley
Merge bzr.dev
42
    KnitPlainFactory,
2770.1.1 by Aaron Bentley
Initial implmentation of plain knit annotation
43
    )
3350.3.14 by Robert Collins
Deprecate VersionedFile.join.
44
from bzrlib.symbol_versioning import one_four, one_five
2535.3.48 by Andrew Bennetts
Merge from bzr.dev.
45
from bzrlib.tests import TestCaseWithMemoryTransport, TestSkipped
3102.1.1 by Vincent Ladeuil
Rename bzrlib/test/HTTPTestUtils.py to bzrlib/tests/http_utils.py and fix
46
from bzrlib.tests.http_utils import TestCaseWithWebserver
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
47
from bzrlib.trace import mutter
1563.2.16 by Robert Collins
Change WeaveStore into VersionedFileStore and make its versoined file class parameterisable.
48
from bzrlib.transport import get_transport
1563.2.13 by Robert Collins
InterVersionedFile implemented.
49
from bzrlib.transport.memory import MemoryTransport
1684.3.1 by Robert Collins
Fix versioned file joins with empty targets.
50
from bzrlib.tsort import topo_sort
3350.3.4 by Robert Collins
Finish adapters for annotated knits to unannotated knits and full texts.
51
from bzrlib.tuned_gzip import GzipFile
1563.2.12 by Robert Collins
Checkpointing: created InterObject to factor out common inter object worker code, added InterVersionedFile and tests to allow making join work between any versionedfile.
52
import bzrlib.versionedfile as versionedfile
1563.2.9 by Robert Collins
Update versionedfile api tests to ensure that data is available after every operation.
53
from bzrlib.weave import WeaveFile
1664.2.9 by Aaron Bentley
Ported weave merge test to versionedfile
54
from bzrlib.weavefile import read_weave, write_weave
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
55
56
3350.3.11 by Robert Collins
Test inserting a stream that overlaps the current content of a knit does not error.
57
def get_diamond_vf(f, trailing_eol=True, left_only=False):
3350.3.4 by Robert Collins
Finish adapters for annotated knits to unannotated knits and full texts.
58
    """Get a diamond graph to exercise deltas and merges.
59
    
60
    :param trailing_eol: If True end the last line with \n.
61
    """
62
    parents = {
63
        'origin': (),
64
        'base': (('origin',),),
65
        'left': (('base',),),
66
        'right': (('base',),),
67
        'merged': (('left',), ('right',)),
68
        }
69
    # insert a diamond graph to exercise deltas and merges.
70
    if trailing_eol:
71
        last_char = '\n'
72
    else:
73
        last_char = ''
74
    f.add_lines('origin', [], ['origin' + last_char])
75
    f.add_lines('base', ['origin'], ['base' + last_char])
76
    f.add_lines('left', ['base'], ['base\n', 'left' + last_char])
3350.3.11 by Robert Collins
Test inserting a stream that overlaps the current content of a knit does not error.
77
    if not left_only:
78
        f.add_lines('right', ['base'],
79
            ['base\n', 'right' + last_char])
80
        f.add_lines('merged', ['left', 'right'],
81
            ['base\n', 'left\n', 'right\n', 'merged' + last_char])
3350.3.4 by Robert Collins
Finish adapters for annotated knits to unannotated knits and full texts.
82
    return f, parents
83
84
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
85
class VersionedFileTestMixIn(object):
86
    """A mixin test class for testing VersionedFiles.
87
88
    This is not an adaptor-style test at this point because
89
    theres no dynamic substitution of versioned file implementations,
90
    they are strictly controlled by their owning repositories.
91
    """
92
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
93
    def get_transaction(self):
94
        if not hasattr(self, '_transaction'):
95
            self._transaction = None
96
        return self._transaction
97
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
98
    def test_add(self):
99
        f = self.get_file()
100
        f.add_lines('r0', [], ['a\n', 'b\n'])
101
        f.add_lines('r1', ['r0'], ['b\n', 'c\n'])
1563.2.9 by Robert Collins
Update versionedfile api tests to ensure that data is available after every operation.
102
        def verify_file(f):
103
            versions = f.versions()
104
            self.assertTrue('r0' in versions)
105
            self.assertTrue('r1' in versions)
106
            self.assertEquals(f.get_lines('r0'), ['a\n', 'b\n'])
107
            self.assertEquals(f.get_text('r0'), 'a\nb\n')
108
            self.assertEquals(f.get_lines('r1'), ['b\n', 'c\n'])
1563.2.18 by Robert Collins
get knit repositories really using knits for text storage.
109
            self.assertEqual(2, len(f))
110
            self.assertEqual(2, f.num_versions())
1563.2.9 by Robert Collins
Update versionedfile api tests to ensure that data is available after every operation.
111
    
112
            self.assertRaises(RevisionNotPresent,
113
                f.add_lines, 'r2', ['foo'], [])
114
            self.assertRaises(RevisionAlreadyPresent,
115
                f.add_lines, 'r1', [], [])
116
        verify_file(f)
1666.1.6 by Robert Collins
Make knit the default format.
117
        # this checks that reopen with create=True does not break anything.
118
        f = self.reopen_file(create=True)
1563.2.9 by Robert Collins
Update versionedfile api tests to ensure that data is available after every operation.
119
        verify_file(f)
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
120
3350.3.3 by Robert Collins
Functional get_record_stream interface tests covering full interface.
121
    def test_get_record_stream_empty(self):
122
        """get_record_stream is a replacement for get_data_stream."""
123
        f = self.get_file()
124
        entries = f.get_record_stream([], 'unordered', False)
125
        self.assertEqual([], list(entries))
126
127
    def assertValidStorageKind(self, storage_kind):
128
        """Assert that storage_kind is a valid storage_kind."""
129
        self.assertSubset([storage_kind],
130
            ['mpdiff', 'knit-annotated-ft', 'knit-annotated-delta',
131
             'knit-ft', 'knit-delta', 'fulltext', 'knit-annotated-ft-gz',
132
             'knit-annotated-delta-gz', 'knit-ft-gz', 'knit-delta-gz'])
133
134
    def capture_stream(self, f, entries, on_seen, parents):
135
        """Capture a stream for testing."""
136
        for factory in entries:
137
            on_seen(factory.key)
138
            self.assertValidStorageKind(factory.storage_kind)
139
            self.assertEqual(f.get_sha1s([factory.key[0]])[0], factory.sha1)
140
            self.assertEqual(parents[factory.key[0]], factory.parents)
141
            self.assertIsInstance(factory.get_bytes_as(factory.storage_kind),
142
                str)
143
144
    def test_get_record_stream_interface(self):
3350.3.22 by Robert Collins
Review feedback.
145
        """Each item in a stream has to provide a regular interface."""
3350.3.4 by Robert Collins
Finish adapters for annotated knits to unannotated knits and full texts.
146
        f, parents = get_diamond_vf(self.get_file())
3350.3.3 by Robert Collins
Functional get_record_stream interface tests covering full interface.
147
        entries = f.get_record_stream(['merged', 'left', 'right', 'base'],
148
            'unordered', False)
149
        seen = set()
150
        self.capture_stream(f, entries, seen.add, parents)
151
        self.assertEqual(set([('base',), ('left',), ('right',), ('merged',)]),
152
            seen)
153
154
    def test_get_record_stream_interface_ordered(self):
3350.3.22 by Robert Collins
Review feedback.
155
        """Each item in a stream has to provide a regular interface."""
3350.3.4 by Robert Collins
Finish adapters for annotated knits to unannotated knits and full texts.
156
        f, parents = get_diamond_vf(self.get_file())
3350.3.3 by Robert Collins
Functional get_record_stream interface tests covering full interface.
157
        entries = f.get_record_stream(['merged', 'left', 'right', 'base'],
158
            'topological', False)
159
        seen = []
160
        self.capture_stream(f, entries, seen.append, parents)
161
        self.assertSubset([tuple(seen)],
162
            (
163
             (('base',), ('left',), ('right',), ('merged',)),
164
             (('base',), ('right',), ('left',), ('merged',)),
165
            ))
166
167
    def test_get_record_stream_interface_ordered_with_delta_closure(self):
3350.3.22 by Robert Collins
Review feedback.
168
        """Each item in a stream has to provide a regular interface."""
3350.3.4 by Robert Collins
Finish adapters for annotated knits to unannotated knits and full texts.
169
        f, parents = get_diamond_vf(self.get_file())
3350.3.3 by Robert Collins
Functional get_record_stream interface tests covering full interface.
170
        entries = f.get_record_stream(['merged', 'left', 'right', 'base'],
171
            'topological', True)
172
        seen = []
173
        for factory in entries:
174
            seen.append(factory.key)
175
            self.assertValidStorageKind(factory.storage_kind)
176
            self.assertEqual(f.get_sha1s([factory.key[0]])[0], factory.sha1)
177
            self.assertEqual(parents[factory.key[0]], factory.parents)
178
            self.assertEqual(f.get_text(factory.key[0]),
179
                factory.get_bytes_as('fulltext'))
180
            self.assertIsInstance(factory.get_bytes_as(factory.storage_kind),
181
                str)
182
        self.assertSubset([tuple(seen)],
183
            (
184
             (('base',), ('left',), ('right',), ('merged',)),
185
             (('base',), ('right',), ('left',), ('merged',)),
186
            ))
187
188
    def test_get_record_stream_unknown_storage_kind_raises(self):
189
        """Asking for a storage kind that the stream cannot supply raises."""
3350.3.4 by Robert Collins
Finish adapters for annotated knits to unannotated knits and full texts.
190
        f, parents = get_diamond_vf(self.get_file())
3350.3.3 by Robert Collins
Functional get_record_stream interface tests covering full interface.
191
        entries = f.get_record_stream(['merged', 'left', 'right', 'base'],
192
            'unordered', False)
193
        # We track the contents because we should be able to try, fail a
194
        # particular kind and then ask for one that works and continue.
195
        seen = set()
196
        for factory in entries:
197
            seen.add(factory.key)
198
            self.assertValidStorageKind(factory.storage_kind)
199
            self.assertEqual(f.get_sha1s([factory.key[0]])[0], factory.sha1)
200
            self.assertEqual(parents[factory.key[0]], factory.parents)
201
            # currently no stream emits mpdiff
202
            self.assertRaises(errors.UnavailableRepresentation,
203
                factory.get_bytes_as, 'mpdiff')
204
            self.assertIsInstance(factory.get_bytes_as(factory.storage_kind),
205
                str)
206
        self.assertEqual(set([('base',), ('left',), ('right',), ('merged',)]),
207
            seen)
208
3350.3.12 by Robert Collins
Generate streams with absent records.
209
    def test_get_record_stream_missing_records_are_absent(self):
210
        f, parents = get_diamond_vf(self.get_file())
211
        entries = f.get_record_stream(['merged', 'left', 'right', 'or', 'base'],
212
            'unordered', False)
3350.3.18 by Robert Collins
Test absent record emission more stringently.
213
        self.assertAbsentRecord(f, parents, entries)
214
        entries = f.get_record_stream(['merged', 'left', 'right', 'or', 'base'],
215
            'topological', False)
216
        self.assertAbsentRecord(f, parents, entries)
217
218
    def assertAbsentRecord(self, f, parents, entries):
219
        """Helper for test_get_record_stream_missing_records_are_absent."""
3350.3.12 by Robert Collins
Generate streams with absent records.
220
        seen = set()
221
        for factory in entries:
222
            seen.add(factory.key)
223
            if factory.key == ('or',):
224
                self.assertEqual('absent', factory.storage_kind)
225
                self.assertEqual(None, factory.sha1)
226
                self.assertEqual(None, factory.parents)
227
            else:
228
                self.assertValidStorageKind(factory.storage_kind)
229
                self.assertEqual(f.get_sha1s([factory.key[0]])[0], factory.sha1)
230
                self.assertEqual(parents[factory.key[0]], factory.parents)
231
                self.assertIsInstance(factory.get_bytes_as(factory.storage_kind),
232
                    str)
233
        self.assertEqual(
234
            set([('base',), ('left',), ('right',), ('merged',), ('or',)]),
235
            seen)
236
3350.3.14 by Robert Collins
Deprecate VersionedFile.join.
237
    def test_filter_absent_records(self):
238
        """Requested missing records can be filter trivially."""
239
        f, parents = get_diamond_vf(self.get_file())
240
        entries = f.get_record_stream(['merged', 'left', 'right', 'extra', 'base'],
241
            'unordered', False)
242
        seen = set()
243
        self.capture_stream(f, versionedfile.filter_absent(entries), seen.add,
244
            parents)
245
        self.assertEqual(set([('base',), ('left',), ('right',), ('merged',)]),
246
            seen)
3350.3.12 by Robert Collins
Generate streams with absent records.
247
3350.3.8 by Robert Collins
Basic stream insertion, no fast path yet for knit to knit.
248
    def test_insert_record_stream_empty(self):
249
        """Inserting an empty record stream should work."""
250
        f = self.get_file()
251
        stream = []
252
        f.insert_record_stream([])
253
254
    def assertIdenticalVersionedFile(self, left, right):
255
        """Assert that left and right have the same contents."""
256
        self.assertEqual(set(left.versions()), set(right.versions()))
257
        self.assertEqual(left.get_parent_map(left.versions()),
258
            right.get_parent_map(right.versions()))
259
        for v in left.versions():
260
            self.assertEqual(left.get_text(v), right.get_text(v))
261
262
    def test_insert_record_stream_fulltexts(self):
263
        """Any file should accept a stream of fulltexts."""
264
        f = self.get_file()
265
        weave_vf = WeaveFile('source', get_transport(self.get_url('.')),
266
            create=True, get_scope=self.get_transaction)
267
        source, _ = get_diamond_vf(weave_vf)
268
        stream = source.get_record_stream(source.versions(), 'topological',
269
            False)
270
        f.insert_record_stream(stream)
271
        self.assertIdenticalVersionedFile(f, source)
272
273
    def test_insert_record_stream_fulltexts_noeol(self):
274
        """Any file should accept a stream of fulltexts."""
275
        f = self.get_file()
276
        weave_vf = WeaveFile('source', get_transport(self.get_url('.')),
277
            create=True, get_scope=self.get_transaction)
278
        source, _ = get_diamond_vf(weave_vf, trailing_eol=False)
279
        stream = source.get_record_stream(source.versions(), 'topological',
280
            False)
281
        f.insert_record_stream(stream)
282
        self.assertIdenticalVersionedFile(f, source)
283
284
    def test_insert_record_stream_annotated_knits(self):
285
        """Any file should accept a stream from plain knits."""
286
        f = self.get_file()
287
        source = make_file_knit('source', get_transport(self.get_url('.')),
288
            create=True)
289
        get_diamond_vf(source)
290
        stream = source.get_record_stream(source.versions(), 'topological',
291
            False)
292
        f.insert_record_stream(stream)
293
        self.assertIdenticalVersionedFile(f, source)
294
295
    def test_insert_record_stream_annotated_knits_noeol(self):
296
        """Any file should accept a stream from plain knits."""
297
        f = self.get_file()
298
        source = make_file_knit('source', get_transport(self.get_url('.')),
299
            create=True)
300
        get_diamond_vf(source, trailing_eol=False)
301
        stream = source.get_record_stream(source.versions(), 'topological',
302
            False)
303
        f.insert_record_stream(stream)
304
        self.assertIdenticalVersionedFile(f, source)
305
306
    def test_insert_record_stream_plain_knits(self):
307
        """Any file should accept a stream from plain knits."""
308
        f = self.get_file()
309
        source = make_file_knit('source', get_transport(self.get_url('.')),
310
            create=True, factory=KnitPlainFactory())
311
        get_diamond_vf(source)
312
        stream = source.get_record_stream(source.versions(), 'topological',
313
            False)
314
        f.insert_record_stream(stream)
315
        self.assertIdenticalVersionedFile(f, source)
316
317
    def test_insert_record_stream_plain_knits_noeol(self):
318
        """Any file should accept a stream from plain knits."""
319
        f = self.get_file()
320
        source = make_file_knit('source', get_transport(self.get_url('.')),
321
            create=True, factory=KnitPlainFactory())
322
        get_diamond_vf(source, trailing_eol=False)
323
        stream = source.get_record_stream(source.versions(), 'topological',
324
            False)
325
        f.insert_record_stream(stream)
326
        self.assertIdenticalVersionedFile(f, source)
327
3350.3.11 by Robert Collins
Test inserting a stream that overlaps the current content of a knit does not error.
328
    def test_insert_record_stream_existing_keys(self):
329
        """Inserting keys already in a file should not error."""
330
        f = self.get_file()
331
        source = make_file_knit('source', get_transport(self.get_url('.')),
332
            create=True, factory=KnitPlainFactory())
333
        get_diamond_vf(source)
334
        # insert some keys into f.
335
        get_diamond_vf(f, left_only=True)
336
        stream = source.get_record_stream(source.versions(), 'topological',
337
            False)
338
        f.insert_record_stream(stream)
339
        self.assertIdenticalVersionedFile(f, source)
340
3350.3.15 by Robert Collins
Update the insert_record_stream contract to error if an absent record is provided.
341
    def test_insert_record_stream_missing_keys(self):
342
        """Inserting a stream with absent keys should raise an error."""
343
        f = self.get_file()
344
        source = make_file_knit('source', get_transport(self.get_url('.')),
345
            create=True, factory=KnitPlainFactory())
346
        stream = source.get_record_stream(['missing'], 'topological',
347
            False)
348
        self.assertRaises(errors.RevisionNotPresent, f.insert_record_stream,
349
            stream)
350
3350.3.16 by Robert Collins
Add test that out of order insertion fails with a clean error/does not fail.
351
    def test_insert_record_stream_out_of_order(self):
352
        """An out of order stream can either error or work."""
353
        f, parents = get_diamond_vf(self.get_file())
354
        origin_entries = f.get_record_stream(['origin'], 'unordered', False)
355
        end_entries = f.get_record_stream(['merged', 'left'],
356
            'topological', False)
357
        start_entries = f.get_record_stream(['right', 'base'],
358
            'topological', False)
359
        entries = chain(origin_entries, end_entries, start_entries)
360
        target = self.get_file('target')
361
        try:
362
            target.insert_record_stream(entries)
363
        except RevisionNotPresent:
364
            # Must not have corrupted the file.
365
            target.check()
366
        else:
367
            self.assertIdenticalVersionedFile(f, target)
368
3350.3.17 by Robert Collins
Prevent corrupt knits being created when a stream is interrupted with basis parents not present.
369
    def test_insert_record_stream_delta_missing_basis_no_corruption(self):
370
        """Insertion where a needed basis is not included aborts safely."""
371
        # Annotated source - deltas can be used in any knit.
372
        source = make_file_knit('source', get_transport(self.get_url('.')),
373
            create=True)
374
        get_diamond_vf(source)
375
        entries = source.get_record_stream(['origin', 'merged'], 'unordered', False)
376
        f = self.get_file()
377
        self.assertRaises(RevisionNotPresent, f.insert_record_stream, entries)
378
        f.check()
379
        self.assertFalse(f.has_version('merged'))
380
1596.2.32 by Robert Collins
Reduce re-extraction of texts during weave to knit joins by providing a memoisation facility.
381
    def test_adds_with_parent_texts(self):
382
        f = self.get_file()
383
        parent_texts = {}
2776.1.1 by Robert Collins
* The ``add_lines`` methods on ``VersionedFile`` implementations has changed
384
        _, _, parent_texts['r0'] = f.add_lines('r0', [], ['a\n', 'b\n'])
1596.2.32 by Robert Collins
Reduce re-extraction of texts during weave to knit joins by providing a memoisation facility.
385
        try:
2776.1.1 by Robert Collins
* The ``add_lines`` methods on ``VersionedFile`` implementations has changed
386
            _, _, parent_texts['r1'] = f.add_lines_with_ghosts('r1',
387
                ['r0', 'ghost'], ['b\n', 'c\n'], parent_texts=parent_texts)
1596.2.32 by Robert Collins
Reduce re-extraction of texts during weave to knit joins by providing a memoisation facility.
388
        except NotImplementedError:
389
            # if the format doesn't support ghosts, just add normally.
2776.1.1 by Robert Collins
* The ``add_lines`` methods on ``VersionedFile`` implementations has changed
390
            _, _, parent_texts['r1'] = f.add_lines('r1',
391
                ['r0'], ['b\n', 'c\n'], parent_texts=parent_texts)
1596.2.32 by Robert Collins
Reduce re-extraction of texts during weave to knit joins by providing a memoisation facility.
392
        f.add_lines('r2', ['r1'], ['c\n', 'd\n'], parent_texts=parent_texts)
393
        self.assertNotEqual(None, parent_texts['r0'])
394
        self.assertNotEqual(None, parent_texts['r1'])
395
        def verify_file(f):
396
            versions = f.versions()
397
            self.assertTrue('r0' in versions)
398
            self.assertTrue('r1' in versions)
399
            self.assertTrue('r2' in versions)
400
            self.assertEquals(f.get_lines('r0'), ['a\n', 'b\n'])
401
            self.assertEquals(f.get_lines('r1'), ['b\n', 'c\n'])
402
            self.assertEquals(f.get_lines('r2'), ['c\n', 'd\n'])
403
            self.assertEqual(3, f.num_versions())
404
            origins = f.annotate('r1')
405
            self.assertEquals(origins[0][0], 'r0')
406
            self.assertEquals(origins[1][0], 'r1')
407
            origins = f.annotate('r2')
408
            self.assertEquals(origins[0][0], 'r1')
409
            self.assertEquals(origins[1][0], 'r2')
410
411
        verify_file(f)
412
        f = self.reopen_file()
413
        verify_file(f)
414
2805.6.7 by Robert Collins
Review feedback.
415
    def test_add_unicode_content(self):
416
        # unicode content is not permitted in versioned files. 
417
        # versioned files version sequences of bytes only.
418
        vf = self.get_file()
419
        self.assertRaises(errors.BzrBadParameterUnicode,
420
            vf.add_lines, 'a', [], ['a\n', u'b\n', 'c\n'])
421
        self.assertRaises(
422
            (errors.BzrBadParameterUnicode, NotImplementedError),
423
            vf.add_lines_with_ghosts, 'a', [], ['a\n', u'b\n', 'c\n'])
424
2520.4.150 by Aaron Bentley
Test that non-Weave uses left_matching_blocks for add_lines
425
    def test_add_follows_left_matching_blocks(self):
426
        """If we change left_matching_blocks, delta changes
427
428
        Note: There are multiple correct deltas in this case, because
429
        we start with 1 "a" and we get 3.
430
        """
431
        vf = self.get_file()
432
        if isinstance(vf, WeaveFile):
433
            raise TestSkipped("WeaveFile ignores left_matching_blocks")
434
        vf.add_lines('1', [], ['a\n'])
435
        vf.add_lines('2', ['1'], ['a\n', 'a\n', 'a\n'],
436
                     left_matching_blocks=[(0, 0, 1), (1, 3, 0)])
2794.1.2 by Robert Collins
Nuke versioned file add/get delta support, allowing easy simplification of unannotated Content, reducing memory copies and friction during commit on unannotated texts.
437
        self.assertEqual(['a\n', 'a\n', 'a\n'], vf.get_lines('2'))
2520.4.150 by Aaron Bentley
Test that non-Weave uses left_matching_blocks for add_lines
438
        vf.add_lines('3', ['1'], ['a\n', 'a\n', 'a\n'],
439
                     left_matching_blocks=[(0, 2, 1), (1, 3, 0)])
2794.1.2 by Robert Collins
Nuke versioned file add/get delta support, allowing easy simplification of unannotated Content, reducing memory copies and friction during commit on unannotated texts.
440
        self.assertEqual(['a\n', 'a\n', 'a\n'], vf.get_lines('3'))
2520.4.150 by Aaron Bentley
Test that non-Weave uses left_matching_blocks for add_lines
441
2805.6.7 by Robert Collins
Review feedback.
442
    def test_inline_newline_throws(self):
443
        # \r characters are not permitted in lines being added
444
        vf = self.get_file()
445
        self.assertRaises(errors.BzrBadParameterContainsNewline, 
446
            vf.add_lines, 'a', [], ['a\n\n'])
447
        self.assertRaises(
448
            (errors.BzrBadParameterContainsNewline, NotImplementedError),
449
            vf.add_lines_with_ghosts, 'a', [], ['a\n\n'])
450
        # but inline CR's are allowed
451
        vf.add_lines('a', [], ['a\r\n'])
452
        try:
453
            vf.add_lines_with_ghosts('b', [], ['a\r\n'])
454
        except NotImplementedError:
455
            pass
456
2229.2.1 by Aaron Bentley
Reject reserved ids in versiondfile, tree, branch and repository
457
    def test_add_reserved(self):
458
        vf = self.get_file()
459
        self.assertRaises(errors.ReservedId,
460
            vf.add_lines, 'a:', [], ['a\n', 'b\n', 'c\n'])
461
2794.1.1 by Robert Collins
Allow knits to be instructed not to add a text based on a sha, for commit.
462
    def test_add_lines_nostoresha(self):
463
        """When nostore_sha is supplied using old content raises."""
464
        vf = self.get_file()
465
        empty_text = ('a', [])
466
        sample_text_nl = ('b', ["foo\n", "bar\n"])
467
        sample_text_no_nl = ('c', ["foo\n", "bar"])
468
        shas = []
469
        for version, lines in (empty_text, sample_text_nl, sample_text_no_nl):
470
            sha, _, _ = vf.add_lines(version, [], lines)
471
            shas.append(sha)
472
        # we now have a copy of all the lines in the vf.
473
        for sha, (version, lines) in zip(
474
            shas, (empty_text, sample_text_nl, sample_text_no_nl)):
475
            self.assertRaises(errors.ExistingContent,
476
                vf.add_lines, version + "2", [], lines,
477
                nostore_sha=sha)
478
            # and no new version should have been added.
479
            self.assertRaises(errors.RevisionNotPresent, vf.get_lines,
480
                version + "2")
481
2803.1.1 by Robert Collins
Fix typo in ghosts version of test_add_lines_nostoresha.
482
    def test_add_lines_with_ghosts_nostoresha(self):
2794.1.1 by Robert Collins
Allow knits to be instructed not to add a text based on a sha, for commit.
483
        """When nostore_sha is supplied using old content raises."""
484
        vf = self.get_file()
485
        empty_text = ('a', [])
486
        sample_text_nl = ('b', ["foo\n", "bar\n"])
487
        sample_text_no_nl = ('c', ["foo\n", "bar"])
488
        shas = []
489
        for version, lines in (empty_text, sample_text_nl, sample_text_no_nl):
490
            sha, _, _ = vf.add_lines(version, [], lines)
491
            shas.append(sha)
492
        # we now have a copy of all the lines in the vf.
493
        # is the test applicable to this vf implementation?
494
        try:
495
            vf.add_lines_with_ghosts('d', [], [])
496
        except NotImplementedError:
497
            raise TestSkipped("add_lines_with_ghosts is optional")
498
        for sha, (version, lines) in zip(
499
            shas, (empty_text, sample_text_nl, sample_text_no_nl)):
500
            self.assertRaises(errors.ExistingContent,
501
                vf.add_lines_with_ghosts, version + "2", [], lines,
502
                nostore_sha=sha)
503
            # and no new version should have been added.
504
            self.assertRaises(errors.RevisionNotPresent, vf.get_lines,
505
                version + "2")
506
2776.1.1 by Robert Collins
* The ``add_lines`` methods on ``VersionedFile`` implementations has changed
507
    def test_add_lines_return_value(self):
508
        # add_lines should return the sha1 and the text size.
509
        vf = self.get_file()
510
        empty_text = ('a', [])
511
        sample_text_nl = ('b', ["foo\n", "bar\n"])
512
        sample_text_no_nl = ('c', ["foo\n", "bar"])
513
        # check results for the three cases:
514
        for version, lines in (empty_text, sample_text_nl, sample_text_no_nl):
515
            # the first two elements are the same for all versioned files:
516
            # - the digest and the size of the text. For some versioned files
517
            #   additional data is returned in additional tuple elements.
518
            result = vf.add_lines(version, [], lines)
519
            self.assertEqual(3, len(result))
520
            self.assertEqual((osutils.sha_strings(lines), sum(map(len, lines))),
521
                result[0:2])
522
        # parents should not affect the result:
523
        lines = sample_text_nl[1]
524
        self.assertEqual((osutils.sha_strings(lines), sum(map(len, lines))),
525
            vf.add_lines('d', ['b', 'c'], lines)[0:2])
526
2229.2.1 by Aaron Bentley
Reject reserved ids in versiondfile, tree, branch and repository
527
    def test_get_reserved(self):
528
        vf = self.get_file()
529
        self.assertRaises(errors.ReservedId, vf.get_texts, ['b:'])
530
        self.assertRaises(errors.ReservedId, vf.get_lines, 'b:')
531
        self.assertRaises(errors.ReservedId, vf.get_text, 'b:')
532
3468.2.4 by Martin Pool
Test and fix #234748 problems in trailing newline diffs
533
    def test_add_unchanged_last_line_noeol_snapshot(self):
534
        """Add a text with an unchanged last line with no eol should work."""
535
        # Test adding this in a number of chain lengths; because the interface
536
        # for VersionedFile does not allow forcing a specific chain length, we
537
        # just use a small base to get the first snapshot, then a much longer
538
        # first line for the next add (which will make the third add snapshot)
539
        # and so on. 20 has been chosen as an aribtrary figure - knits use 200
540
        # as a capped delta length, but ideally we would have some way of
541
        # tuning the test to the store (e.g. keep going until a snapshot
542
        # happens).
543
        for length in range(20):
544
            version_lines = {}
545
            vf = self.get_file('case-%d' % length)
546
            prefix = 'step-%d'
547
            parents = []
548
            for step in range(length):
549
                version = prefix % step
550
                lines = (['prelude \n'] * step) + ['line']
551
                vf.add_lines(version, parents, lines)
552
                version_lines[version] = lines
553
                parents = [version]
554
            vf.add_lines('no-eol', parents, ['line'])
555
            vf.get_texts(version_lines.keys())
556
            self.assertEqualDiff('line', vf.get_text('no-eol'))
557
558
    def test_get_texts_eol_variation(self):
559
        # similar to the failure in <http://bugs.launchpad.net/234748>
560
        vf = self.get_file()
561
        sample_text_nl = ["line\n"]
562
        sample_text_no_nl = ["line"]
563
        versions = []
564
        version_lines = {}
565
        parents = []
566
        for i in range(4):
567
            version = 'v%d' % i
568
            if i % 2:
569
                lines = sample_text_nl
570
            else:
571
                lines = sample_text_no_nl
572
            # left_matching blocks is an internal api; it operates on the
573
            # *internal* representation for a knit, which is with *all* lines
574
            # being normalised to end with \n - even the final line in a no_nl
575
            # file. Using it here ensures that a broken internal implementation
576
            # (which is what this test tests) will generate a correct line
577
            # delta (which is to say, an empty delta).
578
            vf.add_lines(version, parents, lines,
579
                left_matching_blocks=[(0, 0, 1)])
580
            parents = [version]
581
            versions.append(version)
582
            version_lines[version] = lines
583
        vf.check()
584
        vf.get_texts(versions)
585
        vf.get_texts(reversed(versions))
586
3460.2.1 by Robert Collins
* Inserting a bundle which changes the contents of a file with no trailing
587
    def test_add_lines_with_matching_blocks_noeol_last_line(self):
588
        """Add a text with an unchanged last line with no eol should work."""
589
        from bzrlib import multiparent
590
        # Hand verified sha1 of the text we're adding.
591
        sha1 = '6a1d115ec7b60afb664dc14890b5af5ce3c827a4'
592
        # Create a mpdiff which adds a new line before the trailing line, and
593
        # reuse the last line unaltered (which can cause annotation reuse).
594
        # Test adding this in two situations:
595
        # On top of a new insertion
596
        vf = self.get_file('fulltext')
597
        vf.add_lines('noeol', [], ['line'])
598
        vf.add_lines('noeol2', ['noeol'], ['newline\n', 'line'],
599
            left_matching_blocks=[(0, 1, 1)])
600
        self.assertEqualDiff('newline\nline', vf.get_text('noeol2'))
601
        # On top of a delta
602
        vf = self.get_file('delta')
603
        vf.add_lines('base', [], ['line'])
604
        vf.add_lines('noeol', ['base'], ['prelude\n', 'line'])
605
        vf.add_lines('noeol2', ['noeol'], ['newline\n', 'line'],
606
            left_matching_blocks=[(1, 1, 1)])
607
        self.assertEqualDiff('newline\nline', vf.get_text('noeol2'))
608
2520.4.85 by Aaron Bentley
Get all test passing (which just proves there aren't enough tests!)
609
    def test_make_mpdiffs(self):
2520.4.3 by Aaron Bentley
Implement plain strategy for extracting and installing multiparent diffs
610
        from bzrlib import multiparent
611
        vf = self.get_file('foo')
612
        sha1s = self._setup_for_deltas(vf)
613
        new_vf = self.get_file('bar')
614
        for version in multiparent.topo_iter(vf):
2520.4.85 by Aaron Bentley
Get all test passing (which just proves there aren't enough tests!)
615
            mpdiff = vf.make_mpdiffs([version])[0]
3287.5.2 by Robert Collins
Deprecate VersionedFile.get_parents, breaking pulling from a ghost containing knit or pack repository to weaves, which improves correctness and allows simplification of core code.
616
            new_vf.add_mpdiffs([(version, vf.get_parent_map([version])[version],
3316.2.9 by Robert Collins
* ``VersionedFile.get_sha1`` is deprecated, please use
617
                                 vf.get_sha1s([version])[0], mpdiff)])
2520.4.3 by Aaron Bentley
Implement plain strategy for extracting and installing multiparent diffs
618
            self.assertEqualDiff(vf.get_text(version),
619
                                 new_vf.get_text(version))
620
3453.3.2 by John Arbash Meinel
Add a test case for the first loop, unable to find a way to trigger the second loop
621
    def test_make_mpdiffs_with_ghosts(self):
622
        vf = self.get_file('foo')
3453.3.4 by John Arbash Meinel
Skip the new test for old weave formats that don't support ghosts
623
        try:
624
            vf.add_lines_with_ghosts('text', ['ghost'], ['line\n'])
625
        except NotImplementedError:
626
            # old Weave formats do not allow ghosts
627
            return
3453.3.2 by John Arbash Meinel
Add a test case for the first loop, unable to find a way to trigger the second loop
628
        self.assertRaises(errors.RevisionNotPresent, vf.make_mpdiffs, ['ghost'])
629
1596.2.38 by Robert Collins
rollback from using deltas to using fulltexts - deltas need more work to be ready.
630
    def _setup_for_deltas(self, f):
2794.1.2 by Robert Collins
Nuke versioned file add/get delta support, allowing easy simplification of unannotated Content, reducing memory copies and friction during commit on unannotated texts.
631
        self.assertFalse(f.has_version('base'))
1596.2.36 by Robert Collins
add a get_delta api to versioned_file.
632
        # add texts that should trip the knit maximum delta chain threshold
633
        # as well as doing parallel chains of data in knits.
634
        # this is done by two chains of 25 insertions
635
        f.add_lines('base', [], ['line\n'])
1596.2.38 by Robert Collins
rollback from using deltas to using fulltexts - deltas need more work to be ready.
636
        f.add_lines('noeol', ['base'], ['line'])
637
        # detailed eol tests:
638
        # shared last line with parent no-eol
639
        f.add_lines('noeolsecond', ['noeol'], ['line\n', 'line'])
640
        # differing last line with parent, both no-eol
641
        f.add_lines('noeolnotshared', ['noeolsecond'], ['line\n', 'phone'])
642
        # add eol following a noneol parent, change content
643
        f.add_lines('eol', ['noeol'], ['phone\n'])
644
        # add eol following a noneol parent, no change content
645
        f.add_lines('eolline', ['noeol'], ['line\n'])
646
        # noeol with no parents:
647
        f.add_lines('noeolbase', [], ['line'])
648
        # noeol preceeding its leftmost parent in the output:
649
        # this is done by making it a merge of two parents with no common
650
        # anestry: noeolbase and noeol with the 
651
        # later-inserted parent the leftmost.
652
        f.add_lines('eolbeforefirstparent', ['noeolbase', 'noeol'], ['line'])
653
        # two identical eol texts
654
        f.add_lines('noeoldup', ['noeol'], ['line'])
1596.2.36 by Robert Collins
add a get_delta api to versioned_file.
655
        next_parent = 'base'
656
        text_name = 'chain1-'
657
        text = ['line\n']
658
        sha1s = {0 :'da6d3141cb4a5e6f464bf6e0518042ddc7bfd079',
659
                 1 :'45e21ea146a81ea44a821737acdb4f9791c8abe7',
660
                 2 :'e1f11570edf3e2a070052366c582837a4fe4e9fa',
661
                 3 :'26b4b8626da827088c514b8f9bbe4ebf181edda1',
662
                 4 :'e28a5510be25ba84d31121cff00956f9970ae6f6',
663
                 5 :'d63ec0ce22e11dcf65a931b69255d3ac747a318d',
664
                 6 :'2c2888d288cb5e1d98009d822fedfe6019c6a4ea',
665
                 7 :'95c14da9cafbf828e3e74a6f016d87926ba234ab',
666
                 8 :'779e9a0b28f9f832528d4b21e17e168c67697272',
667
                 9 :'1f8ff4e5c6ff78ac106fcfe6b1e8cb8740ff9a8f',
668
                 10:'131a2ae712cf51ed62f143e3fbac3d4206c25a05',
669
                 11:'c5a9d6f520d2515e1ec401a8f8a67e6c3c89f199',
670
                 12:'31a2286267f24d8bedaa43355f8ad7129509ea85',
671
                 13:'dc2a7fe80e8ec5cae920973973a8ee28b2da5e0a',
672
                 14:'2c4b1736566b8ca6051e668de68650686a3922f2',
673
                 15:'5912e4ecd9b0c07be4d013e7e2bdcf9323276cde',
674
                 16:'b0d2e18d3559a00580f6b49804c23fea500feab3',
675
                 17:'8e1d43ad72f7562d7cb8f57ee584e20eb1a69fc7',
676
                 18:'5cf64a3459ae28efa60239e44b20312d25b253f3',
677
                 19:'1ebed371807ba5935958ad0884595126e8c4e823',
678
                 20:'2aa62a8b06fb3b3b892a3292a068ade69d5ee0d3',
679
                 21:'01edc447978004f6e4e962b417a4ae1955b6fe5d',
680
                 22:'d8d8dc49c4bf0bab401e0298bb5ad827768618bb',
681
                 23:'c21f62b1c482862983a8ffb2b0c64b3451876e3f',
682
                 24:'c0593fe795e00dff6b3c0fe857a074364d5f04fc',
683
                 25:'dd1a1cf2ba9cc225c3aff729953e6364bf1d1855',
684
                 }
685
        for depth in range(26):
686
            new_version = text_name + '%s' % depth
687
            text = text + ['line\n']
688
            f.add_lines(new_version, [next_parent], text)
689
            next_parent = new_version
690
        next_parent = 'base'
691
        text_name = 'chain2-'
692
        text = ['line\n']
693
        for depth in range(26):
694
            new_version = text_name + '%s' % depth
695
            text = text + ['line\n']
696
            f.add_lines(new_version, [next_parent], text)
697
            next_parent = new_version
1596.2.38 by Robert Collins
rollback from using deltas to using fulltexts - deltas need more work to be ready.
698
        return sha1s
1596.2.37 by Robert Collins
Switch to delta based content copying in the generic versioned file copier.
699
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
700
    def test_ancestry(self):
701
        f = self.get_file()
1563.2.29 by Robert Collins
Remove all but fetch references to repository.revision_store.
702
        self.assertEqual([], f.get_ancestry([]))
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
703
        f.add_lines('r0', [], ['a\n', 'b\n'])
704
        f.add_lines('r1', ['r0'], ['b\n', 'c\n'])
705
        f.add_lines('r2', ['r0'], ['b\n', 'c\n'])
706
        f.add_lines('r3', ['r2'], ['b\n', 'c\n'])
707
        f.add_lines('rM', ['r1', 'r2'], ['b\n', 'c\n'])
1563.2.29 by Robert Collins
Remove all but fetch references to repository.revision_store.
708
        self.assertEqual([], f.get_ancestry([]))
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
709
        versions = f.get_ancestry(['rM'])
710
        # there are some possibilities:
711
        # r0 r1 r2 rM r3
712
        # r0 r1 r2 r3 rM
713
        # etc
714
        # so we check indexes
715
        r0 = versions.index('r0')
716
        r1 = versions.index('r1')
717
        r2 = versions.index('r2')
718
        self.assertFalse('r3' in versions)
719
        rM = versions.index('rM')
720
        self.assertTrue(r0 < r1)
721
        self.assertTrue(r0 < r2)
722
        self.assertTrue(r1 < rM)
723
        self.assertTrue(r2 < rM)
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
724
725
        self.assertRaises(RevisionNotPresent,
726
            f.get_ancestry, ['rM', 'rX'])
1594.2.21 by Robert Collins
Teach versioned files to prevent mutation after finishing.
727
2530.1.1 by Aaron Bentley
Make topological sorting optional for get_ancestry
728
        self.assertEqual(set(f.get_ancestry('rM')),
729
            set(f.get_ancestry('rM', topo_sorted=False)))
730
1594.2.21 by Robert Collins
Teach versioned files to prevent mutation after finishing.
731
    def test_mutate_after_finish(self):
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
732
        self._transaction = 'before'
1594.2.21 by Robert Collins
Teach versioned files to prevent mutation after finishing.
733
        f = self.get_file()
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
734
        self._transaction = 'after'
1594.2.21 by Robert Collins
Teach versioned files to prevent mutation after finishing.
735
        self.assertRaises(errors.OutSideTransaction, f.add_lines, '', [], [])
736
        self.assertRaises(errors.OutSideTransaction, f.add_lines_with_ghosts, '', [], [])
3350.3.14 by Robert Collins
Deprecate VersionedFile.join.
737
        self.assertRaises(errors.OutSideTransaction, self.applyDeprecated,
738
            one_five, f.join, '')
1563.2.7 by Robert Collins
add versioned file clear_cache entry.
739
        
1563.2.15 by Robert Collins
remove the weavestore assumptions about the number and nature of files it manages.
740
    def test_copy_to(self):
741
        f = self.get_file()
742
        f.add_lines('0', [], ['a\n'])
743
        t = MemoryTransport()
744
        f.copy_to('foo', t)
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
745
        for suffix in self.get_factory().get_suffixes():
1563.2.15 by Robert Collins
remove the weavestore assumptions about the number and nature of files it manages.
746
            self.assertTrue(t.has('foo' + suffix))
747
748
    def test_get_suffixes(self):
749
        f = self.get_file()
750
        # and should be a list
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
751
        self.assertTrue(isinstance(self.get_factory().get_suffixes(), list))
1563.2.15 by Robert Collins
remove the weavestore assumptions about the number and nature of files it manages.
752
3287.5.1 by Robert Collins
Add VersionedFile.get_parent_map.
753
    def test_get_parent_map(self):
754
        f = self.get_file()
755
        f.add_lines('r0', [], ['a\n', 'b\n'])
756
        self.assertEqual(
757
            {'r0':()}, f.get_parent_map(['r0']))
758
        f.add_lines('r1', ['r0'], ['a\n', 'b\n'])
759
        self.assertEqual(
760
            {'r1':('r0',)}, f.get_parent_map(['r1']))
761
        self.assertEqual(
762
            {'r0':(),
763
             'r1':('r0',)},
764
            f.get_parent_map(['r0', 'r1']))
765
        f.add_lines('r2', [], ['a\n', 'b\n'])
766
        f.add_lines('r3', [], ['a\n', 'b\n'])
767
        f.add_lines('m', ['r0', 'r1', 'r2', 'r3'], ['a\n', 'b\n'])
768
        self.assertEqual(
769
            {'m':('r0', 'r1', 'r2', 'r3')}, f.get_parent_map(['m']))
770
        self.assertEqual({}, f.get_parent_map('y'))
771
        self.assertEqual(
772
            {'r0':(),
773
             'r1':('r0',)},
774
            f.get_parent_map(['r0', 'y', 'r1']))
775
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
776
    def test_annotate(self):
777
        f = self.get_file()
778
        f.add_lines('r0', [], ['a\n', 'b\n'])
779
        f.add_lines('r1', ['r0'], ['c\n', 'b\n'])
780
        origins = f.annotate('r1')
781
        self.assertEquals(origins[0][0], 'r1')
782
        self.assertEquals(origins[1][0], 'r0')
783
784
        self.assertRaises(RevisionNotPresent,
785
            f.annotate, 'foo')
786
1563.2.6 by Robert Collins
Start check tests for knits (pending), and remove dead code.
787
    def test_detection(self):
788
        # Test weaves detect corruption.
789
        #
790
        # Weaves contain a checksum of their texts.
791
        # When a text is extracted, this checksum should be
792
        # verified.
793
794
        w = self.get_file_corrupted_text()
795
796
        self.assertEqual('hello\n', w.get_text('v1'))
797
        self.assertRaises(errors.WeaveInvalidChecksum, w.get_text, 'v2')
798
        self.assertRaises(errors.WeaveInvalidChecksum, w.get_lines, 'v2')
799
        self.assertRaises(errors.WeaveInvalidChecksum, w.check)
800
801
        w = self.get_file_corrupted_checksum()
802
803
        self.assertEqual('hello\n', w.get_text('v1'))
804
        self.assertRaises(errors.WeaveInvalidChecksum, w.get_text, 'v2')
805
        self.assertRaises(errors.WeaveInvalidChecksum, w.get_lines, 'v2')
806
        self.assertRaises(errors.WeaveInvalidChecksum, w.check)
807
808
    def get_file_corrupted_text(self):
809
        """Return a versioned file with corrupt text but valid metadata."""
810
        raise NotImplementedError(self.get_file_corrupted_text)
811
1563.2.9 by Robert Collins
Update versionedfile api tests to ensure that data is available after every operation.
812
    def reopen_file(self, name='foo'):
813
        """Open the versioned file from disk again."""
814
        raise NotImplementedError(self.reopen_file)
815
1594.2.6 by Robert Collins
Introduce a api specifically for looking at lines in some versions of the inventory, for fileid_involved.
816
    def test_iter_lines_added_or_present_in_versions(self):
817
        # test that we get at least an equalset of the lines added by
818
        # versions in the weave 
819
        # the ordering here is to make a tree so that dumb searches have
820
        # more changes to muck up.
2039.1.1 by Aaron Bentley
Clean up progress properly when interrupted during fetch (#54000)
821
822
        class InstrumentedProgress(progress.DummyProgress):
823
824
            def __init__(self):
825
826
                progress.DummyProgress.__init__(self)
827
                self.updates = []
828
829
            def update(self, msg=None, current=None, total=None):
830
                self.updates.append((msg, current, total))
831
1594.2.6 by Robert Collins
Introduce a api specifically for looking at lines in some versions of the inventory, for fileid_involved.
832
        vf = self.get_file()
833
        # add a base to get included
834
        vf.add_lines('base', [], ['base\n'])
835
        # add a ancestor to be included on one side
836
        vf.add_lines('lancestor', [], ['lancestor\n'])
837
        # add a ancestor to be included on the other side
838
        vf.add_lines('rancestor', ['base'], ['rancestor\n'])
839
        # add a child of rancestor with no eofile-nl
840
        vf.add_lines('child', ['rancestor'], ['base\n', 'child\n'])
841
        # add a child of lancestor and base to join the two roots
842
        vf.add_lines('otherchild',
843
                     ['lancestor', 'base'],
844
                     ['base\n', 'lancestor\n', 'otherchild\n'])
2039.1.1 by Aaron Bentley
Clean up progress properly when interrupted during fetch (#54000)
845
        def iter_with_versions(versions, expected):
1594.2.6 by Robert Collins
Introduce a api specifically for looking at lines in some versions of the inventory, for fileid_involved.
846
            # now we need to see what lines are returned, and how often.
2975.3.1 by Robert Collins
Change (without backwards compatibility) the
847
            lines = {}
2039.1.1 by Aaron Bentley
Clean up progress properly when interrupted during fetch (#54000)
848
            progress = InstrumentedProgress()
1594.2.6 by Robert Collins
Introduce a api specifically for looking at lines in some versions of the inventory, for fileid_involved.
849
            # iterate over the lines
2975.3.1 by Robert Collins
Change (without backwards compatibility) the
850
            for line in vf.iter_lines_added_or_present_in_versions(versions,
2039.1.1 by Aaron Bentley
Clean up progress properly when interrupted during fetch (#54000)
851
                pb=progress):
2975.3.1 by Robert Collins
Change (without backwards compatibility) the
852
                lines.setdefault(line, 0)
1594.2.6 by Robert Collins
Introduce a api specifically for looking at lines in some versions of the inventory, for fileid_involved.
853
                lines[line] += 1
2975.3.1 by Robert Collins
Change (without backwards compatibility) the
854
            if []!= progress.updates:
2039.1.2 by Aaron Bentley
Tweak test to avoid catching assert
855
                self.assertEqual(expected, progress.updates)
1594.2.6 by Robert Collins
Introduce a api specifically for looking at lines in some versions of the inventory, for fileid_involved.
856
            return lines
2147.1.3 by John Arbash Meinel
In knit.py we were re-using a variable in 2 loops, causing bogus progress messages to be generated.
857
        lines = iter_with_versions(['child', 'otherchild'],
858
                                   [('Walking content.', 0, 2),
859
                                    ('Walking content.', 1, 2),
2039.1.1 by Aaron Bentley
Clean up progress properly when interrupted during fetch (#54000)
860
                                    ('Walking content.', 2, 2)])
1594.2.6 by Robert Collins
Introduce a api specifically for looking at lines in some versions of the inventory, for fileid_involved.
861
        # we must see child and otherchild
2975.3.1 by Robert Collins
Change (without backwards compatibility) the
862
        self.assertTrue(lines[('child\n', 'child')] > 0)
863
        self.assertTrue(lines[('otherchild\n', 'otherchild')] > 0)
1594.2.6 by Robert Collins
Introduce a api specifically for looking at lines in some versions of the inventory, for fileid_involved.
864
        # we dont care if we got more than that.
865
        
866
        # test all lines
2147.1.3 by John Arbash Meinel
In knit.py we were re-using a variable in 2 loops, causing bogus progress messages to be generated.
867
        lines = iter_with_versions(None, [('Walking content.', 0, 5),
868
                                          ('Walking content.', 1, 5),
869
                                          ('Walking content.', 2, 5),
870
                                          ('Walking content.', 3, 5),
871
                                          ('Walking content.', 4, 5),
2039.1.1 by Aaron Bentley
Clean up progress properly when interrupted during fetch (#54000)
872
                                          ('Walking content.', 5, 5)])
1594.2.6 by Robert Collins
Introduce a api specifically for looking at lines in some versions of the inventory, for fileid_involved.
873
        # all lines must be seen at least once
2975.3.1 by Robert Collins
Change (without backwards compatibility) the
874
        self.assertTrue(lines[('base\n', 'base')] > 0)
875
        self.assertTrue(lines[('lancestor\n', 'lancestor')] > 0)
876
        self.assertTrue(lines[('rancestor\n', 'rancestor')] > 0)
877
        self.assertTrue(lines[('child\n', 'child')] > 0)
878
        self.assertTrue(lines[('otherchild\n', 'otherchild')] > 0)
1594.2.7 by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc.
879
1594.2.8 by Robert Collins
add ghost aware apis to knits.
880
    def test_add_lines_with_ghosts(self):
881
        # some versioned file formats allow lines to be added with parent
882
        # information that is > than that in the format. Formats that do
883
        # not support this need to raise NotImplementedError on the
884
        # add_lines_with_ghosts api.
885
        vf = self.get_file()
886
        # add a revision with ghost parents
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
887
        # The preferred form is utf8, but we should translate when needed
888
        parent_id_unicode = u'b\xbfse'
889
        parent_id_utf8 = parent_id_unicode.encode('utf8')
1594.2.8 by Robert Collins
add ghost aware apis to knits.
890
        try:
2309.4.7 by John Arbash Meinel
Update VersionedFile tests to ensure that they can take Unicode,
891
            vf.add_lines_with_ghosts('notbxbfse', [parent_id_utf8], [])
1594.2.8 by Robert Collins
add ghost aware apis to knits.
892
        except NotImplementedError:
893
            # check the other ghost apis are also not implemented
894
            self.assertRaises(NotImplementedError, vf.get_ancestry_with_ghosts, ['foo'])
895
            self.assertRaises(NotImplementedError, vf.get_parents_with_ghosts, 'foo')
896
            return
2150.2.1 by Robert Collins
Correctly decode utf8 revision ids from knits when parsing, fixes a regression where a unicode revision id is stored correctly, but then indexed by the utf8 value on the next invocation of bzr, rather than the unicode value.
897
        vf = self.reopen_file()
1594.2.8 by Robert Collins
add ghost aware apis to knits.
898
        # test key graph related apis: getncestry, _graph, get_parents
899
        # has_version
900
        # - these are ghost unaware and must not be reflect ghosts
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
901
        self.assertEqual(['notbxbfse'], vf.get_ancestry('notbxbfse'))
902
        self.assertFalse(vf.has_version(parent_id_utf8))
1594.2.8 by Robert Collins
add ghost aware apis to knits.
903
        # we have _with_ghost apis to give us ghost information.
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
904
        self.assertEqual([parent_id_utf8, 'notbxbfse'], vf.get_ancestry_with_ghosts(['notbxbfse']))
905
        self.assertEqual([parent_id_utf8], vf.get_parents_with_ghosts('notbxbfse'))
1594.2.8 by Robert Collins
add ghost aware apis to knits.
906
        # if we add something that is a ghost of another, it should correct the
907
        # results of the prior apis
2858.2.1 by Martin Pool
Remove most calls to safe_file_id and safe_revision_id.
908
        vf.add_lines(parent_id_utf8, [], [])
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
909
        self.assertEqual([parent_id_utf8, 'notbxbfse'], vf.get_ancestry(['notbxbfse']))
3287.5.2 by Robert Collins
Deprecate VersionedFile.get_parents, breaking pulling from a ghost containing knit or pack repository to weaves, which improves correctness and allows simplification of core code.
910
        self.assertEqual({'notbxbfse':(parent_id_utf8,)},
911
            vf.get_parent_map(['notbxbfse']))
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
912
        self.assertTrue(vf.has_version(parent_id_utf8))
1594.2.8 by Robert Collins
add ghost aware apis to knits.
913
        # we have _with_ghost apis to give us ghost information.
2858.2.1 by Martin Pool
Remove most calls to safe_file_id and safe_revision_id.
914
        self.assertEqual([parent_id_utf8, 'notbxbfse'],
915
            vf.get_ancestry_with_ghosts(['notbxbfse']))
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
916
        self.assertEqual([parent_id_utf8], vf.get_parents_with_ghosts('notbxbfse'))
1594.2.8 by Robert Collins
add ghost aware apis to knits.
917
1594.2.9 by Robert Collins
Teach Knit repositories how to handle ghosts without corrupting at all.
918
    def test_add_lines_with_ghosts_after_normal_revs(self):
919
        # some versioned file formats allow lines to be added with parent
920
        # information that is > than that in the format. Formats that do
921
        # not support this need to raise NotImplementedError on the
922
        # add_lines_with_ghosts api.
923
        vf = self.get_file()
924
        # probe for ghost support
925
        try:
3287.6.5 by Robert Collins
Deprecate VersionedFile.has_ghost.
926
            vf.add_lines_with_ghosts('base', [], ['line\n', 'line_b\n'])
1594.2.9 by Robert Collins
Teach Knit repositories how to handle ghosts without corrupting at all.
927
        except NotImplementedError:
928
            return
929
        vf.add_lines_with_ghosts('references_ghost',
930
                                 ['base', 'a_ghost'],
931
                                 ['line\n', 'line_b\n', 'line_c\n'])
932
        origins = vf.annotate('references_ghost')
933
        self.assertEquals(('base', 'line\n'), origins[0])
934
        self.assertEquals(('base', 'line_b\n'), origins[1])
935
        self.assertEquals(('references_ghost', 'line_c\n'), origins[2])
1594.2.23 by Robert Collins
Test versioned file storage handling of clean/dirty status for accessed versioned files.
936
937
    def test_readonly_mode(self):
938
        transport = get_transport(self.get_url('.'))
939
        factory = self.get_factory()
940
        vf = factory('id', transport, 0777, create=True, access_mode='w')
941
        vf = factory('id', transport, access_mode='r')
942
        self.assertRaises(errors.ReadOnlyError, vf.add_lines, 'base', [], [])
943
        self.assertRaises(errors.ReadOnlyError,
944
                          vf.add_lines_with_ghosts,
945
                          'base',
946
                          [],
947
                          [])
3350.3.14 by Robert Collins
Deprecate VersionedFile.join.
948
        self.assertRaises(errors.ReadOnlyError, self.applyDeprecated, one_five,
949
            vf.join, 'base')
1666.1.6 by Robert Collins
Make knit the default format.
950
    
3316.2.9 by Robert Collins
* ``VersionedFile.get_sha1`` is deprecated, please use
951
    def test_get_sha1s(self):
1666.1.6 by Robert Collins
Make knit the default format.
952
        # check the sha1 data is available
953
        vf = self.get_file()
954
        # a simple file
955
        vf.add_lines('a', [], ['a\n'])
956
        # the same file, different metadata
957
        vf.add_lines('b', ['a'], ['a\n'])
958
        # a file differing only in last newline.
959
        vf.add_lines('c', [], ['a'])
2520.4.89 by Aaron Bentley
Add get_sha1s to weaves
960
        self.assertEqual(['3f786850e387550fdab836ed7e6dc881de23001b',
961
                          '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8',
962
                          '3f786850e387550fdab836ed7e6dc881de23001b'],
963
                          vf.get_sha1s(['a', 'c', 'b']))
1594.2.9 by Robert Collins
Teach Knit repositories how to handle ghosts without corrupting at all.
964
        
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
965
2535.3.1 by Andrew Bennetts
Add get_format_signature to VersionedFile
966
class TestWeave(TestCaseWithMemoryTransport, VersionedFileTestMixIn):
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
967
968
    def get_file(self, name='foo'):
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
969
        return WeaveFile(name, get_transport(self.get_url('.')), create=True,
970
            get_scope=self.get_transaction)
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
971
1563.2.6 by Robert Collins
Start check tests for knits (pending), and remove dead code.
972
    def get_file_corrupted_text(self):
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
973
        w = WeaveFile('foo', get_transport(self.get_url('.')), create=True,
974
            get_scope=self.get_transaction)
1563.2.13 by Robert Collins
InterVersionedFile implemented.
975
        w.add_lines('v1', [], ['hello\n'])
976
        w.add_lines('v2', ['v1'], ['hello\n', 'there\n'])
1563.2.6 by Robert Collins
Start check tests for knits (pending), and remove dead code.
977
        
978
        # We are going to invasively corrupt the text
979
        # Make sure the internals of weave are the same
980
        self.assertEqual([('{', 0)
981
                        , 'hello\n'
982
                        , ('}', None)
983
                        , ('{', 1)
984
                        , 'there\n'
985
                        , ('}', None)
986
                        ], w._weave)
987
        
988
        self.assertEqual(['f572d396fae9206628714fb2ce00f72e94f2258f'
989
                        , '90f265c6e75f1c8f9ab76dcf85528352c5f215ef'
990
                        ], w._sha1s)
991
        w.check()
992
        
993
        # Corrupted
994
        w._weave[4] = 'There\n'
995
        return w
996
997
    def get_file_corrupted_checksum(self):
998
        w = self.get_file_corrupted_text()
999
        # Corrected
1000
        w._weave[4] = 'there\n'
1001
        self.assertEqual('hello\nthere\n', w.get_text('v2'))
1002
        
1003
        #Invalid checksum, first digit changed
1004
        w._sha1s[1] =  'f0f265c6e75f1c8f9ab76dcf85528352c5f215ef'
1005
        return w
1006
1666.1.6 by Robert Collins
Make knit the default format.
1007
    def reopen_file(self, name='foo', create=False):
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
1008
        return WeaveFile(name, get_transport(self.get_url('.')), create=create,
1009
            get_scope=self.get_transaction)
1563.2.9 by Robert Collins
Update versionedfile api tests to ensure that data is available after every operation.
1010
1563.2.25 by Robert Collins
Merge in upstream.
1011
    def test_no_implicit_create(self):
1012
        self.assertRaises(errors.NoSuchFile,
1013
                          WeaveFile,
1014
                          'foo',
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
1015
                          get_transport(self.get_url('.')),
1016
                          get_scope=self.get_transaction)
1563.2.25 by Robert Collins
Merge in upstream.
1017
1594.2.23 by Robert Collins
Test versioned file storage handling of clean/dirty status for accessed versioned files.
1018
    def get_factory(self):
1019
        return WeaveFile
1020
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
1021
2535.3.1 by Andrew Bennetts
Add get_format_signature to VersionedFile
1022
class TestKnit(TestCaseWithMemoryTransport, VersionedFileTestMixIn):
1563.2.4 by Robert Collins
First cut at including the knit implementation of versioned_file.
1023
3350.3.11 by Robert Collins
Test inserting a stream that overlaps the current content of a knit does not error.
1024
    def get_file(self, name='foo', create=True):
1025
        return make_file_knit(name, get_transport(self.get_url('.')),
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
1026
            delta=True, create=True, get_scope=self.get_transaction)
1563.2.6 by Robert Collins
Start check tests for knits (pending), and remove dead code.
1027
1594.2.23 by Robert Collins
Test versioned file storage handling of clean/dirty status for accessed versioned files.
1028
    def get_factory(self):
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
1029
        return make_file_knit
1594.2.23 by Robert Collins
Test versioned file storage handling of clean/dirty status for accessed versioned files.
1030
1563.2.6 by Robert Collins
Start check tests for knits (pending), and remove dead code.
1031
    def get_file_corrupted_text(self):
1032
        knit = self.get_file()
1033
        knit.add_lines('v1', [], ['hello\n'])
1034
        knit.add_lines('v2', ['v1'], ['hello\n', 'there\n'])
1035
        return knit
1563.2.9 by Robert Collins
Update versionedfile api tests to ensure that data is available after every operation.
1036
1666.1.6 by Robert Collins
Make knit the default format.
1037
    def reopen_file(self, name='foo', create=False):
3350.3.11 by Robert Collins
Test inserting a stream that overlaps the current content of a knit does not error.
1038
        return self.get_file(name, create)
1563.2.10 by Robert Collins
Change weave store to be a versioned store, using WeaveFiles which maintain integrity without needing explicit 'put' operations.
1039
1040
    def test_detection(self):
1563.2.19 by Robert Collins
stub out a check for knits.
1041
        knit = self.get_file()
1042
        knit.check()
1563.2.12 by Robert Collins
Checkpointing: created InterObject to factor out common inter object worker code, added InterVersionedFile and tests to allow making join work between any versionedfile.
1043
1563.2.25 by Robert Collins
Merge in upstream.
1044
    def test_no_implicit_create(self):
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
1045
        self.assertRaises(errors.NoSuchFile, self.get_factory(), 'foo',
1046
            get_transport(self.get_url('.')))
1563.2.25 by Robert Collins
Merge in upstream.
1047
1563.2.12 by Robert Collins
Checkpointing: created InterObject to factor out common inter object worker code, added InterVersionedFile and tests to allow making join work between any versionedfile.
1048
2770.1.1 by Aaron Bentley
Initial implmentation of plain knit annotation
1049
class TestPlaintextKnit(TestKnit):
1050
    """Test a knit with no cached annotations"""
1051
3350.3.11 by Robert Collins
Test inserting a stream that overlaps the current content of a knit does not error.
1052
    def get_file(self, name='foo', create=True):
1053
        return make_file_knit(name, get_transport(self.get_url('.')),
1054
            delta=True, create=create, get_scope=self.get_transaction,
1055
            factory=_mod_knit.KnitPlainFactory())
2770.1.1 by Aaron Bentley
Initial implmentation of plain knit annotation
1056
1057
3062.1.9 by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile
1058
class TestPlanMergeVersionedFile(TestCaseWithMemoryTransport):
1059
1060
    def setUp(self):
1061
        TestCaseWithMemoryTransport.setUp(self)
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
1062
        self.vf1 = make_file_knit('root', self.get_transport(), create=True)
1063
        self.vf2 = make_file_knit('root', self.get_transport(), create=True)
3062.1.9 by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile
1064
        self.plan_merge_vf = versionedfile._PlanMergeVersionedFile('root',
1065
            [self.vf1, self.vf2])
1066
1067
    def test_add_lines(self):
1068
        self.plan_merge_vf.add_lines('a:', [], [])
1069
        self.assertRaises(ValueError, self.plan_merge_vf.add_lines, 'a', [],
1070
                          [])
1071
        self.assertRaises(ValueError, self.plan_merge_vf.add_lines, 'a:', None,
1072
                          [])
1073
        self.assertRaises(ValueError, self.plan_merge_vf.add_lines, 'a:', [],
1074
                          None)
1075
1076
    def test_ancestry(self):
1077
        self.vf1.add_lines('A', [], [])
1078
        self.vf1.add_lines('B', ['A'], [])
1079
        self.plan_merge_vf.add_lines('C:', ['B'], [])
1080
        self.plan_merge_vf.add_lines('D:', ['C:'], [])
1081
        self.assertEqual(set(['A', 'B', 'C:', 'D:']),
3062.1.14 by Aaron Bentley
Use topo_sorted=False with get_ancestry
1082
            self.plan_merge_vf.get_ancestry('D:', topo_sorted=False))
3062.1.9 by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile
1083
1084
    def setup_abcde(self):
1085
        self.vf1.add_lines('A', [], ['a'])
1086
        self.vf1.add_lines('B', ['A'], ['b'])
1087
        self.vf2.add_lines('C', [], ['c'])
1088
        self.vf2.add_lines('D', ['C'], ['d'])
1089
        self.plan_merge_vf.add_lines('E:', ['B', 'D'], ['e'])
1090
1091
    def test_ancestry_uses_all_versionedfiles(self):
1092
        self.setup_abcde()
1093
        self.assertEqual(set(['A', 'B', 'C', 'D', 'E:']),
3062.1.14 by Aaron Bentley
Use topo_sorted=False with get_ancestry
1094
            self.plan_merge_vf.get_ancestry('E:', topo_sorted=False))
3062.1.9 by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile
1095
1096
    def test_ancestry_raises_revision_not_present(self):
1097
        error = self.assertRaises(errors.RevisionNotPresent,
3062.1.14 by Aaron Bentley
Use topo_sorted=False with get_ancestry
1098
                                  self.plan_merge_vf.get_ancestry, 'E:', False)
3062.1.9 by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile
1099
        self.assertContainsRe(str(error), '{E:} not present in "root"')
1100
1101
    def test_get_parents(self):
1102
        self.setup_abcde()
3287.5.2 by Robert Collins
Deprecate VersionedFile.get_parents, breaking pulling from a ghost containing knit or pack repository to weaves, which improves correctness and allows simplification of core code.
1103
        self.assertEqual({'B':('A',)}, self.plan_merge_vf.get_parent_map(['B']))
1104
        self.assertEqual({'D':('C',)}, self.plan_merge_vf.get_parent_map(['D']))
1105
        self.assertEqual({'E:':('B', 'D')},
1106
            self.plan_merge_vf.get_parent_map(['E:']))
1107
        self.assertEqual({}, self.plan_merge_vf.get_parent_map(['F']))
1108
        self.assertEqual({
1109
                'B':('A',),
1110
                'D':('C',),
1111
                'E:':('B', 'D'),
1112
                }, self.plan_merge_vf.get_parent_map(['B', 'D', 'E:', 'F']))
3062.1.9 by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile
1113
1114
    def test_get_lines(self):
1115
        self.setup_abcde()
1116
        self.assertEqual(['a'], self.plan_merge_vf.get_lines('A'))
1117
        self.assertEqual(['c'], self.plan_merge_vf.get_lines('C'))
1118
        self.assertEqual(['e'], self.plan_merge_vf.get_lines('E:'))
1119
        error = self.assertRaises(errors.RevisionNotPresent,
1120
                                  self.plan_merge_vf.get_lines, 'F')
1121
        self.assertContainsRe(str(error), '{F} not present in "root"')
1122
1123
1563.2.12 by Robert Collins
Checkpointing: created InterObject to factor out common inter object worker code, added InterVersionedFile and tests to allow making join work between any versionedfile.
1124
class InterString(versionedfile.InterVersionedFile):
1125
    """An inter-versionedfile optimised code path for strings.
1126
1127
    This is for use during testing where we use strings as versionedfiles
1128
    so that none of the default regsitered interversionedfile classes will
1129
    match - which lets us test the match logic.
1130
    """
1131
1132
    @staticmethod
1133
    def is_compatible(source, target):
1134
        """InterString is compatible with strings-as-versionedfiles."""
1135
        return isinstance(source, str) and isinstance(target, str)
1136
1137
1138
# TODO this and the InterRepository core logic should be consolidatable
1139
# if we make the registry a separate class though we still need to 
1140
# test the behaviour in the active registry to catch failure-to-handle-
1141
# stange-objects
2535.3.1 by Andrew Bennetts
Add get_format_signature to VersionedFile
1142
class TestInterVersionedFile(TestCaseWithMemoryTransport):
1563.2.12 by Robert Collins
Checkpointing: created InterObject to factor out common inter object worker code, added InterVersionedFile and tests to allow making join work between any versionedfile.
1143
1144
    def test_get_default_inter_versionedfile(self):
1145
        # test that the InterVersionedFile.get(a, b) probes
1146
        # for a class where is_compatible(a, b) returns
1147
        # true and returns a default interversionedfile otherwise.
1148
        # This also tests that the default registered optimised interversionedfile
1149
        # classes do not barf inappropriately when a surprising versionedfile type
1150
        # is handed to them.
1151
        dummy_a = "VersionedFile 1."
1152
        dummy_b = "VersionedFile 2."
1153
        self.assertGetsDefaultInterVersionedFile(dummy_a, dummy_b)
1154
1155
    def assertGetsDefaultInterVersionedFile(self, a, b):
1156
        """Asserts that InterVersionedFile.get(a, b) -> the default."""
1157
        inter = versionedfile.InterVersionedFile.get(a, b)
1158
        self.assertEqual(versionedfile.InterVersionedFile,
1159
                         inter.__class__)
1160
        self.assertEqual(a, inter.source)
1161
        self.assertEqual(b, inter.target)
1162
1163
    def test_register_inter_versionedfile_class(self):
1164
        # test that a optimised code path provider - a
1165
        # InterVersionedFile subclass can be registered and unregistered
1166
        # and that it is correctly selected when given a versionedfile
1167
        # pair that it returns true on for the is_compatible static method
1168
        # check
1169
        dummy_a = "VersionedFile 1."
1170
        dummy_b = "VersionedFile 2."
1171
        versionedfile.InterVersionedFile.register_optimiser(InterString)
1172
        try:
1173
            # we should get the default for something InterString returns False
1174
            # to
1175
            self.assertFalse(InterString.is_compatible(dummy_a, None))
1176
            self.assertGetsDefaultInterVersionedFile(dummy_a, None)
1177
            # and we should get an InterString for a pair it 'likes'
1178
            self.assertTrue(InterString.is_compatible(dummy_a, dummy_b))
1179
            inter = versionedfile.InterVersionedFile.get(dummy_a, dummy_b)
1180
            self.assertEqual(InterString, inter.__class__)
1181
            self.assertEqual(dummy_a, inter.source)
1182
            self.assertEqual(dummy_b, inter.target)
1183
        finally:
1184
            versionedfile.InterVersionedFile.unregister_optimiser(InterString)
1185
        # now we should get the default InterVersionedFile object again.
1186
        self.assertGetsDefaultInterVersionedFile(dummy_a, dummy_b)
1666.1.1 by Robert Collins
Add trivial http-using test for versioned files.
1187
1188
1189
class TestReadonlyHttpMixin(object):
1190
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
1191
    def get_transaction(self):
1192
        return 1
1193
1666.1.1 by Robert Collins
Add trivial http-using test for versioned files.
1194
    def test_readonly_http_works(self):
1195
        # we should be able to read from http with a versioned file.
1196
        vf = self.get_file()
1666.1.6 by Robert Collins
Make knit the default format.
1197
        # try an empty file access
1198
        readonly_vf = self.get_factory()('foo', get_transport(self.get_readonly_url('.')))
1199
        self.assertEqual([], readonly_vf.versions())
1200
        # now with feeling.
1666.1.1 by Robert Collins
Add trivial http-using test for versioned files.
1201
        vf.add_lines('1', [], ['a\n'])
1202
        vf.add_lines('2', ['1'], ['b\n', 'a\n'])
1203
        readonly_vf = self.get_factory()('foo', get_transport(self.get_readonly_url('.')))
1666.1.6 by Robert Collins
Make knit the default format.
1204
        self.assertEqual(['1', '2'], vf.versions())
1666.1.1 by Robert Collins
Add trivial http-using test for versioned files.
1205
        for version in readonly_vf.versions():
1206
            readonly_vf.get_lines(version)
1207
1208
1209
class TestWeaveHTTP(TestCaseWithWebserver, TestReadonlyHttpMixin):
1210
1211
    def get_file(self):
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
1212
        return WeaveFile('foo', get_transport(self.get_url('.')), create=True,
1213
            get_scope=self.get_transaction)
1666.1.1 by Robert Collins
Add trivial http-using test for versioned files.
1214
1215
    def get_factory(self):
1216
        return WeaveFile
1217
1218
1219
class TestKnitHTTP(TestCaseWithWebserver, TestReadonlyHttpMixin):
1220
1221
    def get_file(self):
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
1222
        return make_file_knit('foo', get_transport(self.get_url('.')),
1223
            delta=True, create=True, get_scope=self.get_transaction)
1666.1.1 by Robert Collins
Add trivial http-using test for versioned files.
1224
1225
    def get_factory(self):
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
1226
        return make_file_knit
1664.2.9 by Aaron Bentley
Ported weave merge test to versionedfile
1227
1228
1229
class MergeCasesMixin(object):
1230
1231
    def doMerge(self, base, a, b, mp):
1232
        from cStringIO import StringIO
1233
        from textwrap import dedent
1234
1235
        def addcrlf(x):
1236
            return x + '\n'
1237
        
1238
        w = self.get_file()
1239
        w.add_lines('text0', [], map(addcrlf, base))
1240
        w.add_lines('text1', ['text0'], map(addcrlf, a))
1241
        w.add_lines('text2', ['text0'], map(addcrlf, b))
1242
1243
        self.log_contents(w)
1244
1245
        self.log('merge plan:')
1246
        p = list(w.plan_merge('text1', 'text2'))
1247
        for state, line in p:
1248
            if line:
1249
                self.log('%12s | %s' % (state, line[:-1]))
1250
1251
        self.log('merge:')
1252
        mt = StringIO()
1253
        mt.writelines(w.weave_merge(p))
1254
        mt.seek(0)
1255
        self.log(mt.getvalue())
1256
1257
        mp = map(addcrlf, mp)
1258
        self.assertEqual(mt.readlines(), mp)
1259
        
1260
        
1261
    def testOneInsert(self):
1262
        self.doMerge([],
1263
                     ['aa'],
1264
                     [],
1265
                     ['aa'])
1266
1267
    def testSeparateInserts(self):
1268
        self.doMerge(['aaa', 'bbb', 'ccc'],
1269
                     ['aaa', 'xxx', 'bbb', 'ccc'],
1270
                     ['aaa', 'bbb', 'yyy', 'ccc'],
1271
                     ['aaa', 'xxx', 'bbb', 'yyy', 'ccc'])
1272
1273
    def testSameInsert(self):
1274
        self.doMerge(['aaa', 'bbb', 'ccc'],
1275
                     ['aaa', 'xxx', 'bbb', 'ccc'],
1276
                     ['aaa', 'xxx', 'bbb', 'yyy', 'ccc'],
1277
                     ['aaa', 'xxx', 'bbb', 'yyy', 'ccc'])
1278
    overlappedInsertExpected = ['aaa', 'xxx', 'yyy', 'bbb']
1279
    def testOverlappedInsert(self):
1280
        self.doMerge(['aaa', 'bbb'],
1281
                     ['aaa', 'xxx', 'yyy', 'bbb'],
1282
                     ['aaa', 'xxx', 'bbb'], self.overlappedInsertExpected)
1283
1284
        # really it ought to reduce this to 
1285
        # ['aaa', 'xxx', 'yyy', 'bbb']
1286
1287
1288
    def testClashReplace(self):
1289
        self.doMerge(['aaa'],
1290
                     ['xxx'],
1291
                     ['yyy', 'zzz'],
1292
                     ['<<<<<<< ', 'xxx', '=======', 'yyy', 'zzz', 
1293
                      '>>>>>>> '])
1294
1295
    def testNonClashInsert1(self):
1296
        self.doMerge(['aaa'],
1297
                     ['xxx', 'aaa'],
1298
                     ['yyy', 'zzz'],
1299
                     ['<<<<<<< ', 'xxx', 'aaa', '=======', 'yyy', 'zzz', 
1300
                      '>>>>>>> '])
1301
1302
    def testNonClashInsert2(self):
1303
        self.doMerge(['aaa'],
1304
                     ['aaa'],
1305
                     ['yyy', 'zzz'],
1306
                     ['yyy', 'zzz'])
1307
1308
1309
    def testDeleteAndModify(self):
1310
        """Clashing delete and modification.
1311
1312
        If one side modifies a region and the other deletes it then
1313
        there should be a conflict with one side blank.
1314
        """
1315
1316
        #######################################
1317
        # skippd, not working yet
1318
        return
1319
        
1320
        self.doMerge(['aaa', 'bbb', 'ccc'],
1321
                     ['aaa', 'ddd', 'ccc'],
1322
                     ['aaa', 'ccc'],
1323
                     ['<<<<<<<< ', 'aaa', '=======', '>>>>>>> ', 'ccc'])
1324
1325
    def _test_merge_from_strings(self, base, a, b, expected):
1326
        w = self.get_file()
1327
        w.add_lines('text0', [], base.splitlines(True))
1328
        w.add_lines('text1', ['text0'], a.splitlines(True))
1329
        w.add_lines('text2', ['text0'], b.splitlines(True))
1330
        self.log('merge plan:')
1331
        p = list(w.plan_merge('text1', 'text2'))
1332
        for state, line in p:
1333
            if line:
1334
                self.log('%12s | %s' % (state, line[:-1]))
1335
        self.log('merge result:')
1336
        result_text = ''.join(w.weave_merge(p))
1337
        self.log(result_text)
1338
        self.assertEqualDiff(result_text, expected)
1339
1340
    def test_weave_merge_conflicts(self):
1341
        # does weave merge properly handle plans that end with unchanged?
1342
        result = ''.join(self.get_file().weave_merge([('new-a', 'hello\n')]))
1343
        self.assertEqual(result, 'hello\n')
1344
1345
    def test_deletion_extended(self):
1346
        """One side deletes, the other deletes more.
1347
        """
1348
        base = """\
1349
            line 1
1350
            line 2
1351
            line 3
1352
            """
1353
        a = """\
1354
            line 1
1355
            line 2
1356
            """
1357
        b = """\
1358
            line 1
1359
            """
1360
        result = """\
1361
            line 1
1362
            """
1363
        self._test_merge_from_strings(base, a, b, result)
1364
1365
    def test_deletion_overlap(self):
1366
        """Delete overlapping regions with no other conflict.
1367
1368
        Arguably it'd be better to treat these as agreement, rather than 
1369
        conflict, but for now conflict is safer.
1370
        """
1371
        base = """\
1372
            start context
1373
            int a() {}
1374
            int b() {}
1375
            int c() {}
1376
            end context
1377
            """
1378
        a = """\
1379
            start context
1380
            int a() {}
1381
            end context
1382
            """
1383
        b = """\
1384
            start context
1385
            int c() {}
1386
            end context
1387
            """
1388
        result = """\
1389
            start context
1390
<<<<<<< 
1391
            int a() {}
1392
=======
1393
            int c() {}
1394
>>>>>>> 
1395
            end context
1396
            """
1397
        self._test_merge_from_strings(base, a, b, result)
1398
1399
    def test_agreement_deletion(self):
1400
        """Agree to delete some lines, without conflicts."""
1401
        base = """\
1402
            start context
1403
            base line 1
1404
            base line 2
1405
            end context
1406
            """
1407
        a = """\
1408
            start context
1409
            base line 1
1410
            end context
1411
            """
1412
        b = """\
1413
            start context
1414
            base line 1
1415
            end context
1416
            """
1417
        result = """\
1418
            start context
1419
            base line 1
1420
            end context
1421
            """
1422
        self._test_merge_from_strings(base, a, b, result)
1423
1424
    def test_sync_on_deletion(self):
1425
        """Specific case of merge where we can synchronize incorrectly.
1426
        
1427
        A previous version of the weave merge concluded that the two versions
1428
        agreed on deleting line 2, and this could be a synchronization point.
1429
        Line 1 was then considered in isolation, and thought to be deleted on 
1430
        both sides.
1431
1432
        It's better to consider the whole thing as a disagreement region.
1433
        """
1434
        base = """\
1435
            start context
1436
            base line 1
1437
            base line 2
1438
            end context
1439
            """
1440
        a = """\
1441
            start context
1442
            base line 1
1443
            a's replacement line 2
1444
            end context
1445
            """
1446
        b = """\
1447
            start context
1448
            b replaces
1449
            both lines
1450
            end context
1451
            """
1452
        result = """\
1453
            start context
1454
<<<<<<< 
1455
            base line 1
1456
            a's replacement line 2
1457
=======
1458
            b replaces
1459
            both lines
1460
>>>>>>> 
1461
            end context
1462
            """
1463
        self._test_merge_from_strings(base, a, b, result)
1464
1465
2535.3.1 by Andrew Bennetts
Add get_format_signature to VersionedFile
1466
class TestKnitMerge(TestCaseWithMemoryTransport, MergeCasesMixin):
1664.2.9 by Aaron Bentley
Ported weave merge test to versionedfile
1467
1468
    def get_file(self, name='foo'):
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
1469
        return make_file_knit(name, get_transport(self.get_url('.')),
1664.2.9 by Aaron Bentley
Ported weave merge test to versionedfile
1470
                                 delta=True, create=True)
1471
1472
    def log_contents(self, w):
1473
        pass
1474
1475
2535.3.1 by Andrew Bennetts
Add get_format_signature to VersionedFile
1476
class TestWeaveMerge(TestCaseWithMemoryTransport, MergeCasesMixin):
1664.2.9 by Aaron Bentley
Ported weave merge test to versionedfile
1477
1478
    def get_file(self, name='foo'):
1479
        return WeaveFile(name, get_transport(self.get_url('.')), create=True)
1480
1481
    def log_contents(self, w):
1482
        self.log('weave is:')
1483
        tmpf = StringIO()
1484
        write_weave(w, tmpf)
1485
        self.log(tmpf.getvalue())
1486
1487
    overlappedInsertExpected = ['aaa', '<<<<<<< ', 'xxx', 'yyy', '=======', 
1488
                                'xxx', '>>>>>>> ', 'bbb']
3350.3.4 by Robert Collins
Finish adapters for annotated knits to unannotated knits and full texts.
1489
1490
1491
class TestContentFactoryAdaption(TestCaseWithMemoryTransport):
1492
1493
    def test_select_adaptor(self):
3350.3.7 by Robert Collins
Create a registry of versioned file record adapters.
1494
        """Test expected adapters exist."""
1495
        # One scenario for each lookup combination we expect to use.
1496
        # Each is source_kind, requested_kind, adapter class
1497
        scenarios = [
1498
            ('knit-delta-gz', 'fulltext', _mod_knit.DeltaPlainToFullText),
1499
            ('knit-ft-gz', 'fulltext', _mod_knit.FTPlainToFullText),
1500
            ('knit-annotated-delta-gz', 'knit-delta-gz',
1501
                _mod_knit.DeltaAnnotatedToUnannotated),
1502
            ('knit-annotated-delta-gz', 'fulltext',
1503
                _mod_knit.DeltaAnnotatedToFullText),
1504
            ('knit-annotated-ft-gz', 'knit-ft-gz',
1505
                _mod_knit.FTAnnotatedToUnannotated),
1506
            ('knit-annotated-ft-gz', 'fulltext',
1507
                _mod_knit.FTAnnotatedToFullText),
1508
            ]
1509
        for source, requested, klass in scenarios:
1510
            adapter_factory = versionedfile.adapter_registry.get(
1511
                (source, requested))
1512
            adapter = adapter_factory(None)
1513
            self.assertIsInstance(adapter, klass)
3350.3.4 by Robert Collins
Finish adapters for annotated knits to unannotated knits and full texts.
1514
3350.3.5 by Robert Collins
Create adapters from plain compressed knit content.
1515
    def get_knit(self, annotated=True):
1516
        if annotated:
1517
            factory = KnitAnnotateFactory()
1518
        else:
1519
            factory = KnitPlainFactory()
3350.3.4 by Robert Collins
Finish adapters for annotated knits to unannotated knits and full texts.
1520
        return make_file_knit('knit', self.get_transport('.'), delta=True,
3350.3.5 by Robert Collins
Create adapters from plain compressed knit content.
1521
            create=True, factory=factory)
3350.3.4 by Robert Collins
Finish adapters for annotated knits to unannotated knits and full texts.
1522
1523
    def helpGetBytes(self, f, ft_adapter, delta_adapter):
3350.3.22 by Robert Collins
Review feedback.
1524
        """Grab the interested adapted texts for tests."""
3350.3.4 by Robert Collins
Finish adapters for annotated knits to unannotated knits and full texts.
1525
        # origin is a fulltext
1526
        entries = f.get_record_stream(['origin'], 'unordered', False)
1527
        base = entries.next()
1528
        ft_data = ft_adapter.get_bytes(base, base.get_bytes_as(base.storage_kind))
1529
        # merged is both a delta and multiple parents.
1530
        entries = f.get_record_stream(['merged'], 'unordered', False)
1531
        merged = entries.next()
1532
        delta_data = delta_adapter.get_bytes(merged,
1533
            merged.get_bytes_as(merged.storage_kind))
1534
        return ft_data, delta_data
1535
1536
    def test_deannotation_noeol(self):
1537
        """Test converting annotated knits to unannotated knits."""
1538
        # we need a full text, and a delta
1539
        f, parents = get_diamond_vf(self.get_knit(), trailing_eol=False)
1540
        ft_data, delta_data = self.helpGetBytes(f,
3350.3.7 by Robert Collins
Create a registry of versioned file record adapters.
1541
            _mod_knit.FTAnnotatedToUnannotated(None),
1542
            _mod_knit.DeltaAnnotatedToUnannotated(None))
3350.3.4 by Robert Collins
Finish adapters for annotated knits to unannotated knits and full texts.
1543
        self.assertEqual(
1544
            'version origin 1 b284f94827db1fa2970d9e2014f080413b547a7e\n'
1545
            'origin\n'
1546
            'end origin\n',
1547
            GzipFile(mode='rb', fileobj=StringIO(ft_data)).read())
1548
        self.assertEqual(
1549
            'version merged 4 32c2e79763b3f90e8ccde37f9710b6629c25a796\n'
1550
            '1,2,3\nleft\nright\nmerged\nend merged\n',
1551
            GzipFile(mode='rb', fileobj=StringIO(delta_data)).read())
1552
1553
    def test_deannotation(self):
1554
        """Test converting annotated knits to unannotated knits."""
1555
        # we need a full text, and a delta
1556
        f, parents = get_diamond_vf(self.get_knit())
1557
        ft_data, delta_data = self.helpGetBytes(f,
3350.3.7 by Robert Collins
Create a registry of versioned file record adapters.
1558
            _mod_knit.FTAnnotatedToUnannotated(None),
1559
            _mod_knit.DeltaAnnotatedToUnannotated(None))
3350.3.4 by Robert Collins
Finish adapters for annotated knits to unannotated knits and full texts.
1560
        self.assertEqual(
1561
            'version origin 1 00e364d235126be43292ab09cb4686cf703ddc17\n'
1562
            'origin\n'
1563
            'end origin\n',
1564
            GzipFile(mode='rb', fileobj=StringIO(ft_data)).read())
1565
        self.assertEqual(
1566
            'version merged 3 ed8bce375198ea62444dc71952b22cfc2b09226d\n'
1567
            '2,2,2\nright\nmerged\nend merged\n',
1568
            GzipFile(mode='rb', fileobj=StringIO(delta_data)).read())
1569
1570
    def test_annotated_to_fulltext_no_eol(self):
1571
        """Test adapting annotated knits to full texts (for -> weaves)."""
1572
        # we need a full text, and a delta
1573
        f, parents = get_diamond_vf(self.get_knit(), trailing_eol=False)
1574
        # Reconstructing a full text requires a backing versioned file, and it
1575
        # must have the base lines requested from it.
1576
        logged_vf = versionedfile.RecordingVersionedFileDecorator(f)
1577
        ft_data, delta_data = self.helpGetBytes(f,
3350.3.7 by Robert Collins
Create a registry of versioned file record adapters.
1578
            _mod_knit.FTAnnotatedToFullText(None),
3350.3.4 by Robert Collins
Finish adapters for annotated knits to unannotated knits and full texts.
1579
            _mod_knit.DeltaAnnotatedToFullText(logged_vf))
1580
        self.assertEqual('origin', ft_data)
1581
        self.assertEqual('base\nleft\nright\nmerged', delta_data)
1582
        self.assertEqual([('get_lines', 'left')], logged_vf.calls)
1583
1584
    def test_annotated_to_fulltext(self):
1585
        """Test adapting annotated knits to full texts (for -> weaves)."""
1586
        # we need a full text, and a delta
1587
        f, parents = get_diamond_vf(self.get_knit())
1588
        # Reconstructing a full text requires a backing versioned file, and it
1589
        # must have the base lines requested from it.
1590
        logged_vf = versionedfile.RecordingVersionedFileDecorator(f)
1591
        ft_data, delta_data = self.helpGetBytes(f,
3350.3.7 by Robert Collins
Create a registry of versioned file record adapters.
1592
            _mod_knit.FTAnnotatedToFullText(None),
3350.3.4 by Robert Collins
Finish adapters for annotated knits to unannotated knits and full texts.
1593
            _mod_knit.DeltaAnnotatedToFullText(logged_vf))
1594
        self.assertEqual('origin\n', ft_data)
1595
        self.assertEqual('base\nleft\nright\nmerged\n', delta_data)
1596
        self.assertEqual([('get_lines', 'left')], logged_vf.calls)
3350.3.5 by Robert Collins
Create adapters from plain compressed knit content.
1597
1598
    def test_unannotated_to_fulltext(self):
1599
        """Test adapting unannotated knits to full texts.
1600
        
1601
        This is used for -> weaves, and for -> annotated knits.
1602
        """
1603
        # we need a full text, and a delta
1604
        f, parents = get_diamond_vf(self.get_knit(annotated=False))
1605
        # Reconstructing a full text requires a backing versioned file, and it
1606
        # must have the base lines requested from it.
1607
        logged_vf = versionedfile.RecordingVersionedFileDecorator(f)
1608
        ft_data, delta_data = self.helpGetBytes(f,
3350.3.7 by Robert Collins
Create a registry of versioned file record adapters.
1609
            _mod_knit.FTPlainToFullText(None),
3350.3.5 by Robert Collins
Create adapters from plain compressed knit content.
1610
            _mod_knit.DeltaPlainToFullText(logged_vf))
1611
        self.assertEqual('origin\n', ft_data)
1612
        self.assertEqual('base\nleft\nright\nmerged\n', delta_data)
1613
        self.assertEqual([('get_lines', 'left')], logged_vf.calls)
1614
3350.3.6 by Robert Collins
Test EOL behaviour of plain knit record adapters.
1615
    def test_unannotated_to_fulltext_no_eol(self):
1616
        """Test adapting unannotated knits to full texts.
1617
        
1618
        This is used for -> weaves, and for -> annotated knits.
1619
        """
1620
        # we need a full text, and a delta
1621
        f, parents = get_diamond_vf(self.get_knit(annotated=False),
1622
            trailing_eol=False)
1623
        # Reconstructing a full text requires a backing versioned file, and it
1624
        # must have the base lines requested from it.
1625
        logged_vf = versionedfile.RecordingVersionedFileDecorator(f)
1626
        ft_data, delta_data = self.helpGetBytes(f,
3350.3.7 by Robert Collins
Create a registry of versioned file record adapters.
1627
            _mod_knit.FTPlainToFullText(None),
3350.3.6 by Robert Collins
Test EOL behaviour of plain knit record adapters.
1628
            _mod_knit.DeltaPlainToFullText(logged_vf))
1629
        self.assertEqual('origin', ft_data)
1630
        self.assertEqual('base\nleft\nright\nmerged', delta_data)
1631
        self.assertEqual([('get_lines', 'left')], logged_vf.calls)
1632