~bzr-pqm/bzr/bzr.dev

2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
1
# Copyright (C) 2006 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
"""Whitebox tests for annotate functionality."""
18
19
from cStringIO import StringIO
20
21
from bzrlib import (
22
    annotate,
23
    conflicts,
24
    errors,
25
    tests,
26
    trace,
27
    )
28
29
1551.9.19 by Aaron Bentley
Merge from bzr.dev
30
def annotation(text):
31
    return [tuple(l.split(' ', 1)) for l in text.splitlines(True)]
32
33
34
parent_1 = annotation("""\
35
rev1 a
36
rev2 b
37
rev3 c
38
rev4 d
39
rev5 e
40
""")
41
42
43
parent_2 = annotation("""\
44
rev1 a
45
rev3 c
46
rev4 d
47
rev6 f
48
rev7 e
49
rev8 h
50
""")
51
52
53
expected_2_1 = annotation("""\
54
rev1 a
55
blahblah b
56
rev3 c
57
rev4 d
58
rev7 e
59
""")
60
61
62
# a: in both, same value, kept
63
# b: in 1, kept
64
# c: in both, same value, kept
65
# d: in both, same value, kept
66
# e: 1 and 2 disagree, so it goes to blahblah
67
# f: in 2, but not in new, so ignored
68
# g: not in 1 or 2, so it goes to blahblah
69
# h: only in parent 2, so 2 gets it
70
expected_1_2_2 = annotation("""\
71
rev1 a
72
rev2 b
73
rev3 c
74
rev4 d
75
blahblah e
76
blahblah g
77
rev8 h
78
""")
79
80
81
new_1 = """\
82
a
83
b
84
c
85
d
86
e
87
""".splitlines(True)
88
89
90
new_2 = """\
91
a
92
b
93
c
94
d
95
e
96
g
97
h
98
""".splitlines(True)
99
100
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
101
class TestAnnotate(tests.TestCaseWithTransport):
102
103
    def create_merged_trees(self):
104
        tree1 = self.make_branch_and_tree('tree1')
105
        self.build_tree_contents([('tree1/a', 'first\n')])
106
        tree1.add(['a'], ['a-id'])
107
        tree1.commit('a', rev_id='rev-1',
2182.3.12 by John Arbash Meinel
Force the timezone properly during tests which look at dates.
108
                     committer="joe@foo.com",
109
                     timestamp=1166046000.00, timezone=0)
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
110
111
        tree2 = tree1.bzrdir.clone('tree2').open_workingtree()
112
113
        self.build_tree_contents([('tree1/a', 'first\nsecond\n')])
114
        tree1.commit('b', rev_id='rev-2',
2182.3.12 by John Arbash Meinel
Force the timezone properly during tests which look at dates.
115
                     committer='joe@foo.com',
116
                     timestamp=1166046001.00, timezone=0)
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
117
118
        self.build_tree_contents([('tree2/a', 'first\nthird\n')])
119
        tree2.commit('c', rev_id='rev-1_1_1',
2182.3.12 by John Arbash Meinel
Force the timezone properly during tests which look at dates.
120
                     committer="barry@foo.com",
121
                     timestamp=1166046002.00, timezone=0)
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
122
123
        num_conflicts = tree1.merge_from_branch(tree2.branch)
124
        self.assertEqual(1, num_conflicts)
125
126
        self.build_tree_contents([('tree1/a',
127
                                 'first\nsecond\nthird\n')])
128
        tree1.set_conflicts(conflicts.ConflictList())
129
        tree1.commit('merge 2', rev_id='rev-3',
2182.3.12 by John Arbash Meinel
Force the timezone properly during tests which look at dates.
130
                     committer='sal@foo.com',
131
                     timestamp=1166046003.00, timezone=0)
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
132
        return tree1, tree2
133
134
    def create_deeply_merged_trees(self):
135
        tree1, tree2 = self.create_merged_trees()
136
137
        tree3 = tree2.bzrdir.clone('tree3').open_workingtree()
138
139
        tree2.commit('noop', rev_id='rev-1.1.2')
140
        self.assertEqual(0, tree1.merge_from_branch(tree2.branch))
141
        tree1.commit('noop merge', rev_id='rev-4')
142
143
        self.build_tree_contents([('tree3/a', 'first\nthird\nfourth\n')])
2182.3.4 by John Arbash Meinel
add show-ids and test that nearby areas are collapsed without full
144
        tree3.commit('four', rev_id='rev-1_1_1_1_1',
2182.3.12 by John Arbash Meinel
Force the timezone properly during tests which look at dates.
145
                     committer='jerry@foo.com',
146
                     timestamp=1166046003.00, timezone=0)
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
147
148
        tree4 = tree3.bzrdir.clone('tree4').open_workingtree()
149
150
        tree3.commit('noop', rev_id='rev-1.1.1.1.2',
2182.3.12 by John Arbash Meinel
Force the timezone properly during tests which look at dates.
151
                     committer='jerry@foo.com',
152
                     timestamp=1166046004.00, timezone=0)
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
153
        self.assertEqual(0, tree1.merge_from_branch(tree3.branch))
154
        tree1.commit('merge four', rev_id='rev-5')
155
2182.3.4 by John Arbash Meinel
add show-ids and test that nearby areas are collapsed without full
156
        self.build_tree_contents([('tree4/a',
157
                                   'first\nthird\nfourth\nfifth\nsixth\n')])
158
        tree4.commit('five and six', rev_id='rev-1_1_1_1_1_1_1',
2182.3.12 by John Arbash Meinel
Force the timezone properly during tests which look at dates.
159
                     committer='george@foo.com',
160
                     timestamp=1166046005.00, timezone=0)
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
161
        self.assertEqual(0, tree1.merge_from_branch(tree4.branch))
2182.3.4 by John Arbash Meinel
add show-ids and test that nearby areas are collapsed without full
162
        tree1.commit('merge five and six', rev_id='rev-6')
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
163
        return tree1
164
165
    def test_annotate_shows_dotted_revnos(self):
166
        tree1, tree2 = self.create_merged_trees()
167
168
        sio = StringIO()
169
        annotate.annotate_file(tree1.branch, 'rev-3', 'a-id',
170
                               to_file=sio)
171
        self.assertEqualDiff('1     joe@foo | first\n'
172
                             '2     joe@foo | second\n'
173
                             '1.1.1 barry@f | third\n',
174
                             sio.getvalue())
175
176
    def test_annotate_limits_dotted_revnos(self):
177
        """Annotate should limit dotted revnos to a depth of 12"""
178
        tree1 = self.create_deeply_merged_trees()
179
180
        sio = StringIO()
181
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
2182.3.4 by John Arbash Meinel
add show-ids and test that nearby areas are collapsed without full
182
                               to_file=sio, verbose=False, full=False)
183
        self.assertEqualDiff('1            joe@foo | first\n'
184
                             '2            joe@foo | second\n'
185
                             '1.1.1        barry@f | third\n'
186
                             '1.1.1.1.1    jerry@f | fourth\n'
187
                             '1.1.1.1.1.1> george@ | fifth\n'
188
                             '                     | sixth\n',
189
                             sio.getvalue())
190
191
        sio = StringIO()
192
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
193
                               to_file=sio, verbose=False, full=True)
194
        self.assertEqualDiff('1            joe@foo | first\n'
195
                             '2            joe@foo | second\n'
196
                             '1.1.1        barry@f | third\n'
197
                             '1.1.1.1.1    jerry@f | fourth\n'
198
                             '1.1.1.1.1.1> george@ | fifth\n'
199
                             '1.1.1.1.1.1> george@ | sixth\n',
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
200
                             sio.getvalue())
201
202
        # verbose=True shows everything, the full revno, user id, and date
203
        sio = StringIO()
204
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
2182.3.4 by John Arbash Meinel
add show-ids and test that nearby areas are collapsed without full
205
                               to_file=sio, verbose=True, full=False)
206
        self.assertEqualDiff('1             joe@foo.com    20061213 | first\n'
207
                             '2             joe@foo.com    20061213 | second\n'
208
                             '1.1.1         barry@foo.com  20061213 | third\n'
209
                             '1.1.1.1.1     jerry@foo.com  20061213 | fourth\n'
210
                             '1.1.1.1.1.1.1 george@foo.com 20061213 | fifth\n'
211
                             '                                      | sixth\n',
212
                             sio.getvalue())
213
214
        sio = StringIO()
215
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
216
                               to_file=sio, verbose=True, full=True)
217
        self.assertEqualDiff('1             joe@foo.com    20061213 | first\n'
218
                             '2             joe@foo.com    20061213 | second\n'
219
                             '1.1.1         barry@foo.com  20061213 | third\n'
220
                             '1.1.1.1.1     jerry@foo.com  20061213 | fourth\n'
221
                             '1.1.1.1.1.1.1 george@foo.com 20061213 | fifth\n'
222
                             '1.1.1.1.1.1.1 george@foo.com 20061213 | sixth\n',
223
                             sio.getvalue())
224
    
225
    def test_annotate_show_ids(self):
226
        tree1 = self.create_deeply_merged_trees()
227
228
        sio = StringIO()
229
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
230
                               to_file=sio, show_ids=True, full=False)
231
232
        # It looks better with real revision ids :)
233
        self.assertEqualDiff('            rev-1 | first\n'
234
                             '            rev-2 | second\n'
235
                             '        rev-1_1_1 | third\n'
236
                             '    rev-1_1_1_1_1 | fourth\n'
237
                             'rev-1_1_1_1_1_1_1 | fifth\n'
238
                             '                  | sixth\n',
239
                             sio.getvalue())
240
241
        sio = StringIO()
242
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
243
                               to_file=sio, show_ids=True, full=True)
244
245
        self.assertEqualDiff('            rev-1 | first\n'
246
                             '            rev-2 | second\n'
247
                             '        rev-1_1_1 | third\n'
248
                             '    rev-1_1_1_1_1 | fourth\n'
249
                             'rev-1_1_1_1_1_1_1 | fifth\n'
250
                             'rev-1_1_1_1_1_1_1 | sixth\n',
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
251
                             sio.getvalue())
1551.9.19 by Aaron Bentley
Merge from bzr.dev
252
253
254
class TestReannotate(tests.TestCase):
255
256
    def annotateEqual(self, expected, parents, newlines, revision_id):
257
        annotate_list = list(annotate.reannotate(parents, newlines,
258
                             revision_id))
259
        self.assertEqual(len(expected), len(annotate_list))
260
        for e, a in zip(expected, annotate_list):
261
            self.assertEqual(e, a)
262
263
    def test_reannotate(self):
264
        self.annotateEqual(parent_1, [parent_1], new_1, 'blahblah')
265
        self.annotateEqual(expected_2_1, [parent_2], new_1, 'blahblah')
266
        self.annotateEqual(expected_1_2_2, [parent_1, parent_2], new_2, 
267
                           'blahblah')