~bzr-pqm/bzr/bzr.dev

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
1664.2.9 by Aaron Bentley
Ported weave merge test to versionedfile
24
from StringIO import StringIO
25
1563.2.6 by Robert Collins
Start check tests for knits (pending), and remove dead code.
26
import bzrlib
2039.1.1 by Aaron Bentley
Clean up progress properly when interrupted during fetch (#54000)
27
from bzrlib import (
28
    errors,
2309.4.7 by John Arbash Meinel
Update VersionedFile tests to ensure that they can take Unicode,
29
    osutils,
2039.1.1 by Aaron Bentley
Clean up progress properly when interrupted during fetch (#54000)
30
    progress,
31
    )
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.
32
from bzrlib.errors import (
33
                           RevisionNotPresent, 
34
                           RevisionAlreadyPresent,
35
                           WeaveParentMismatch
36
                           )
1563.2.6 by Robert Collins
Start check tests for knits (pending), and remove dead code.
37
from bzrlib.knit import KnitVersionedFile, \
38
     KnitAnnotateFactory
2520.4.150 by Aaron Bentley
Test that non-Weave uses left_matching_blocks for add_lines
39
from bzrlib.tests import TestCaseWithTransport, TestSkipped
1666.1.1 by Robert Collins
Add trivial http-using test for versioned files.
40
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
41
from bzrlib.trace import mutter
1563.2.16 by Robert Collins
Change WeaveStore into VersionedFileStore and make its versoined file class parameterisable.
42
from bzrlib.transport import get_transport
1563.2.13 by Robert Collins
InterVersionedFile implemented.
43
from bzrlib.transport.memory import MemoryTransport
1684.3.1 by Robert Collins
Fix versioned file joins with empty targets.
44
from bzrlib.tsort import topo_sort
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.
45
import bzrlib.versionedfile as versionedfile
1563.2.9 by Robert Collins
Update versionedfile api tests to ensure that data is available after every operation.
46
from bzrlib.weave import WeaveFile
1664.2.9 by Aaron Bentley
Ported weave merge test to versionedfile
47
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.
48
49
50
class VersionedFileTestMixIn(object):
51
    """A mixin test class for testing VersionedFiles.
52
53
    This is not an adaptor-style test at this point because
54
    theres no dynamic substitution of versioned file implementations,
55
    they are strictly controlled by their owning repositories.
56
    """
57
58
    def test_add(self):
59
        f = self.get_file()
60
        f.add_lines('r0', [], ['a\n', 'b\n'])
61
        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.
62
        def verify_file(f):
63
            versions = f.versions()
64
            self.assertTrue('r0' in versions)
65
            self.assertTrue('r1' in versions)
66
            self.assertEquals(f.get_lines('r0'), ['a\n', 'b\n'])
67
            self.assertEquals(f.get_text('r0'), 'a\nb\n')
68
            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.
69
            self.assertEqual(2, len(f))
70
            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.
71
    
72
            self.assertRaises(RevisionNotPresent,
73
                f.add_lines, 'r2', ['foo'], [])
74
            self.assertRaises(RevisionAlreadyPresent,
75
                f.add_lines, 'r1', [], [])
76
        verify_file(f)
1666.1.6 by Robert Collins
Make knit the default format.
77
        # this checks that reopen with create=True does not break anything.
78
        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.
79
        verify_file(f)
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
80
1596.2.32 by Robert Collins
Reduce re-extraction of texts during weave to knit joins by providing a memoisation facility.
81
    def test_adds_with_parent_texts(self):
82
        f = self.get_file()
83
        parent_texts = {}
84
        parent_texts['r0'] = f.add_lines('r0', [], ['a\n', 'b\n'])
85
        try:
86
            parent_texts['r1'] = f.add_lines_with_ghosts('r1',
87
                                                         ['r0', 'ghost'], 
88
                                                         ['b\n', 'c\n'],
89
                                                         parent_texts=parent_texts)
90
        except NotImplementedError:
91
            # if the format doesn't support ghosts, just add normally.
92
            parent_texts['r1'] = f.add_lines('r1',
93
                                             ['r0'], 
94
                                             ['b\n', 'c\n'],
95
                                             parent_texts=parent_texts)
96
        f.add_lines('r2', ['r1'], ['c\n', 'd\n'], parent_texts=parent_texts)
97
        self.assertNotEqual(None, parent_texts['r0'])
98
        self.assertNotEqual(None, parent_texts['r1'])
99
        def verify_file(f):
100
            versions = f.versions()
101
            self.assertTrue('r0' in versions)
102
            self.assertTrue('r1' in versions)
103
            self.assertTrue('r2' in versions)
104
            self.assertEquals(f.get_lines('r0'), ['a\n', 'b\n'])
105
            self.assertEquals(f.get_lines('r1'), ['b\n', 'c\n'])
106
            self.assertEquals(f.get_lines('r2'), ['c\n', 'd\n'])
107
            self.assertEqual(3, f.num_versions())
108
            origins = f.annotate('r1')
109
            self.assertEquals(origins[0][0], 'r0')
110
            self.assertEquals(origins[1][0], 'r1')
111
            origins = f.annotate('r2')
112
            self.assertEquals(origins[0][0], 'r1')
113
            self.assertEquals(origins[1][0], 'r2')
114
115
        verify_file(f)
116
        f = self.reopen_file()
117
        verify_file(f)
118
1666.1.6 by Robert Collins
Make knit the default format.
119
    def test_add_unicode_content(self):
120
        # unicode content is not permitted in versioned files. 
121
        # versioned files version sequences of bytes only.
122
        vf = self.get_file()
123
        self.assertRaises(errors.BzrBadParameterUnicode,
124
            vf.add_lines, 'a', [], ['a\n', u'b\n', 'c\n'])
125
        self.assertRaises(
126
            (errors.BzrBadParameterUnicode, NotImplementedError),
127
            vf.add_lines_with_ghosts, 'a', [], ['a\n', u'b\n', 'c\n'])
128
2520.4.150 by Aaron Bentley
Test that non-Weave uses left_matching_blocks for add_lines
129
    def test_add_follows_left_matching_blocks(self):
130
        """If we change left_matching_blocks, delta changes
131
132
        Note: There are multiple correct deltas in this case, because
133
        we start with 1 "a" and we get 3.
134
        """
135
        vf = self.get_file()
136
        if isinstance(vf, WeaveFile):
137
            raise TestSkipped("WeaveFile ignores left_matching_blocks")
138
        vf.add_lines('1', [], ['a\n'])
139
        vf.add_lines('2', ['1'], ['a\n', 'a\n', 'a\n'],
140
                     left_matching_blocks=[(0, 0, 1), (1, 3, 0)])
141
        self.assertEqual([(1, 1, 2, [('2', 'a\n'), ('2', 'a\n')])],
142
                         vf.get_delta('2')[3])
143
        vf.add_lines('3', ['1'], ['a\n', 'a\n', 'a\n'],
144
                     left_matching_blocks=[(0, 2, 1), (1, 3, 0)])
145
        self.assertEqual([(0, 0, 2, [('3', 'a\n'), ('3', 'a\n')])],
146
                         vf.get_delta('3')[3])
147
1666.1.6 by Robert Collins
Make knit the default format.
148
    def test_inline_newline_throws(self):
149
        # \r characters are not permitted in lines being added
150
        vf = self.get_file()
151
        self.assertRaises(errors.BzrBadParameterContainsNewline, 
152
            vf.add_lines, 'a', [], ['a\n\n'])
153
        self.assertRaises(
154
            (errors.BzrBadParameterContainsNewline, NotImplementedError),
155
            vf.add_lines_with_ghosts, 'a', [], ['a\n\n'])
156
        # but inline CR's are allowed
157
        vf.add_lines('a', [], ['a\r\n'])
158
        try:
159
            vf.add_lines_with_ghosts('b', [], ['a\r\n'])
160
        except NotImplementedError:
161
            pass
162
2229.2.1 by Aaron Bentley
Reject reserved ids in versiondfile, tree, branch and repository
163
    def test_add_reserved(self):
164
        vf = self.get_file()
165
        self.assertRaises(errors.ReservedId,
166
            vf.add_lines, 'a:', [], ['a\n', 'b\n', 'c\n'])
167
168
        self.assertRaises(errors.ReservedId,
169
            vf.add_delta, 'a:', [], None, 'sha1', False, ((0, 0, 0, []),))
170
171
    def test_get_reserved(self):
172
        vf = self.get_file()
173
        self.assertRaises(errors.ReservedId, vf.get_delta, 'b:')
174
        self.assertRaises(errors.ReservedId, vf.get_texts, ['b:'])
175
        self.assertRaises(errors.ReservedId, vf.get_lines, 'b:')
176
        self.assertRaises(errors.ReservedId, vf.get_text, 'b:')
177
1596.2.37 by Robert Collins
Switch to delta based content copying in the generic versioned file copier.
178
    def test_get_delta(self):
1596.2.36 by Robert Collins
add a get_delta api to versioned_file.
179
        f = self.get_file()
1596.2.38 by Robert Collins
rollback from using deltas to using fulltexts - deltas need more work to be ready.
180
        sha1s = self._setup_for_deltas(f)
181
        expected_delta = (None, '6bfa09d82ce3e898ad4641ae13dd4fdb9cf0d76b', False, 
182
                          [(0, 0, 1, [('base', 'line\n')])])
183
        self.assertEqual(expected_delta, f.get_delta('base'))
184
        next_parent = 'base'
185
        text_name = 'chain1-'
186
        for depth in range(26):
187
            new_version = text_name + '%s' % depth
188
            expected_delta = (next_parent, sha1s[depth], 
189
                              False,
190
                              [(depth + 1, depth + 1, 1, [(new_version, 'line\n')])])
191
            self.assertEqual(expected_delta, f.get_delta(new_version))
192
            next_parent = new_version
193
        next_parent = 'base'
194
        text_name = 'chain2-'
195
        for depth in range(26):
196
            new_version = text_name + '%s' % depth
197
            expected_delta = (next_parent, sha1s[depth], False,
198
                              [(depth + 1, depth + 1, 1, [(new_version, 'line\n')])])
199
            self.assertEqual(expected_delta, f.get_delta(new_version))
200
            next_parent = new_version
201
        # smoke test for eol support
202
        expected_delta = ('base', '264f39cab871e4cfd65b3a002f7255888bb5ed97', True, [])
203
        self.assertEqual(['line'], f.get_lines('noeol'))
204
        self.assertEqual(expected_delta, f.get_delta('noeol'))
205
206
    def test_get_deltas(self):
207
        f = self.get_file()
208
        sha1s = self._setup_for_deltas(f)
209
        deltas = f.get_deltas(f.versions())
210
        expected_delta = (None, '6bfa09d82ce3e898ad4641ae13dd4fdb9cf0d76b', False, 
211
                          [(0, 0, 1, [('base', 'line\n')])])
212
        self.assertEqual(expected_delta, deltas['base'])
213
        next_parent = 'base'
214
        text_name = 'chain1-'
215
        for depth in range(26):
216
            new_version = text_name + '%s' % depth
217
            expected_delta = (next_parent, sha1s[depth], 
218
                              False,
219
                              [(depth + 1, depth + 1, 1, [(new_version, 'line\n')])])
220
            self.assertEqual(expected_delta, deltas[new_version])
221
            next_parent = new_version
222
        next_parent = 'base'
223
        text_name = 'chain2-'
224
        for depth in range(26):
225
            new_version = text_name + '%s' % depth
226
            expected_delta = (next_parent, sha1s[depth], False,
227
                              [(depth + 1, depth + 1, 1, [(new_version, 'line\n')])])
228
            self.assertEqual(expected_delta, deltas[new_version])
229
            next_parent = new_version
230
        # smoke tests for eol support
231
        expected_delta = ('base', '264f39cab871e4cfd65b3a002f7255888bb5ed97', True, [])
232
        self.assertEqual(['line'], f.get_lines('noeol'))
233
        self.assertEqual(expected_delta, deltas['noeol'])
234
        # smoke tests for eol support - two noeol in a row same content
235
        expected_deltas = (('noeol', '3ad7ee82dbd8f29ecba073f96e43e414b3f70a4d', True, 
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
236
                          [(0, 1, 2, [('noeolsecond', 'line\n'), ('noeolsecond', 'line\n')])]),
1596.2.38 by Robert Collins
rollback from using deltas to using fulltexts - deltas need more work to be ready.
237
                          ('noeol', '3ad7ee82dbd8f29ecba073f96e43e414b3f70a4d', True, 
238
                           [(0, 0, 1, [('noeolsecond', 'line\n')]), (1, 1, 0, [])]))
239
        self.assertEqual(['line\n', 'line'], f.get_lines('noeolsecond'))
240
        self.assertTrue(deltas['noeolsecond'] in expected_deltas)
241
        # two no-eol in a row, different content
242
        expected_delta = ('noeolsecond', '8bb553a84e019ef1149db082d65f3133b195223b', True, 
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
243
                          [(1, 2, 1, [('noeolnotshared', 'phone\n')])])
1596.2.38 by Robert Collins
rollback from using deltas to using fulltexts - deltas need more work to be ready.
244
        self.assertEqual(['line\n', 'phone'], f.get_lines('noeolnotshared'))
245
        self.assertEqual(expected_delta, deltas['noeolnotshared'])
246
        # eol folling a no-eol with content change
247
        expected_delta = ('noeol', 'a61f6fb6cfc4596e8d88c34a308d1e724caf8977', False, 
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
248
                          [(0, 1, 1, [('eol', 'phone\n')])])
1596.2.38 by Robert Collins
rollback from using deltas to using fulltexts - deltas need more work to be ready.
249
        self.assertEqual(['phone\n'], f.get_lines('eol'))
250
        self.assertEqual(expected_delta, deltas['eol'])
251
        # eol folling a no-eol with content change
252
        expected_delta = ('noeol', '6bfa09d82ce3e898ad4641ae13dd4fdb9cf0d76b', False, 
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
253
                          [(0, 1, 1, [('eolline', 'line\n')])])
1596.2.38 by Robert Collins
rollback from using deltas to using fulltexts - deltas need more work to be ready.
254
        self.assertEqual(['line\n'], f.get_lines('eolline'))
255
        self.assertEqual(expected_delta, deltas['eolline'])
256
        # eol with no parents
257
        expected_delta = (None, '264f39cab871e4cfd65b3a002f7255888bb5ed97', True, 
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
258
                          [(0, 0, 1, [('noeolbase', 'line\n')])])
1596.2.38 by Robert Collins
rollback from using deltas to using fulltexts - deltas need more work to be ready.
259
        self.assertEqual(['line'], f.get_lines('noeolbase'))
260
        self.assertEqual(expected_delta, deltas['noeolbase'])
261
        # eol with two parents, in inverse insertion order
262
        expected_deltas = (('noeolbase', '264f39cab871e4cfd65b3a002f7255888bb5ed97', True,
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
263
                            [(0, 1, 1, [('eolbeforefirstparent', 'line\n')])]),
1596.2.38 by Robert Collins
rollback from using deltas to using fulltexts - deltas need more work to be ready.
264
                           ('noeolbase', '264f39cab871e4cfd65b3a002f7255888bb5ed97', True,
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
265
                            [(0, 1, 1, [('eolbeforefirstparent', 'line\n')])]))
1596.2.38 by Robert Collins
rollback from using deltas to using fulltexts - deltas need more work to be ready.
266
        self.assertEqual(['line'], f.get_lines('eolbeforefirstparent'))
267
        #self.assertTrue(deltas['eolbeforefirstparent'] in expected_deltas)
268
2520.4.85 by Aaron Bentley
Get all test passing (which just proves there aren't enough tests!)
269
    def test_make_mpdiffs(self):
2520.4.3 by Aaron Bentley
Implement plain strategy for extracting and installing multiparent diffs
270
        from bzrlib import multiparent
271
        vf = self.get_file('foo')
272
        sha1s = self._setup_for_deltas(vf)
273
        new_vf = self.get_file('bar')
274
        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!)
275
            mpdiff = vf.make_mpdiffs([version])[0]
276
            new_vf.add_mpdiffs([(version, vf.get_parents(version),
277
                                 vf.get_sha1(version), mpdiff)])
2520.4.3 by Aaron Bentley
Implement plain strategy for extracting and installing multiparent diffs
278
            self.assertEqualDiff(vf.get_text(version),
279
                                 new_vf.get_text(version))
280
1596.2.38 by Robert Collins
rollback from using deltas to using fulltexts - deltas need more work to be ready.
281
    def _setup_for_deltas(self, f):
1596.2.36 by Robert Collins
add a get_delta api to versioned_file.
282
        self.assertRaises(errors.RevisionNotPresent, f.get_delta, 'base')
283
        # add texts that should trip the knit maximum delta chain threshold
284
        # as well as doing parallel chains of data in knits.
285
        # this is done by two chains of 25 insertions
286
        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.
287
        f.add_lines('noeol', ['base'], ['line'])
288
        # detailed eol tests:
289
        # shared last line with parent no-eol
290
        f.add_lines('noeolsecond', ['noeol'], ['line\n', 'line'])
291
        # differing last line with parent, both no-eol
292
        f.add_lines('noeolnotshared', ['noeolsecond'], ['line\n', 'phone'])
293
        # add eol following a noneol parent, change content
294
        f.add_lines('eol', ['noeol'], ['phone\n'])
295
        # add eol following a noneol parent, no change content
296
        f.add_lines('eolline', ['noeol'], ['line\n'])
297
        # noeol with no parents:
298
        f.add_lines('noeolbase', [], ['line'])
299
        # noeol preceeding its leftmost parent in the output:
300
        # this is done by making it a merge of two parents with no common
301
        # anestry: noeolbase and noeol with the 
302
        # later-inserted parent the leftmost.
303
        f.add_lines('eolbeforefirstparent', ['noeolbase', 'noeol'], ['line'])
304
        # two identical eol texts
305
        f.add_lines('noeoldup', ['noeol'], ['line'])
1596.2.36 by Robert Collins
add a get_delta api to versioned_file.
306
        next_parent = 'base'
307
        text_name = 'chain1-'
308
        text = ['line\n']
309
        sha1s = {0 :'da6d3141cb4a5e6f464bf6e0518042ddc7bfd079',
310
                 1 :'45e21ea146a81ea44a821737acdb4f9791c8abe7',
311
                 2 :'e1f11570edf3e2a070052366c582837a4fe4e9fa',
312
                 3 :'26b4b8626da827088c514b8f9bbe4ebf181edda1',
313
                 4 :'e28a5510be25ba84d31121cff00956f9970ae6f6',
314
                 5 :'d63ec0ce22e11dcf65a931b69255d3ac747a318d',
315
                 6 :'2c2888d288cb5e1d98009d822fedfe6019c6a4ea',
316
                 7 :'95c14da9cafbf828e3e74a6f016d87926ba234ab',
317
                 8 :'779e9a0b28f9f832528d4b21e17e168c67697272',
318
                 9 :'1f8ff4e5c6ff78ac106fcfe6b1e8cb8740ff9a8f',
319
                 10:'131a2ae712cf51ed62f143e3fbac3d4206c25a05',
320
                 11:'c5a9d6f520d2515e1ec401a8f8a67e6c3c89f199',
321
                 12:'31a2286267f24d8bedaa43355f8ad7129509ea85',
322
                 13:'dc2a7fe80e8ec5cae920973973a8ee28b2da5e0a',
323
                 14:'2c4b1736566b8ca6051e668de68650686a3922f2',
324
                 15:'5912e4ecd9b0c07be4d013e7e2bdcf9323276cde',
325
                 16:'b0d2e18d3559a00580f6b49804c23fea500feab3',
326
                 17:'8e1d43ad72f7562d7cb8f57ee584e20eb1a69fc7',
327
                 18:'5cf64a3459ae28efa60239e44b20312d25b253f3',
328
                 19:'1ebed371807ba5935958ad0884595126e8c4e823',
329
                 20:'2aa62a8b06fb3b3b892a3292a068ade69d5ee0d3',
330
                 21:'01edc447978004f6e4e962b417a4ae1955b6fe5d',
331
                 22:'d8d8dc49c4bf0bab401e0298bb5ad827768618bb',
332
                 23:'c21f62b1c482862983a8ffb2b0c64b3451876e3f',
333
                 24:'c0593fe795e00dff6b3c0fe857a074364d5f04fc',
334
                 25:'dd1a1cf2ba9cc225c3aff729953e6364bf1d1855',
335
                 }
336
        for depth in range(26):
337
            new_version = text_name + '%s' % depth
338
            text = text + ['line\n']
339
            f.add_lines(new_version, [next_parent], text)
340
            next_parent = new_version
341
        next_parent = 'base'
342
        text_name = 'chain2-'
343
        text = ['line\n']
344
        for depth in range(26):
345
            new_version = text_name + '%s' % depth
346
            text = text + ['line\n']
347
            f.add_lines(new_version, [next_parent], text)
348
            next_parent = new_version
1596.2.38 by Robert Collins
rollback from using deltas to using fulltexts - deltas need more work to be ready.
349
        return sha1s
1596.2.37 by Robert Collins
Switch to delta based content copying in the generic versioned file copier.
350
351
    def test_add_delta(self):
352
        # tests for the add-delta facility.
353
        # at this point, optimising for speed, we assume no checks when deltas are inserted.
354
        # this may need to be revisited.
355
        source = self.get_file('source')
356
        source.add_lines('base', [], ['line\n'])
357
        next_parent = 'base'
358
        text_name = 'chain1-'
359
        text = ['line\n']
360
        for depth in range(26):
361
            new_version = text_name + '%s' % depth
362
            text = text + ['line\n']
363
            source.add_lines(new_version, [next_parent], text)
364
            next_parent = new_version
365
        next_parent = 'base'
366
        text_name = 'chain2-'
367
        text = ['line\n']
368
        for depth in range(26):
369
            new_version = text_name + '%s' % depth
370
            text = text + ['line\n']
371
            source.add_lines(new_version, [next_parent], text)
372
            next_parent = new_version
373
        source.add_lines('noeol', ['base'], ['line'])
374
        
375
        target = self.get_file('target')
376
        for version in source.versions():
377
            parent, sha1, noeol, delta = source.get_delta(version)
378
            target.add_delta(version,
379
                             source.get_parents(version),
380
                             parent,
381
                             sha1,
382
                             noeol,
383
                             delta)
384
        self.assertRaises(RevisionAlreadyPresent,
385
                          target.add_delta, 'base', [], None, '', False, [])
386
        for version in source.versions():
387
            self.assertEqual(source.get_lines(version),
388
                             target.get_lines(version))
1596.2.36 by Robert Collins
add a get_delta api to versioned_file.
389
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
390
    def test_ancestry(self):
391
        f = self.get_file()
1563.2.29 by Robert Collins
Remove all but fetch references to repository.revision_store.
392
        self.assertEqual([], f.get_ancestry([]))
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
393
        f.add_lines('r0', [], ['a\n', 'b\n'])
394
        f.add_lines('r1', ['r0'], ['b\n', 'c\n'])
395
        f.add_lines('r2', ['r0'], ['b\n', 'c\n'])
396
        f.add_lines('r3', ['r2'], ['b\n', 'c\n'])
397
        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.
398
        self.assertEqual([], f.get_ancestry([]))
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
399
        versions = f.get_ancestry(['rM'])
400
        # there are some possibilities:
401
        # r0 r1 r2 rM r3
402
        # r0 r1 r2 r3 rM
403
        # etc
404
        # so we check indexes
405
        r0 = versions.index('r0')
406
        r1 = versions.index('r1')
407
        r2 = versions.index('r2')
408
        self.assertFalse('r3' in versions)
409
        rM = versions.index('rM')
410
        self.assertTrue(r0 < r1)
411
        self.assertTrue(r0 < r2)
412
        self.assertTrue(r1 < rM)
413
        self.assertTrue(r2 < rM)
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
414
415
        self.assertRaises(RevisionNotPresent,
416
            f.get_ancestry, ['rM', 'rX'])
1594.2.21 by Robert Collins
Teach versioned files to prevent mutation after finishing.
417
2530.1.1 by Aaron Bentley
Make topological sorting optional for get_ancestry
418
        self.assertEqual(set(f.get_ancestry('rM')),
419
            set(f.get_ancestry('rM', topo_sorted=False)))
420
1594.2.21 by Robert Collins
Teach versioned files to prevent mutation after finishing.
421
    def test_mutate_after_finish(self):
422
        f = self.get_file()
423
        f.transaction_finished()
1596.2.37 by Robert Collins
Switch to delta based content copying in the generic versioned file copier.
424
        self.assertRaises(errors.OutSideTransaction, f.add_delta, '', [], '', '', False, [])
1594.2.21 by Robert Collins
Teach versioned files to prevent mutation after finishing.
425
        self.assertRaises(errors.OutSideTransaction, f.add_lines, '', [], [])
426
        self.assertRaises(errors.OutSideTransaction, f.add_lines_with_ghosts, '', [], [])
427
        self.assertRaises(errors.OutSideTransaction, f.fix_parents, '', [])
428
        self.assertRaises(errors.OutSideTransaction, f.join, '')
1594.2.24 by Robert Collins
Make use of the transaction finalisation warning support to implement in-knit caching.
429
        self.assertRaises(errors.OutSideTransaction, f.clone_text, 'base', 'bar', ['foo'])
1563.2.7 by Robert Collins
add versioned file clear_cache entry.
430
        
431
    def test_clear_cache(self):
432
        f = self.get_file()
433
        # on a new file it should not error
434
        f.clear_cache()
435
        # and after adding content, doing a clear_cache and a get should work.
436
        f.add_lines('0', [], ['a'])
437
        f.clear_cache()
438
        self.assertEqual(['a'], f.get_lines('0'))
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
439
440
    def test_clone_text(self):
441
        f = self.get_file()
442
        f.add_lines('r0', [], ['a\n', 'b\n'])
1563.2.5 by Robert Collins
Remove unused transaction references from knit.py and the versionedfile interface.
443
        f.clone_text('r1', 'r0', ['r0'])
1563.2.9 by Robert Collins
Update versionedfile api tests to ensure that data is available after every operation.
444
        def verify_file(f):
445
            self.assertEquals(f.get_lines('r1'), f.get_lines('r0'))
446
            self.assertEquals(f.get_lines('r1'), ['a\n', 'b\n'])
447
            self.assertEquals(f.get_parents('r1'), ['r0'])
448
    
449
            self.assertRaises(RevisionNotPresent,
450
                f.clone_text, 'r2', 'rX', [])
451
            self.assertRaises(RevisionAlreadyPresent,
452
                f.clone_text, 'r1', 'r0', [])
453
        verify_file(f)
454
        verify_file(self.reopen_file())
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
455
1563.2.13 by Robert Collins
InterVersionedFile implemented.
456
    def test_create_empty(self):
457
        f = self.get_file()
458
        f.add_lines('0', [], ['a\n'])
459
        new_f = f.create_empty('t', MemoryTransport())
460
        # smoke test, specific types should check it is honoured correctly for
461
        # non type attributes
462
        self.assertEqual([], new_f.versions())
463
        self.assertTrue(isinstance(new_f, f.__class__))
464
1563.2.15 by Robert Collins
remove the weavestore assumptions about the number and nature of files it manages.
465
    def test_copy_to(self):
466
        f = self.get_file()
467
        f.add_lines('0', [], ['a\n'])
468
        t = MemoryTransport()
469
        f.copy_to('foo', t)
470
        for suffix in f.__class__.get_suffixes():
471
            self.assertTrue(t.has('foo' + suffix))
472
473
    def test_get_suffixes(self):
474
        f = self.get_file()
475
        # should be the same
476
        self.assertEqual(f.__class__.get_suffixes(), f.__class__.get_suffixes())
477
        # and should be a list
478
        self.assertTrue(isinstance(f.__class__.get_suffixes(), list))
479
1684.3.1 by Robert Collins
Fix versioned file joins with empty targets.
480
    def build_graph(self, file, graph):
481
        for node in topo_sort(graph.items()):
482
            file.add_lines(node, graph[node], [])
483
1563.2.13 by Robert Collins
InterVersionedFile implemented.
484
    def test_get_graph(self):
485
        f = self.get_file()
1684.3.1 by Robert Collins
Fix versioned file joins with empty targets.
486
        graph = {
2625.8.1 by Robert Collins
LIBRARY API BREAKS:
487
            'v1': (),
488
            'v2': ('v1', ),
489
            'v3': ('v2', )}
1684.3.1 by Robert Collins
Fix versioned file joins with empty targets.
490
        self.build_graph(f, graph)
491
        self.assertEqual(graph, f.get_graph())
492
    
493
    def test_get_graph_partial(self):
494
        f = self.get_file()
495
        complex_graph = {}
496
        simple_a = {
2625.8.1 by Robert Collins
LIBRARY API BREAKS:
497
            'c': (),
498
            'b': ('c', ),
499
            'a': ('b', ),
1684.3.1 by Robert Collins
Fix versioned file joins with empty targets.
500
            }
501
        complex_graph.update(simple_a)
502
        simple_b = {
2625.8.1 by Robert Collins
LIBRARY API BREAKS:
503
            'c': (),
504
            'b': ('c', ),
1684.3.1 by Robert Collins
Fix versioned file joins with empty targets.
505
            }
506
        complex_graph.update(simple_b)
507
        simple_gam = {
2625.8.1 by Robert Collins
LIBRARY API BREAKS:
508
            'c': (),
509
            'oo': (),
510
            'bar': ('oo', 'c'),
511
            'gam': ('bar', ),
1684.3.1 by Robert Collins
Fix versioned file joins with empty targets.
512
            }
513
        complex_graph.update(simple_gam)
514
        simple_b_gam = {}
515
        simple_b_gam.update(simple_gam)
516
        simple_b_gam.update(simple_b)
517
        self.build_graph(f, complex_graph)
518
        self.assertEqual(simple_a, f.get_graph(['a']))
519
        self.assertEqual(simple_b, f.get_graph(['b']))
520
        self.assertEqual(simple_gam, f.get_graph(['gam']))
521
        self.assertEqual(simple_b_gam, f.get_graph(['b', 'gam']))
1563.2.13 by Robert Collins
InterVersionedFile implemented.
522
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
523
    def test_get_parents(self):
524
        f = self.get_file()
525
        f.add_lines('r0', [], ['a\n', 'b\n'])
526
        f.add_lines('r1', [], ['a\n', 'b\n'])
527
        f.add_lines('r2', [], ['a\n', 'b\n'])
528
        f.add_lines('r3', [], ['a\n', 'b\n'])
529
        f.add_lines('m', ['r0', 'r1', 'r2', 'r3'], ['a\n', 'b\n'])
530
        self.assertEquals(f.get_parents('m'), ['r0', 'r1', 'r2', 'r3'])
531
532
        self.assertRaises(RevisionNotPresent,
533
            f.get_parents, 'y')
534
535
    def test_annotate(self):
536
        f = self.get_file()
537
        f.add_lines('r0', [], ['a\n', 'b\n'])
538
        f.add_lines('r1', ['r0'], ['c\n', 'b\n'])
539
        origins = f.annotate('r1')
540
        self.assertEquals(origins[0][0], 'r1')
541
        self.assertEquals(origins[1][0], 'r0')
542
543
        self.assertRaises(RevisionNotPresent,
544
            f.annotate, 'foo')
545
1563.2.6 by Robert Collins
Start check tests for knits (pending), and remove dead code.
546
    def test_detection(self):
547
        # Test weaves detect corruption.
548
        #
549
        # Weaves contain a checksum of their texts.
550
        # When a text is extracted, this checksum should be
551
        # verified.
552
553
        w = self.get_file_corrupted_text()
554
555
        self.assertEqual('hello\n', w.get_text('v1'))
556
        self.assertRaises(errors.WeaveInvalidChecksum, w.get_text, 'v2')
557
        self.assertRaises(errors.WeaveInvalidChecksum, w.get_lines, 'v2')
558
        self.assertRaises(errors.WeaveInvalidChecksum, w.check)
559
560
        w = self.get_file_corrupted_checksum()
561
562
        self.assertEqual('hello\n', w.get_text('v1'))
563
        self.assertRaises(errors.WeaveInvalidChecksum, w.get_text, 'v2')
564
        self.assertRaises(errors.WeaveInvalidChecksum, w.get_lines, 'v2')
565
        self.assertRaises(errors.WeaveInvalidChecksum, w.check)
566
567
    def get_file_corrupted_text(self):
568
        """Return a versioned file with corrupt text but valid metadata."""
569
        raise NotImplementedError(self.get_file_corrupted_text)
570
1563.2.9 by Robert Collins
Update versionedfile api tests to ensure that data is available after every operation.
571
    def reopen_file(self, name='foo'):
572
        """Open the versioned file from disk again."""
573
        raise NotImplementedError(self.reopen_file)
574
2625.8.1 by Robert Collins
LIBRARY API BREAKS:
575
    def test_iter_parents(self):
576
        """iter_parents returns the parents for many nodes."""
577
        f = self.get_file()
578
        # sample data:
579
        # no parents
580
        f.add_lines('r0', [], ['a\n', 'b\n'])
581
        # 1 parents
582
        f.add_lines('r1', ['r0'], ['a\n', 'b\n'])
583
        # 2 parents
584
        f.add_lines('r2', ['r1', 'r0'], ['a\n', 'b\n'])
585
        # XXX TODO a ghost
586
        # cases: each sample data individually:
587
        self.assertEqual(set([('r0', ())]),
588
            set(f.iter_parents(['r0'])))
589
        self.assertEqual(set([('r1', ('r0', ))]),
590
            set(f.iter_parents(['r1'])))
591
        self.assertEqual(set([('r2', ('r1', 'r0'))]),
592
            set(f.iter_parents(['r2'])))
593
        # no nodes returned for a missing node
594
        self.assertEqual(set(),
595
            set(f.iter_parents(['missing'])))
596
        # 1 node returned with missing nodes skipped
597
        self.assertEqual(set([('r1', ('r0', ))]),
598
            set(f.iter_parents(['ghost1', 'r1', 'ghost'])))
599
        # 2 nodes returned
600
        self.assertEqual(set([('r0', ()), ('r1', ('r0', ))]),
601
            set(f.iter_parents(['r0', 'r1'])))
602
        # 2 nodes returned, missing skipped
603
        self.assertEqual(set([('r0', ()), ('r1', ('r0', ))]),
604
            set(f.iter_parents(['a', 'r0', 'b', 'r1', 'c'])))
605
1594.2.6 by Robert Collins
Introduce a api specifically for looking at lines in some versions of the inventory, for fileid_involved.
606
    def test_iter_lines_added_or_present_in_versions(self):
607
        # test that we get at least an equalset of the lines added by
608
        # versions in the weave 
609
        # the ordering here is to make a tree so that dumb searches have
610
        # more changes to muck up.
2039.1.1 by Aaron Bentley
Clean up progress properly when interrupted during fetch (#54000)
611
612
        class InstrumentedProgress(progress.DummyProgress):
613
614
            def __init__(self):
615
616
                progress.DummyProgress.__init__(self)
617
                self.updates = []
618
619
            def update(self, msg=None, current=None, total=None):
620
                self.updates.append((msg, current, total))
621
1594.2.6 by Robert Collins
Introduce a api specifically for looking at lines in some versions of the inventory, for fileid_involved.
622
        vf = self.get_file()
623
        # add a base to get included
624
        vf.add_lines('base', [], ['base\n'])
625
        # add a ancestor to be included on one side
626
        vf.add_lines('lancestor', [], ['lancestor\n'])
627
        # add a ancestor to be included on the other side
628
        vf.add_lines('rancestor', ['base'], ['rancestor\n'])
629
        # add a child of rancestor with no eofile-nl
630
        vf.add_lines('child', ['rancestor'], ['base\n', 'child\n'])
631
        # add a child of lancestor and base to join the two roots
632
        vf.add_lines('otherchild',
633
                     ['lancestor', 'base'],
634
                     ['base\n', 'lancestor\n', 'otherchild\n'])
2039.1.1 by Aaron Bentley
Clean up progress properly when interrupted during fetch (#54000)
635
        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.
636
            # now we need to see what lines are returned, and how often.
637
            lines = {'base\n':0,
638
                     'lancestor\n':0,
639
                     'rancestor\n':0,
640
                     'child\n':0,
641
                     'otherchild\n':0,
642
                     }
2039.1.1 by Aaron Bentley
Clean up progress properly when interrupted during fetch (#54000)
643
            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.
644
            # iterate over the lines
2039.1.1 by Aaron Bentley
Clean up progress properly when interrupted during fetch (#54000)
645
            for line in vf.iter_lines_added_or_present_in_versions(versions, 
646
                pb=progress):
1594.2.6 by Robert Collins
Introduce a api specifically for looking at lines in some versions of the inventory, for fileid_involved.
647
                lines[line] += 1
2039.1.2 by Aaron Bentley
Tweak test to avoid catching assert
648
            if []!= progress.updates: 
649
                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.
650
            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.
651
        lines = iter_with_versions(['child', 'otherchild'],
652
                                   [('Walking content.', 0, 2),
653
                                    ('Walking content.', 1, 2),
2039.1.1 by Aaron Bentley
Clean up progress properly when interrupted during fetch (#54000)
654
                                    ('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.
655
        # we must see child and otherchild
656
        self.assertTrue(lines['child\n'] > 0)
657
        self.assertTrue(lines['otherchild\n'] > 0)
658
        # we dont care if we got more than that.
659
        
660
        # 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.
661
        lines = iter_with_versions(None, [('Walking content.', 0, 5),
662
                                          ('Walking content.', 1, 5),
663
                                          ('Walking content.', 2, 5),
664
                                          ('Walking content.', 3, 5),
665
                                          ('Walking content.', 4, 5),
2039.1.1 by Aaron Bentley
Clean up progress properly when interrupted during fetch (#54000)
666
                                          ('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.
667
        # all lines must be seen at least once
668
        self.assertTrue(lines['base\n'] > 0)
669
        self.assertTrue(lines['lancestor\n'] > 0)
670
        self.assertTrue(lines['rancestor\n'] > 0)
671
        self.assertTrue(lines['child\n'] > 0)
672
        self.assertTrue(lines['otherchild\n'] > 0)
1594.2.7 by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc.
673
674
    def test_fix_parents(self):
675
        # some versioned files allow incorrect parents to be corrected after
676
        # insertion - this may not fix ancestry..
677
        # if they do not supported, they just do not implement it.
1594.2.8 by Robert Collins
add ghost aware apis to knits.
678
        # we test this as an interface test to ensure that those that *do*
679
        # implementent it get it right.
1594.2.7 by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc.
680
        vf = self.get_file()
681
        vf.add_lines('notbase', [], [])
682
        vf.add_lines('base', [], [])
683
        try:
684
            vf.fix_parents('notbase', ['base'])
685
        except NotImplementedError:
686
            return
687
        self.assertEqual(['base'], vf.get_parents('notbase'))
688
        # open again, check it stuck.
689
        vf = self.get_file()
690
        self.assertEqual(['base'], vf.get_parents('notbase'))
691
1594.2.8 by Robert Collins
add ghost aware apis to knits.
692
    def test_fix_parents_with_ghosts(self):
693
        # when fixing parents, ghosts that are listed should not be ghosts
694
        # anymore.
695
        vf = self.get_file()
696
697
        try:
698
            vf.add_lines_with_ghosts('notbase', ['base', 'stillghost'], [])
699
        except NotImplementedError:
700
            return
701
        vf.add_lines('base', [], [])
702
        vf.fix_parents('notbase', ['base', 'stillghost'])
703
        self.assertEqual(['base'], vf.get_parents('notbase'))
704
        # open again, check it stuck.
705
        vf = self.get_file()
706
        self.assertEqual(['base'], vf.get_parents('notbase'))
707
        # and check the ghosts
708
        self.assertEqual(['base', 'stillghost'],
709
                         vf.get_parents_with_ghosts('notbase'))
710
711
    def test_add_lines_with_ghosts(self):
712
        # some versioned file formats allow lines to be added with parent
713
        # information that is > than that in the format. Formats that do
714
        # not support this need to raise NotImplementedError on the
715
        # add_lines_with_ghosts api.
716
        vf = self.get_file()
717
        # 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
718
        # The preferred form is utf8, but we should translate when needed
719
        parent_id_unicode = u'b\xbfse'
720
        parent_id_utf8 = parent_id_unicode.encode('utf8')
1594.2.8 by Robert Collins
add ghost aware apis to knits.
721
        try:
2309.4.7 by John Arbash Meinel
Update VersionedFile tests to ensure that they can take Unicode,
722
            vf.add_lines_with_ghosts('notbxbfse', [parent_id_utf8], [])
1594.2.8 by Robert Collins
add ghost aware apis to knits.
723
        except NotImplementedError:
724
            # check the other ghost apis are also not implemented
725
            self.assertRaises(NotImplementedError, vf.has_ghost, 'foo')
726
            self.assertRaises(NotImplementedError, vf.get_ancestry_with_ghosts, ['foo'])
727
            self.assertRaises(NotImplementedError, vf.get_parents_with_ghosts, 'foo')
728
            self.assertRaises(NotImplementedError, vf.get_graph_with_ghosts)
729
            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.
730
        vf = self.reopen_file()
1594.2.8 by Robert Collins
add ghost aware apis to knits.
731
        # test key graph related apis: getncestry, _graph, get_parents
732
        # has_version
733
        # - 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
734
        self.assertEqual(['notbxbfse'], vf.get_ancestry('notbxbfse'))
735
        self.assertEqual([], vf.get_parents('notbxbfse'))
2625.8.1 by Robert Collins
LIBRARY API BREAKS:
736
        self.assertEqual({'notbxbfse':()}, vf.get_graph())
2309.4.7 by John Arbash Meinel
Update VersionedFile tests to ensure that they can take Unicode,
737
        self.assertFalse(self.callDeprecated([osutils._revision_id_warning],
738
                         vf.has_version, parent_id_unicode))
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
739
        self.assertFalse(vf.has_version(parent_id_utf8))
1594.2.8 by Robert Collins
add ghost aware apis to knits.
740
        # 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
741
        self.assertEqual([parent_id_utf8, 'notbxbfse'], vf.get_ancestry_with_ghosts(['notbxbfse']))
742
        self.assertEqual([parent_id_utf8], vf.get_parents_with_ghosts('notbxbfse'))
743
        self.assertEqual({'notbxbfse':[parent_id_utf8]}, vf.get_graph_with_ghosts())
2309.4.7 by John Arbash Meinel
Update VersionedFile tests to ensure that they can take Unicode,
744
        self.assertTrue(self.callDeprecated([osutils._revision_id_warning],
745
                        vf.has_ghost, parent_id_unicode))
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
746
        self.assertTrue(vf.has_ghost(parent_id_utf8))
1594.2.8 by Robert Collins
add ghost aware apis to knits.
747
        # if we add something that is a ghost of another, it should correct the
748
        # results of the prior apis
2309.4.7 by John Arbash Meinel
Update VersionedFile tests to ensure that they can take Unicode,
749
        self.callDeprecated([osutils._revision_id_warning],
750
                            vf.add_lines, parent_id_unicode, [], [])
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
751
        self.assertEqual([parent_id_utf8, 'notbxbfse'], vf.get_ancestry(['notbxbfse']))
752
        self.assertEqual([parent_id_utf8], vf.get_parents('notbxbfse'))
2625.8.1 by Robert Collins
LIBRARY API BREAKS:
753
        self.assertEqual({parent_id_utf8:(),
754
                          'notbxbfse':(parent_id_utf8, ),
1594.2.8 by Robert Collins
add ghost aware apis to knits.
755
                          },
756
                         vf.get_graph())
2309.4.7 by John Arbash Meinel
Update VersionedFile tests to ensure that they can take Unicode,
757
        self.assertTrue(self.callDeprecated([osutils._revision_id_warning],
758
                        vf.has_version, parent_id_unicode))
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
759
        self.assertTrue(vf.has_version(parent_id_utf8))
1594.2.8 by Robert Collins
add ghost aware apis to knits.
760
        # 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
761
        self.assertEqual([parent_id_utf8, 'notbxbfse'], vf.get_ancestry_with_ghosts(['notbxbfse']))
762
        self.assertEqual([parent_id_utf8], vf.get_parents_with_ghosts('notbxbfse'))
763
        self.assertEqual({parent_id_utf8:[],
764
                          'notbxbfse':[parent_id_utf8],
1594.2.8 by Robert Collins
add ghost aware apis to knits.
765
                          },
766
                         vf.get_graph_with_ghosts())
2309.4.7 by John Arbash Meinel
Update VersionedFile tests to ensure that they can take Unicode,
767
        self.assertFalse(self.callDeprecated([osutils._revision_id_warning],
768
                         vf.has_ghost, parent_id_unicode))
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
769
        self.assertFalse(vf.has_ghost(parent_id_utf8))
1594.2.8 by Robert Collins
add ghost aware apis to knits.
770
1594.2.9 by Robert Collins
Teach Knit repositories how to handle ghosts without corrupting at all.
771
    def test_add_lines_with_ghosts_after_normal_revs(self):
772
        # some versioned file formats allow lines to be added with parent
773
        # information that is > than that in the format. Formats that do
774
        # not support this need to raise NotImplementedError on the
775
        # add_lines_with_ghosts api.
776
        vf = self.get_file()
777
        # probe for ghost support
778
        try:
779
            vf.has_ghost('hoo')
780
        except NotImplementedError:
781
            return
782
        vf.add_lines_with_ghosts('base', [], ['line\n', 'line_b\n'])
783
        vf.add_lines_with_ghosts('references_ghost',
784
                                 ['base', 'a_ghost'],
785
                                 ['line\n', 'line_b\n', 'line_c\n'])
786
        origins = vf.annotate('references_ghost')
787
        self.assertEquals(('base', 'line\n'), origins[0])
788
        self.assertEquals(('base', 'line_b\n'), origins[1])
789
        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.
790
791
    def test_readonly_mode(self):
792
        transport = get_transport(self.get_url('.'))
793
        factory = self.get_factory()
794
        vf = factory('id', transport, 0777, create=True, access_mode='w')
795
        vf = factory('id', transport, access_mode='r')
1596.2.37 by Robert Collins
Switch to delta based content copying in the generic versioned file copier.
796
        self.assertRaises(errors.ReadOnlyError, vf.add_delta, '', [], '', '', False, [])
1594.2.23 by Robert Collins
Test versioned file storage handling of clean/dirty status for accessed versioned files.
797
        self.assertRaises(errors.ReadOnlyError, vf.add_lines, 'base', [], [])
798
        self.assertRaises(errors.ReadOnlyError,
799
                          vf.add_lines_with_ghosts,
800
                          'base',
801
                          [],
802
                          [])
803
        self.assertRaises(errors.ReadOnlyError, vf.fix_parents, 'base', [])
804
        self.assertRaises(errors.ReadOnlyError, vf.join, 'base')
1594.2.24 by Robert Collins
Make use of the transaction finalisation warning support to implement in-knit caching.
805
        self.assertRaises(errors.ReadOnlyError, vf.clone_text, 'base', 'bar', ['foo'])
1666.1.6 by Robert Collins
Make knit the default format.
806
    
807
    def test_get_sha1(self):
808
        # check the sha1 data is available
809
        vf = self.get_file()
810
        # a simple file
811
        vf.add_lines('a', [], ['a\n'])
812
        # the same file, different metadata
813
        vf.add_lines('b', ['a'], ['a\n'])
814
        # a file differing only in last newline.
815
        vf.add_lines('c', [], ['a'])
816
        self.assertEqual(
817
            '3f786850e387550fdab836ed7e6dc881de23001b', vf.get_sha1('a'))
818
        self.assertEqual(
819
            '3f786850e387550fdab836ed7e6dc881de23001b', vf.get_sha1('b'))
820
        self.assertEqual(
821
            '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8', vf.get_sha1('c'))
2520.4.89 by Aaron Bentley
Add get_sha1s to weaves
822
823
        self.assertEqual(['3f786850e387550fdab836ed7e6dc881de23001b',
824
                          '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8',
825
                          '3f786850e387550fdab836ed7e6dc881de23001b'],
826
                          vf.get_sha1s(['a', 'c', 'b']))
1594.2.9 by Robert Collins
Teach Knit repositories how to handle ghosts without corrupting at all.
827
        
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
828
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.
829
class TestWeave(TestCaseWithTransport, VersionedFileTestMixIn):
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
830
831
    def get_file(self, name='foo'):
1563.2.25 by Robert Collins
Merge in upstream.
832
        return WeaveFile(name, get_transport(self.get_url('.')), create=True)
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
833
1563.2.6 by Robert Collins
Start check tests for knits (pending), and remove dead code.
834
    def get_file_corrupted_text(self):
1563.2.25 by Robert Collins
Merge in upstream.
835
        w = WeaveFile('foo', get_transport(self.get_url('.')), create=True)
1563.2.13 by Robert Collins
InterVersionedFile implemented.
836
        w.add_lines('v1', [], ['hello\n'])
837
        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.
838
        
839
        # We are going to invasively corrupt the text
840
        # Make sure the internals of weave are the same
841
        self.assertEqual([('{', 0)
842
                        , 'hello\n'
843
                        , ('}', None)
844
                        , ('{', 1)
845
                        , 'there\n'
846
                        , ('}', None)
847
                        ], w._weave)
848
        
849
        self.assertEqual(['f572d396fae9206628714fb2ce00f72e94f2258f'
850
                        , '90f265c6e75f1c8f9ab76dcf85528352c5f215ef'
851
                        ], w._sha1s)
852
        w.check()
853
        
854
        # Corrupted
855
        w._weave[4] = 'There\n'
856
        return w
857
858
    def get_file_corrupted_checksum(self):
859
        w = self.get_file_corrupted_text()
860
        # Corrected
861
        w._weave[4] = 'there\n'
862
        self.assertEqual('hello\nthere\n', w.get_text('v2'))
863
        
864
        #Invalid checksum, first digit changed
865
        w._sha1s[1] =  'f0f265c6e75f1c8f9ab76dcf85528352c5f215ef'
866
        return w
867
1666.1.6 by Robert Collins
Make knit the default format.
868
    def reopen_file(self, name='foo', create=False):
869
        return WeaveFile(name, get_transport(self.get_url('.')), create=create)
1563.2.9 by Robert Collins
Update versionedfile api tests to ensure that data is available after every operation.
870
1563.2.25 by Robert Collins
Merge in upstream.
871
    def test_no_implicit_create(self):
872
        self.assertRaises(errors.NoSuchFile,
873
                          WeaveFile,
874
                          'foo',
875
                          get_transport(self.get_url('.')))
876
1594.2.23 by Robert Collins
Test versioned file storage handling of clean/dirty status for accessed versioned files.
877
    def get_factory(self):
878
        return WeaveFile
879
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
880
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.
881
class TestKnit(TestCaseWithTransport, VersionedFileTestMixIn):
1563.2.4 by Robert Collins
First cut at including the knit implementation of versioned_file.
882
883
    def get_file(self, name='foo'):
1563.2.16 by Robert Collins
Change WeaveStore into VersionedFileStore and make its versoined file class parameterisable.
884
        return KnitVersionedFile(name, get_transport(self.get_url('.')),
1563.2.25 by Robert Collins
Merge in upstream.
885
                                 delta=True, create=True)
1563.2.6 by Robert Collins
Start check tests for knits (pending), and remove dead code.
886
1594.2.23 by Robert Collins
Test versioned file storage handling of clean/dirty status for accessed versioned files.
887
    def get_factory(self):
888
        return KnitVersionedFile
889
1563.2.6 by Robert Collins
Start check tests for knits (pending), and remove dead code.
890
    def get_file_corrupted_text(self):
891
        knit = self.get_file()
892
        knit.add_lines('v1', [], ['hello\n'])
893
        knit.add_lines('v2', ['v1'], ['hello\n', 'there\n'])
894
        return knit
1563.2.9 by Robert Collins
Update versionedfile api tests to ensure that data is available after every operation.
895
1666.1.6 by Robert Collins
Make knit the default format.
896
    def reopen_file(self, name='foo', create=False):
897
        return KnitVersionedFile(name, get_transport(self.get_url('.')),
898
            delta=True,
899
            create=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.
900
901
    def test_detection(self):
1563.2.19 by Robert Collins
stub out a check for knits.
902
        knit = self.get_file()
903
        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.
904
1563.2.25 by Robert Collins
Merge in upstream.
905
    def test_no_implicit_create(self):
906
        self.assertRaises(errors.NoSuchFile,
907
                          KnitVersionedFile,
908
                          'foo',
909
                          get_transport(self.get_url('.')))
910
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.
911
912
class InterString(versionedfile.InterVersionedFile):
913
    """An inter-versionedfile optimised code path for strings.
914
915
    This is for use during testing where we use strings as versionedfiles
916
    so that none of the default regsitered interversionedfile classes will
917
    match - which lets us test the match logic.
918
    """
919
920
    @staticmethod
921
    def is_compatible(source, target):
922
        """InterString is compatible with strings-as-versionedfiles."""
923
        return isinstance(source, str) and isinstance(target, str)
924
925
926
# TODO this and the InterRepository core logic should be consolidatable
927
# if we make the registry a separate class though we still need to 
928
# test the behaviour in the active registry to catch failure-to-handle-
929
# stange-objects
930
class TestInterVersionedFile(TestCaseWithTransport):
931
932
    def test_get_default_inter_versionedfile(self):
933
        # test that the InterVersionedFile.get(a, b) probes
934
        # for a class where is_compatible(a, b) returns
935
        # true and returns a default interversionedfile otherwise.
936
        # This also tests that the default registered optimised interversionedfile
937
        # classes do not barf inappropriately when a surprising versionedfile type
938
        # is handed to them.
939
        dummy_a = "VersionedFile 1."
940
        dummy_b = "VersionedFile 2."
941
        self.assertGetsDefaultInterVersionedFile(dummy_a, dummy_b)
942
943
    def assertGetsDefaultInterVersionedFile(self, a, b):
944
        """Asserts that InterVersionedFile.get(a, b) -> the default."""
945
        inter = versionedfile.InterVersionedFile.get(a, b)
946
        self.assertEqual(versionedfile.InterVersionedFile,
947
                         inter.__class__)
948
        self.assertEqual(a, inter.source)
949
        self.assertEqual(b, inter.target)
950
951
    def test_register_inter_versionedfile_class(self):
952
        # test that a optimised code path provider - a
953
        # InterVersionedFile subclass can be registered and unregistered
954
        # and that it is correctly selected when given a versionedfile
955
        # pair that it returns true on for the is_compatible static method
956
        # check
957
        dummy_a = "VersionedFile 1."
958
        dummy_b = "VersionedFile 2."
959
        versionedfile.InterVersionedFile.register_optimiser(InterString)
960
        try:
961
            # we should get the default for something InterString returns False
962
            # to
963
            self.assertFalse(InterString.is_compatible(dummy_a, None))
964
            self.assertGetsDefaultInterVersionedFile(dummy_a, None)
965
            # and we should get an InterString for a pair it 'likes'
966
            self.assertTrue(InterString.is_compatible(dummy_a, dummy_b))
967
            inter = versionedfile.InterVersionedFile.get(dummy_a, dummy_b)
968
            self.assertEqual(InterString, inter.__class__)
969
            self.assertEqual(dummy_a, inter.source)
970
            self.assertEqual(dummy_b, inter.target)
971
        finally:
972
            versionedfile.InterVersionedFile.unregister_optimiser(InterString)
973
        # now we should get the default InterVersionedFile object again.
974
        self.assertGetsDefaultInterVersionedFile(dummy_a, dummy_b)
1666.1.1 by Robert Collins
Add trivial http-using test for versioned files.
975
976
977
class TestReadonlyHttpMixin(object):
978
979
    def test_readonly_http_works(self):
980
        # we should be able to read from http with a versioned file.
981
        vf = self.get_file()
1666.1.6 by Robert Collins
Make knit the default format.
982
        # try an empty file access
983
        readonly_vf = self.get_factory()('foo', get_transport(self.get_readonly_url('.')))
984
        self.assertEqual([], readonly_vf.versions())
985
        # now with feeling.
1666.1.1 by Robert Collins
Add trivial http-using test for versioned files.
986
        vf.add_lines('1', [], ['a\n'])
987
        vf.add_lines('2', ['1'], ['b\n', 'a\n'])
988
        readonly_vf = self.get_factory()('foo', get_transport(self.get_readonly_url('.')))
1666.1.6 by Robert Collins
Make knit the default format.
989
        self.assertEqual(['1', '2'], vf.versions())
1666.1.1 by Robert Collins
Add trivial http-using test for versioned files.
990
        for version in readonly_vf.versions():
991
            readonly_vf.get_lines(version)
992
993
994
class TestWeaveHTTP(TestCaseWithWebserver, TestReadonlyHttpMixin):
995
996
    def get_file(self):
997
        return WeaveFile('foo', get_transport(self.get_url('.')), create=True)
998
999
    def get_factory(self):
1000
        return WeaveFile
1001
1002
1003
class TestKnitHTTP(TestCaseWithWebserver, TestReadonlyHttpMixin):
1004
1005
    def get_file(self):
1006
        return KnitVersionedFile('foo', get_transport(self.get_url('.')),
1007
                                 delta=True, create=True)
1008
1009
    def get_factory(self):
1010
        return KnitVersionedFile
1664.2.9 by Aaron Bentley
Ported weave merge test to versionedfile
1011
1012
1013
class MergeCasesMixin(object):
1014
1015
    def doMerge(self, base, a, b, mp):
1016
        from cStringIO import StringIO
1017
        from textwrap import dedent
1018
1019
        def addcrlf(x):
1020
            return x + '\n'
1021
        
1022
        w = self.get_file()
1023
        w.add_lines('text0', [], map(addcrlf, base))
1024
        w.add_lines('text1', ['text0'], map(addcrlf, a))
1025
        w.add_lines('text2', ['text0'], map(addcrlf, b))
1026
1027
        self.log_contents(w)
1028
1029
        self.log('merge plan:')
1030
        p = list(w.plan_merge('text1', 'text2'))
1031
        for state, line in p:
1032
            if line:
1033
                self.log('%12s | %s' % (state, line[:-1]))
1034
1035
        self.log('merge:')
1036
        mt = StringIO()
1037
        mt.writelines(w.weave_merge(p))
1038
        mt.seek(0)
1039
        self.log(mt.getvalue())
1040
1041
        mp = map(addcrlf, mp)
1042
        self.assertEqual(mt.readlines(), mp)
1043
        
1044
        
1045
    def testOneInsert(self):
1046
        self.doMerge([],
1047
                     ['aa'],
1048
                     [],
1049
                     ['aa'])
1050
1051
    def testSeparateInserts(self):
1052
        self.doMerge(['aaa', 'bbb', 'ccc'],
1053
                     ['aaa', 'xxx', 'bbb', 'ccc'],
1054
                     ['aaa', 'bbb', 'yyy', 'ccc'],
1055
                     ['aaa', 'xxx', 'bbb', 'yyy', 'ccc'])
1056
1057
    def testSameInsert(self):
1058
        self.doMerge(['aaa', 'bbb', 'ccc'],
1059
                     ['aaa', 'xxx', 'bbb', 'ccc'],
1060
                     ['aaa', 'xxx', 'bbb', 'yyy', 'ccc'],
1061
                     ['aaa', 'xxx', 'bbb', 'yyy', 'ccc'])
1062
    overlappedInsertExpected = ['aaa', 'xxx', 'yyy', 'bbb']
1063
    def testOverlappedInsert(self):
1064
        self.doMerge(['aaa', 'bbb'],
1065
                     ['aaa', 'xxx', 'yyy', 'bbb'],
1066
                     ['aaa', 'xxx', 'bbb'], self.overlappedInsertExpected)
1067
1068
        # really it ought to reduce this to 
1069
        # ['aaa', 'xxx', 'yyy', 'bbb']
1070
1071
1072
    def testClashReplace(self):
1073
        self.doMerge(['aaa'],
1074
                     ['xxx'],
1075
                     ['yyy', 'zzz'],
1076
                     ['<<<<<<< ', 'xxx', '=======', 'yyy', 'zzz', 
1077
                      '>>>>>>> '])
1078
1079
    def testNonClashInsert1(self):
1080
        self.doMerge(['aaa'],
1081
                     ['xxx', 'aaa'],
1082
                     ['yyy', 'zzz'],
1083
                     ['<<<<<<< ', 'xxx', 'aaa', '=======', 'yyy', 'zzz', 
1084
                      '>>>>>>> '])
1085
1086
    def testNonClashInsert2(self):
1087
        self.doMerge(['aaa'],
1088
                     ['aaa'],
1089
                     ['yyy', 'zzz'],
1090
                     ['yyy', 'zzz'])
1091
1092
1093
    def testDeleteAndModify(self):
1094
        """Clashing delete and modification.
1095
1096
        If one side modifies a region and the other deletes it then
1097
        there should be a conflict with one side blank.
1098
        """
1099
1100
        #######################################
1101
        # skippd, not working yet
1102
        return
1103
        
1104
        self.doMerge(['aaa', 'bbb', 'ccc'],
1105
                     ['aaa', 'ddd', 'ccc'],
1106
                     ['aaa', 'ccc'],
1107
                     ['<<<<<<<< ', 'aaa', '=======', '>>>>>>> ', 'ccc'])
1108
1109
    def _test_merge_from_strings(self, base, a, b, expected):
1110
        w = self.get_file()
1111
        w.add_lines('text0', [], base.splitlines(True))
1112
        w.add_lines('text1', ['text0'], a.splitlines(True))
1113
        w.add_lines('text2', ['text0'], b.splitlines(True))
1114
        self.log('merge plan:')
1115
        p = list(w.plan_merge('text1', 'text2'))
1116
        for state, line in p:
1117
            if line:
1118
                self.log('%12s | %s' % (state, line[:-1]))
1119
        self.log('merge result:')
1120
        result_text = ''.join(w.weave_merge(p))
1121
        self.log(result_text)
1122
        self.assertEqualDiff(result_text, expected)
1123
1124
    def test_weave_merge_conflicts(self):
1125
        # does weave merge properly handle plans that end with unchanged?
1126
        result = ''.join(self.get_file().weave_merge([('new-a', 'hello\n')]))
1127
        self.assertEqual(result, 'hello\n')
1128
1129
    def test_deletion_extended(self):
1130
        """One side deletes, the other deletes more.
1131
        """
1132
        base = """\
1133
            line 1
1134
            line 2
1135
            line 3
1136
            """
1137
        a = """\
1138
            line 1
1139
            line 2
1140
            """
1141
        b = """\
1142
            line 1
1143
            """
1144
        result = """\
1145
            line 1
1146
            """
1147
        self._test_merge_from_strings(base, a, b, result)
1148
1149
    def test_deletion_overlap(self):
1150
        """Delete overlapping regions with no other conflict.
1151
1152
        Arguably it'd be better to treat these as agreement, rather than 
1153
        conflict, but for now conflict is safer.
1154
        """
1155
        base = """\
1156
            start context
1157
            int a() {}
1158
            int b() {}
1159
            int c() {}
1160
            end context
1161
            """
1162
        a = """\
1163
            start context
1164
            int a() {}
1165
            end context
1166
            """
1167
        b = """\
1168
            start context
1169
            int c() {}
1170
            end context
1171
            """
1172
        result = """\
1173
            start context
1174
<<<<<<< 
1175
            int a() {}
1176
=======
1177
            int c() {}
1178
>>>>>>> 
1179
            end context
1180
            """
1181
        self._test_merge_from_strings(base, a, b, result)
1182
1183
    def test_agreement_deletion(self):
1184
        """Agree to delete some lines, without conflicts."""
1185
        base = """\
1186
            start context
1187
            base line 1
1188
            base line 2
1189
            end context
1190
            """
1191
        a = """\
1192
            start context
1193
            base line 1
1194
            end context
1195
            """
1196
        b = """\
1197
            start context
1198
            base line 1
1199
            end context
1200
            """
1201
        result = """\
1202
            start context
1203
            base line 1
1204
            end context
1205
            """
1206
        self._test_merge_from_strings(base, a, b, result)
1207
1208
    def test_sync_on_deletion(self):
1209
        """Specific case of merge where we can synchronize incorrectly.
1210
        
1211
        A previous version of the weave merge concluded that the two versions
1212
        agreed on deleting line 2, and this could be a synchronization point.
1213
        Line 1 was then considered in isolation, and thought to be deleted on 
1214
        both sides.
1215
1216
        It's better to consider the whole thing as a disagreement region.
1217
        """
1218
        base = """\
1219
            start context
1220
            base line 1
1221
            base line 2
1222
            end context
1223
            """
1224
        a = """\
1225
            start context
1226
            base line 1
1227
            a's replacement line 2
1228
            end context
1229
            """
1230
        b = """\
1231
            start context
1232
            b replaces
1233
            both lines
1234
            end context
1235
            """
1236
        result = """\
1237
            start context
1238
<<<<<<< 
1239
            base line 1
1240
            a's replacement line 2
1241
=======
1242
            b replaces
1243
            both lines
1244
>>>>>>> 
1245
            end context
1246
            """
1247
        self._test_merge_from_strings(base, a, b, result)
1248
1249
1250
class TestKnitMerge(TestCaseWithTransport, MergeCasesMixin):
1251
1252
    def get_file(self, name='foo'):
1253
        return KnitVersionedFile(name, get_transport(self.get_url('.')),
1254
                                 delta=True, create=True)
1255
1256
    def log_contents(self, w):
1257
        pass
1258
1259
1260
class TestWeaveMerge(TestCaseWithTransport, MergeCasesMixin):
1261
1262
    def get_file(self, name='foo'):
1263
        return WeaveFile(name, get_transport(self.get_url('.')), create=True)
1264
1265
    def log_contents(self, w):
1266
        self.log('weave is:')
1267
        tmpf = StringIO()
1268
        write_weave(w, tmpf)
1269
        self.log(tmpf.getvalue())
1270
1271
    overlappedInsertExpected = ['aaa', '<<<<<<< ', 'xxx', 'yyy', '=======', 
1272
                                'xxx', '>>>>>>> ', 'bbb']