58
60
#self.assertTrue(f4.has_version('r0'))
59
61
#self.assertFalse(f4.has_version('r1'))
63
def test_gets_expected_inter_worker(self):
64
source = self.get_source()
65
target = self.get_target()
66
inter = versionedfile.InterVersionedFile.get(source, target)
67
self.assertTrue(isinstance(inter, self.interversionedfile_class))
69
def test_join_add_parents(self):
70
"""Join inserting new parents into existing versions
72
The new version must have the right parent list and must identify
73
lines originating in another parent.
75
w1 = self.get_target('w1')
76
w2 = self.get_source('w2')
77
w1.add_lines('v-1', [], ['line 1\n'])
78
w2.add_lines('v-2', [], ['line 2\n'])
79
w1.add_lines('v-3', ['v-1'], ['line 1\n'])
80
w2.add_lines('v-3', ['v-2'], ['line 1\n'])
82
self.assertEqual(sorted(w1.versions()),
83
'v-1 v-2 v-3'.split())
84
self.assertEqualDiff(w1.get_text('v-3'),
86
self.assertEqual(sorted(w1.get_parents('v-3')),
88
ann = list(w1.annotate('v-3'))
89
self.assertEqual(len(ann), 1)
90
self.assertEqual(ann[0][0], 'v-1')
91
self.assertEqual(ann[0][1], 'line 1\n')
93
def build_weave1(self):
94
weave1 = self.get_source()
95
self.lines1 = ['hello\n']
96
self.lines3 = ['hello\n', 'cruel\n', 'world\n']
97
weave1.add_lines('v1', [], self.lines1)
98
weave1.add_lines('v2', ['v1'], ['hello\n', 'world\n'])
99
weave1.add_lines('v3', ['v2'], self.lines3)
102
def test_join_with_empty(self):
103
"""Reweave adding empty weave"""
104
wb = self.get_target()
105
w1 = self.build_weave1()
107
self.verify_weave1(w1)
109
def verify_weave1(self, w1):
110
self.assertEqual(sorted(w1.versions()), ['v1', 'v2', 'v3'])
111
self.assertEqual(w1.get_lines('v1'), ['hello\n'])
112
self.assertEqual([], w1.get_parents('v1'))
113
self.assertEqual(w1.get_lines('v2'), ['hello\n', 'world\n'])
114
self.assertEqual(['v1'], w1.get_parents('v2'))
115
self.assertEqual(w1.get_lines('v3'), ['hello\n', 'cruel\n', 'world\n'])
116
self.assertEqual(['v2'], w1.get_parents('v3'))
118
def test_join_with_ghosts_merges_parents(self):
119
"""Join combined parent lists"""
120
wa = self.build_weave1()
121
wb = self.get_target()
122
wb.add_lines('x1', [], ['line from x1\n'])
123
wb.add_lines('v1', [], ['hello\n'])
124
wb.add_lines('v2', ['v1', 'x1'], ['hello\n', 'world\n'])
126
self.assertEqual(['v1','x1'], wa.get_parents('v2'))
128
def test_join_with_ghosts(self):
129
"""Join that inserts parents of an existing revision.
131
This can happen when merging from another branch who
132
knows about revisions the destination does not. In
133
this test the second weave knows of an additional parent of
134
v2. Any revisions which are in common still have to have the
137
w1 = self.build_weave1()
138
wb = self.get_target()
139
wb.add_lines('x1', [], ['line from x1\n'])
140
wb.add_lines('v1', [], ['hello\n'])
141
wb.add_lines('v2', ['v1', 'x1'], ['hello\n', 'world\n'])
143
eq = self.assertEquals
144
eq(sorted(w1.versions()), ['v1', 'v2', 'v3', 'x1',])
145
eq(w1.get_text('x1'), 'line from x1\n')
146
eq(w1.get_lines('v2'), ['hello\n', 'world\n'])
147
eq(w1.get_parents('v2'), ['v1', 'x1'])
149
def build_source_weave(self, name, *pattern):
150
w = self.get_source(name)
151
for version, parents in pattern:
152
w.add_lines(version, parents, [])
155
def build_target_weave(self, name, *pattern):
156
w = self.get_target(name)
157
for version, parents in pattern:
158
w.add_lines(version, parents, [])
161
def test_join_reorder(self):
162
"""Reweave requiring reordering of versions.
164
Weaves must be stored such that parents come before children. When
165
reweaving, we may add new parents to some children, but it is required
166
that there must be *some* valid order that can be found, otherwise the
167
ancestries are contradictory. (For the specific case of inserting
168
ghost revisions there will be no disagreement, only partial knowledge
171
Note that the weaves are only partially ordered: when there are two
172
versions where neither is an ancestor of the other the order in which
173
they occur is unconstrained. When we join those versions into
174
another weave, they may become more constrained and it may be
175
necessary to change their order.
177
One simple case of this is
182
We need to recognize that the final weave must show the ordering
183
a[], b[a], c[b]. The version that must be first in the result is
184
not first in either of the input weaves.
186
w1 = self.build_target_weave('1', ('c', []), ('a', []), ('b', ['a']))
187
w2 = self.build_source_weave('2', ('b', []), ('c', ['b']), ('a', []))
189
self.assertEqual([], w1.get_parents('a'))
190
self.assertEqual(['a'], w1.get_parents('b'))
191
self.assertEqual(['b'], w1.get_parents('c'))