54
54
self.assertRaises(errors.RevisionNotPresent,
55
55
f2.join, f1, version_ids=['r3'])
57
#f3 = self.get_file('1')
58
#f3.add_lines('r0', ['a\n', 'b\n'], [])
59
#f3.add_lines('r1', ['c\n', 'b\n'], ['r0'])
60
#f4 = self.get_file('2')
62
#self.assertTrue(f4.has_version('r0'))
63
#self.assertFalse(f4.has_version('r1'))
65
57
def test_gets_expected_inter_worker(self):
66
58
source = self.get_source()
67
59
target = self.get_target()
87
79
self.assertTrue(target.has_version('namedleft'))
88
80
self.assertTrue(target.has_version('namedright'))
90
def test_join_add_parents(self):
91
"""Join inserting new parents into existing versions
93
The new version must have the right parent list and must identify
94
lines originating in another parent.
82
def test_join_different_parents_existing_version(self):
83
"""This may either ignore or error."""
96
84
w1 = self.get_target('w1')
97
85
w2 = self.get_source('w2')
98
86
w1.add_lines('v-1', [], ['line 1\n'])
99
87
w2.add_lines('v-2', [], ['line 2\n'])
100
88
w1.add_lines('v-3', ['v-1'], ['line 1\n'])
101
89
w2.add_lines('v-3', ['v-2'], ['line 1\n'])
92
except errors.WeaveParentMismatch:
93
# Acceptable behaviour:
103
95
self.assertEqual(sorted(w1.versions()),
104
96
'v-1 v-2 v-3'.split())
105
97
self.assertEqualDiff(w1.get_text('v-3'),
107
99
self.assertEqual(sorted(w1.get_parents('v-3')),
109
101
ann = list(w1.annotate('v-3'))
110
102
self.assertEqual(len(ann), 1)
111
103
self.assertEqual(ann[0][0], 'v-1')
149
141
self.assertEqual(['base'], t.get_parents('text'))
151
def test_join_with_ghosts_merges_parents(self):
152
"""Join combined parent lists"""
153
wa = self.build_weave1()
154
wb = self.get_target()
155
wb.add_lines('x1', [], ['line from x1\n'])
156
wb.add_lines('v1', [], ['hello\n'])
157
wb.add_lines('v2', ['v1', 'x1'], ['hello\n', 'world\n'])
159
self.assertEqual(['v1','x1'], wa.get_parents('v2'))
161
143
def test_join_with_ghosts(self):
162
144
"""Join that inserts parents of an existing revision.
164
This can happen when merging from another branch who
165
knows about revisions the destination does not. In
166
this test the second weave knows of an additional parent of
167
v2. Any revisions which are in common still have to have the
146
This can happen when merging from another branch who knows about
147
revisions the destination does not, and the destinations index is
148
incorrect because it was or is using a ghost-unaware format to
149
represent the index. In this test the second weave knows of an
150
additional parent of v2.
152
However v2 must not be changed because we consider indexes immutable:
153
instead a check or reconcile operation locally should pickup that v2 is
154
wrong and regenerate the index at a later time. So either this errors,
155
or leaves v2 unaltered.
170
157
w1 = self.build_weave1()
171
158
wb = self.get_target()
172
159
wb.add_lines('x1', [], ['line from x1\n'])
173
160
wb.add_lines('v1', [], ['hello\n'])
174
161
wb.add_lines('v2', ['v1', 'x1'], ['hello\n', 'world\n'])
176
eq = self.assertEquals
177
eq(sorted(w1.versions()), ['v1', 'v2', 'v3', 'x1',])
178
eq(w1.get_text('x1'), 'line from x1\n')
179
eq(w1.get_lines('v2'), ['hello\n', 'world\n'])
180
eq(w1.get_parents('v2'), ['v1', 'x1'])
164
except errors.WeaveParentMismatch:
165
# Acceptable behaviour:
167
self.assertEqual(['v1', 'v2', 'v3', 'x1',], sorted(w1.versions()))
168
self.assertEqual('line from x1\n', w1.get_text('x1'))
169
self.assertEqual(['hello\n', 'world\n'], w1.get_lines('v2'))
170
self.assertEqual(['v1'], w1.get_parents('v2'))
182
172
def test_join_with_ignore_missing_versions(self):
183
173
# test that ignore_missing=True makes a listed but absent version id
205
195
for version, parents in pattern:
206
196
w.add_lines(version, parents, [])
209
def test_join_reorder(self):
210
"""Reweave requiring reordering of versions.
212
Weaves must be stored such that parents come before children. When
213
reweaving, we may add new parents to some children, but it is required
214
that there must be *some* valid order that can be found, otherwise the
215
ancestries are contradictory. (For the specific case of inserting
216
ghost revisions there will be no disagreement, only partial knowledge
219
Note that the weaves are only partially ordered: when there are two
220
versions where neither is an ancestor of the other the order in which
221
they occur is unconstrained. When we join those versions into
222
another weave, they may become more constrained and it may be
223
necessary to change their order.
225
One simple case of this is
230
We need to recognize that the final weave must show the ordering
231
a[], b[a], c[b]. The version that must be first in the result is
232
not first in either of the input weaves.
234
w1 = self.build_target_weave('1', ('c', []), ('a', []), ('b', ['a']))
235
w2 = self.build_source_weave('2', ('b', []), ('c', ['b']), ('a', []))
237
self.assertEqual([], w1.get_parents('a'))
238
self.assertEqual(['a'], w1.get_parents('b'))
239
self.assertEqual(['b'], w1.get_parents('c'))
241
199
def test_joining_ghosts(self):
242
200
# some versioned file formats allow lines to be added with parent