/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testreweave.py

  • Committer: Michael Ellerman
  • Date: 2005-10-26 10:03:47 UTC
  • mfrom: (1185.16.116)
  • mto: (1185.16.126)
  • mto: This revision was merged to the branch mainline in revision 1488.
  • Revision ID: michael@ellerman.id.au-20051026100347-bb0b2bd42f7953f2
MergeĀ mainline.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 by Canonical Ltd
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
 
 
17
"""Test reweave code.
 
18
 
 
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 
 
21
 
 
22
 - versions recorded in only one file
 
23
 
 
24
 - versions with different (but not contradictory) lists of parent 
 
25
   revisions
 
26
 
 
27
It is an error if either of these conditions occur:
 
28
 
 
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 
 
32
"""
 
33
 
 
34
import os
 
35
import sys
 
36
 
 
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
 
41
 
 
42
class TestReweave(TestCaseInTempDir):
 
43
 
 
44
    def test_reweave_add_parents(self):
 
45
        """Reweave inserting new parents
 
46
        
 
47
        The new version must have the right parent list and must identify
 
48
        lines originating in another parent.
 
49
        """
 
50
        w1 = Weave('w1')
 
51
        w2 = Weave('w2')
 
52
        w1.add('v-1', [], ['line 1\n'])
 
53
        w2.add('v-2', [], ['line 2\n'])
 
54
        w1.add('v-3', ['v-1'], ['line 1\n'])
 
55
        w2.add('v-3', ['v-2'], ['line 1\n'])
 
56
        w3 = reweave(w1, w2)
 
57
        self.assertEqual(sorted(w3.names()),
 
58
                         'v-1 v-2 v-3'.split())
 
59
        self.assertEqualDiff(w3.get_text('v-3'),
 
60
                'line 1\n')
 
61
        self.assertEqual(sorted(w3.parent_names('v-3')),
 
62
                ['v-1', 'v-2'])
 
63
        ann = list(w3.annotate('v-3'))
 
64
        self.assertEqual(len(ann), 1)
 
65
        self.assertEqual(w3.idx_to_name(ann[0][0]), 'v-1')
 
66
        self.assertEqual(ann[0][1], 'line 1\n')
 
67
        
 
68
    def build_weave1(self):
 
69
        weave1 = Weave()
 
70
        self.lines1 = ['hello\n']
 
71
        self.lines3 = ['hello\n', 'cruel\n', 'world\n']
 
72
        weave1.add('v1', [], self.lines1)
 
73
        weave1.add('v2', [0], ['hello\n', 'world\n'])
 
74
        weave1.add('v3', [1], self.lines3)
 
75
        return weave1
 
76
        
 
77
    def test_reweave_with_empty(self):
 
78
        """Reweave adding empty weave"""
 
79
        wb = Weave()
 
80
        w1 = self.build_weave1()
 
81
        wr = reweave(w1, wb)
 
82
        eq = self.assertEquals
 
83
        eq(sorted(wr.iter_names()), ['v1', 'v2', 'v3'])
 
84
        eq(wr.get_lines('v3'), ['hello\n', 'cruel\n', 'world\n'])
 
85
        self.assertEquals(wr, w1)
 
86
 
 
87
    def test_join_with_ghosts_raises_parent_mismatch(self):
 
88
        """Join weave traps parent mismatch"""
 
89
        wa = self.build_weave1()
 
90
        wb = Weave()
 
91
        wb.add('x1', [], ['line from x1\n'])
 
92
        wb.add('v1', [], ['hello\n'])
 
93
        wb.add('v2', ['v1', 'x1'], ['hello\n', 'world\n'])
 
94
        self.assertRaises(WeaveParentMismatch, wa.join, wb)
 
95
 
 
96
    def test_reweave_with_ghosts(self):
 
97
        """Join that inserts parents of an existing revision.
 
98
 
 
99
        This can happen when merging from another branch who
 
100
        knows about revisions the destination does not.  In 
 
101
        this test the second weave knows of an additional parent of 
 
102
        v2.  Any revisions which are in common still have to have the 
 
103
        same text.
 
104
        """
 
105
        w1 = self.build_weave1()
 
106
        wa = w1.copy()
 
107
        wb = Weave()
 
108
        wb.add('x1', [], ['line from x1\n'])
 
109
        wb.add('v1', [], ['hello\n'])
 
110
        wb.add('v2', ['v1', 'x1'], ['hello\n', 'world\n'])
 
111
        wc = reweave(wa, wb)
 
112
        eq = self.assertEquals
 
113
        eq(sorted(wc.iter_names()), ['v1', 'v2', 'v3', 'x1',])
 
114
        eq(wc.get_text('x1'), 'line from x1\n')
 
115
        eq(wc.get_lines('v2'), ['hello\n', 'world\n'])
 
116
        eq(wc.parent_names('v2'), ['v1', 'x1'])
 
117
        w1.reweave(wb)
 
118
        self.assertEquals(wc, w1)