1
# Copyright (C) 2005 by Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
Reweave takes two weaves containing a partial view of history and combines
20
them into a single weave containing all the information. This can include
22
- versions recorded in only one file
24
- versions with different (but not contradictory) lists of parent
27
It is an error if either of these conditions occur:
29
- contradictory ancestry graphs, e.g.
30
- v1 is an ancestor of v2 in one weave, and vice versa in the other
31
- different text for any version
37
from bzrlib.tests import TestCase
38
from bzrlib.weave import Weave, reweave
39
from bzrlib.errors import WeaveParentMismatch
41
class TestReweave(TestCase):
43
def test_reweave_add_parents(self):
44
"""Reweave inserting new parents
46
The new version must have the right parent list and must identify
47
lines originating in another parent.
51
w1.add('v-1', [], ['line 1\n'])
52
w2.add('v-2', [], ['line 2\n'])
53
w1.add('v-3', ['v-1'], ['line 1\n'])
54
w2.add('v-3', ['v-2'], ['line 1\n'])
56
self.assertEqual(sorted(w3.names()),
57
'v-1 v-2 v-3'.split())
58
self.assertEqualDiff(w3.get_text('v-3'),
60
self.assertEqual(sorted(w3.parent_names('v-3')),
62
ann = list(w3.annotate('v-3'))
63
self.assertEqual(len(ann), 1)
64
self.assertEqual(w3.idx_to_name(ann[0][0]), 'v-1')
65
self.assertEqual(ann[0][1], 'line 1\n')
67
def build_weave1(self):
69
self.lines1 = ['hello\n']
70
self.lines3 = ['hello\n', 'cruel\n', 'world\n']
71
weave1.add('v1', [], self.lines1)
72
weave1.add('v2', [0], ['hello\n', 'world\n'])
73
weave1.add('v3', [1], self.lines3)
76
def test_reweave_with_empty(self):
77
"""Reweave adding empty weave"""
79
w1 = self.build_weave1()
81
eq = self.assertEquals
82
eq(sorted(wr.iter_names()), ['v1', 'v2', 'v3'])
83
eq(wr.get_lines('v3'), ['hello\n', 'cruel\n', 'world\n'])
84
self.assertEquals(wr, w1)
86
def test_join_with_ghosts_raises_parent_mismatch(self):
87
"""Join weave traps parent mismatch"""
88
wa = self.build_weave1()
90
wb.add('x1', [], ['line from x1\n'])
91
wb.add('v1', [], ['hello\n'])
92
wb.add('v2', ['v1', 'x1'], ['hello\n', 'world\n'])
93
self.assertRaises(WeaveParentMismatch, wa.join, wb)
95
def test_reweave_with_ghosts(self):
96
"""Join that inserts parents of an existing revision.
98
This can happen when merging from another branch who
99
knows about revisions the destination does not. In
100
this test the second weave knows of an additional parent of
101
v2. Any revisions which are in common still have to have the
104
w1 = self.build_weave1()
107
wb.add('x1', [], ['line from x1\n'])
108
wb.add('v1', [], ['hello\n'])
109
wb.add('v2', ['v1', 'x1'], ['hello\n', 'world\n'])
111
eq = self.assertEquals
112
eq(sorted(wc.iter_names()), ['v1', 'v2', 'v3', 'x1',])
113
eq(wc.get_text('x1'), 'line from x1\n')
114
eq(wc.get_lines('v2'), ['hello\n', 'world\n'])
115
eq(wc.parent_names('v2'), ['v1', 'x1'])
117
self.assertEquals(wc, w1)
119
def build_empty_weave(self, *pattern):
121
for version, parents in pattern:
122
w.add(version, parents, [])
125
def test_reweave_reorder(self):
126
"""Reweave requiring reordering of versions.
128
Weaves must be stored such that parents come before children. When
129
reweaving, we may add new parents to some children, but it is required
130
that there must be *some* valid order that can be found, otherwise the
131
ancestries are contradictory. (For the specific case of inserting
132
ghost revisions there will be no disagreement, only partial knowledge
135
Note that the weaves are only partially ordered: when there are two
136
versions where neither is an ancestor of the other the order in which
137
they occur is unconstrained. When we reweave those versions into
138
another weave, they may become more constrained and it may be
139
necessary to change their order.
141
One simple case of this is
146
We need to recognize that the final weave must show the ordering
147
a[], b[a], c[b]. The version that must be first in the result is
148
not first in either of the input weaves.
150
w1 = self.build_empty_weave(('c', []), ('a', []), ('b', ['a']))
151
w2 = self.build_empty_weave(('b', []), ('c', ['b']), ('a', []))