194
197
"""Open the versioned file from disk again."""
195
198
raise NotImplementedError(self.reopen_file)
200
def test_join_add_parents(self):
201
"""Reweave inserting new parents
203
The new version must have the right parent list and must identify
204
lines originating in another parent.
206
w1 = self.get_file('w1')
207
w2 = self.get_file('w2')
208
w1.add_lines('v-1', [], ['line 1\n'])
209
w2.add_lines('v-2', [], ['line 2\n'])
210
w1.add_lines('v-3', ['v-1'], ['line 1\n'])
211
w2.add_lines('v-3', ['v-2'], ['line 1\n'])
213
self.assertEqual(sorted(w1.names()),
214
'v-1 v-2 v-3'.split())
215
self.assertEqualDiff(w1.get_text('v-3'),
217
self.assertEqual(sorted(w1.parent_names('v-3')),
219
ann = list(w1.annotate('v-3'))
220
self.assertEqual(len(ann), 1)
221
self.assertEqual(ann[0][0], 'v-1')
222
self.assertEqual(ann[0][1], 'line 1\n')
224
def build_weave1(self):
225
weave1 = self.get_file()
226
self.lines1 = ['hello\n']
227
self.lines3 = ['hello\n', 'cruel\n', 'world\n']
228
weave1.add_lines('v1', [], self.lines1)
229
weave1.add_lines('v2', ['v1'], ['hello\n', 'world\n'])
230
weave1.add_lines('v3', ['v2'], self.lines3)
233
def test_join_with_empty(self):
234
"""Reweave adding empty weave"""
235
wb = self.get_file('b')
236
w1 = self.build_weave1()
238
self.assertEqual(sorted(w1.iter_names()), ['v1', 'v2', 'v3'])
239
self.assertEqual(w1.get_lines('v1'), ['hello\n'])
240
self.assertEqual([], w1.get_parents('v1'))
241
self.assertEqual(w1.get_lines('v2'), ['hello\n', 'world\n'])
242
self.assertEqual(['v1'], w1.get_parents('v2'))
243
self.assertEqual(w1.get_lines('v3'), ['hello\n', 'cruel\n', 'world\n'])
244
self.assertEqual(['v2'], w1.get_parents('v3'))
246
def test_join_with_ghosts_raises_parent_mismatch(self):
247
"""Join combined parent lists"""
248
wa = self.build_weave1()
249
wb = self.get_file('b')
250
wb.add_lines('x1', [], ['line from x1\n'])
251
wb.add_lines('v1', [], ['hello\n'])
252
wb.add_lines('v2', ['v1', 'x1'], ['hello\n', 'world\n'])
254
self.assertEqual(['v1','x1'], wa.get_parents('v2'))
256
def test_join_with_ghosts(self):
257
"""Join that inserts parents of an existing revision.
259
This can happen when merging from another branch who
260
knows about revisions the destination does not. In
261
this test the second weave knows of an additional parent of
262
v2. Any revisions which are in common still have to have the
265
w1 = self.build_weave1()
266
wb = self.get_file('b')
267
wb.add_lines('x1', [], ['line from x1\n'])
268
wb.add_lines('v1', [], ['hello\n'])
269
wb.add_lines('v2', ['v1', 'x1'], ['hello\n', 'world\n'])
271
eq = self.assertEquals
272
eq(sorted(w1.iter_names()), ['v1', 'v2', 'v3', 'x1',])
273
eq(w1.get_text('x1'), 'line from x1\n')
274
eq(w1.get_lines('v2'), ['hello\n', 'world\n'])
275
eq(w1.parent_names('v2'), ['v1', 'x1'])
277
def build_empty_weave(self, name, *pattern):
278
w = self.get_file(name)
279
for version, parents in pattern:
280
w.add_lines(version, parents, [])
283
def test_join_reorder(self):
284
"""Reweave requiring reordering of versions.
286
Weaves must be stored such that parents come before children. When
287
reweaving, we may add new parents to some children, but it is required
288
that there must be *some* valid order that can be found, otherwise the
289
ancestries are contradictory. (For the specific case of inserting
290
ghost revisions there will be no disagreement, only partial knowledge
293
Note that the weaves are only partially ordered: when there are two
294
versions where neither is an ancestor of the other the order in which
295
they occur is unconstrained. When we join those versions into
296
another weave, they may become more constrained and it may be
297
necessary to change their order.
299
One simple case of this is
304
We need to recognize that the final weave must show the ordering
305
a[], b[a], c[b]. The version that must be first in the result is
306
not first in either of the input weaves.
308
w1 = self.build_empty_weave('1', ('c', []), ('a', []), ('b', ['a']))
309
w2 = self.build_empty_weave('2', ('b', []), ('c', ['b']), ('a', []))
311
self.assertEqual([], w1.get_parents('a'))
312
self.assertEqual(['a'], w1.get_parents('b'))
313
self.assertEqual(['b'], w1.get_parents('c'))
198
315
class TestWeave(TestCaseInTempDir, VersionedFileTestMixIn):