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.selftest import TestCaseInTempDir
38
from bzrlib.weave import Weave, reweave
39
from bzrlib.weavefile import read_weave
40
from bzrlib.errors import WeaveParentMismatch
42
class TestReweave(TestCaseInTempDir):
44
def test_reweave_add_parents(self):
47
w1.add('v-1', [], ['line from 1\n'])
48
w2.add('v-2', [], ['line from 2\n'])
49
w1.add('v-3', ['v-1'], ['final line\n'])
50
w2.add('v-3', ['v-2'], ['final line\n'])
52
self.assertEqual(sorted(w3.names()),
53
'v-1 v-2 v-3'.split())
54
self.assertEqualDiff(w3.get_text('v-3'),
57
def build_weave1(self):
59
self.lines1 = ['hello\n']
60
self.lines3 = ['hello\n', 'cruel\n', 'world\n']
61
weave1.add('v1', [], self.lines1)
62
weave1.add('v2', [0], ['hello\n', 'world\n'])
63
weave1.add('v3', [1], self.lines3)
66
def test_reweave_with_empty(self):
68
w1 = self.build_weave1()
70
eq = self.assertEquals
71
eq(sorted(wr.iter_names()), ['v1', 'v2', 'v3'])
72
eq(wr.get_lines('v3'), ['hello\n', 'cruel\n', 'world\n'])
73
self.assertEquals(wr, w1)
75
def test_join_with_ghosts_raises_parent_mismatch(self):
76
wa = self.build_weave1()
78
wb.add('x1', [], ['line from x1\n'])
79
wb.add('v1', [], ['hello\n'])
80
wb.add('v2', ['v1', 'x1'], ['hello\n', 'world\n'])
81
self.assertRaises(WeaveParentMismatch, wa.join, wb)
83
def test_reweave_with_ghosts(self):
84
"""Join that inserts parents of an existing revision.
86
This can happen when merging from another branch who
87
knows about revisions the destination does not. In
88
this test the second weave knows of an additional parent of
89
v2. Any revisions which are in common still have to have the
91
w1 = self.build_weave1()
94
wb.add('x1', [], ['line from x1\n'])
95
wb.add('v1', [], ['hello\n'])
96
wb.add('v2', ['v1', 'x1'], ['hello\n', 'world\n'])
98
eq = self.assertEquals
99
eq(sorted(wc.iter_names()), ['v1', 'v2', 'v3', 'x1',])
100
eq(wc.get_text('x1'), 'line from x1\n')
101
eq(wc.get_lines('v2'), ['hello\n', 'world\n'])
102
eq(wc.parent_names('v2'), ['v1', 'x1'])
104
self.assertEquals(wc, w1)