~bzr-pqm/bzr/bzr.dev

4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
1
# Copyright (C) 2009 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17
"""Tests for interface conformance of 'WorkingTree.annotate_iter'"""
18
19
import os
20
21
from bzrlib import (
22
    errors,
23
    inventory,
24
    osutils,
25
    tests,
26
    )
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
27
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
28
29
30
class TestAnnotateIter(TestCaseWithWorkingTree):
31
32
    def make_single_rev_tree(self):
33
        builder = self.make_branch_builder('branch')
34
        builder.build_snapshot('rev-1', None, [
35
            ('add', ('', 'TREE_ROOT', 'directory', None)),
36
            ('add', ('file', 'file-id', 'file', 'initial content\n')),
37
            ])
38
        b = builder.get_branch()
39
        tree = b.create_checkout('tree', lightweight=True)
40
        tree.lock_read()
41
        self.addCleanup(tree.unlock)
42
        return tree
43
44
    def test_annotate_same_as_parent(self):
45
        tree = self.make_single_rev_tree()
46
        annotations = tree.annotate_iter('file-id')
47
        self.assertEqual([('rev-1', 'initial content\n')],
48
                         annotations)
49
50
    def test_annotate_mod_from_parent(self):
51
        tree = self.make_single_rev_tree()
52
        self.build_tree_contents([('tree/file',
53
                                   'initial content\nnew content\n')])
54
        annotations = tree.annotate_iter('file-id')
55
        self.assertEqual([('rev-1', 'initial content\n'),
56
                          ('current:', 'new content\n'),
57
                         ], annotations)
58
59
    def test_annotate_merge_parents(self):
60
        builder = self.make_branch_builder('branch')
61
        builder.start_series()
62
        builder.build_snapshot('rev-1', None, [
63
            ('add', ('', 'TREE_ROOT', 'directory', None)),
64
            ('add', ('file', 'file-id', 'file', 'initial content\n')),
65
            ])
66
        builder.build_snapshot('rev-2', ['rev-1'], [
67
            ('modify', ('file-id', 'initial content\ncontent in 2\n')),
68
            ])
69
        builder.build_snapshot('rev-3', ['rev-1'], [
70
            ('modify', ('file-id', 'initial content\ncontent in 3\n')),
71
            ])
72
        builder.finish_series()
73
        b = builder.get_branch()
74
        tree = b.create_checkout('tree', revision_id='rev-2', lightweight=True)
75
        tree.lock_write()
76
        self.addCleanup(tree.unlock)
77
        tree.set_parent_ids(['rev-2', 'rev-3'])
78
        self.build_tree_contents([('tree/file',
79
                                   'initial content\ncontent in 2\n'
80
                                   'content in 3\nnew content\n')])
81
        annotations = tree.annotate_iter('file-id')
82
        self.assertEqual([('rev-1', 'initial content\n'),
83
                          ('rev-2', 'content in 2\n'),
84
                          ('rev-3', 'content in 3\n'),
85
                          ('current:', 'new content\n'),
86
                         ], annotations)
87
88
    def test_annotate_merge_parent_no_file(self):
89
        builder = self.make_branch_builder('branch')
90
        builder.start_series()
91
        builder.build_snapshot('rev-1', None, [
92
            ('add', ('', 'TREE_ROOT', 'directory', None)),
93
            ])
94
        builder.build_snapshot('rev-2', ['rev-1'], [
95
            ('add', ('file', 'file-id', 'file', 'initial content\n')),
96
            ])
97
        builder.build_snapshot('rev-3', ['rev-1'], [])
98
        builder.finish_series()
99
        b = builder.get_branch()
100
        tree = b.create_checkout('tree', revision_id='rev-2', lightweight=True)
101
        tree.lock_write()
102
        self.addCleanup(tree.unlock)
103
        tree.set_parent_ids(['rev-2', 'rev-3'])
104
        self.build_tree_contents([('tree/file',
105
                                   'initial content\nnew content\n')])
106
        annotations = tree.annotate_iter('file-id')
107
        self.assertEqual([('rev-2', 'initial content\n'),
108
                          ('current:', 'new content\n'),
109
                         ], annotations)
110
111
    def test_annotate_merge_parent_was_directory(self):
112
        builder = self.make_branch_builder('branch')
113
        builder.start_series()
114
        builder.build_snapshot('rev-1', None, [
115
            ('add', ('', 'TREE_ROOT', 'directory', None)),
116
            ])
117
        builder.build_snapshot('rev-2', ['rev-1'], [
118
            ('add', ('file', 'file-id', 'file', 'initial content\n')),
119
            ])
120
        builder.build_snapshot('rev-3', ['rev-1'], [
121
            ('add', ('a_dir', 'file-id', 'directory', None)),
122
            ])
123
        builder.finish_series()
124
        b = builder.get_branch()
125
        tree = b.create_checkout('tree', revision_id='rev-2', lightweight=True)
126
        tree.lock_write()
127
        self.addCleanup(tree.unlock)
128
        tree.set_parent_ids(['rev-2', 'rev-3'])
129
        self.build_tree_contents([('tree/file',
130
                                   'initial content\nnew content\n')])
131
        annotations = tree.annotate_iter('file-id')
132
        self.assertEqual([('rev-2', 'initial content\n'),
133
                          ('current:', 'new content\n'),
134
                         ], annotations)
4454.3.69 by John Arbash Meinel
Add a couple more annotate-after-merge tests for WT.
135
136
    def test_annotate_same_as_merge_parent(self):
137
        builder = self.make_branch_builder('branch')
138
        builder.start_series()
139
        builder.build_snapshot('rev-1', None, [
140
            ('add', ('', 'TREE_ROOT', 'directory', None)),
141
            ('add', ('file', 'file-id', 'file', 'initial content\n')),
142
            ])
143
        builder.build_snapshot('rev-2', ['rev-1'], [
144
            ])
145
        builder.build_snapshot('rev-3', ['rev-1'], [
146
            ('modify', ('file-id', 'initial content\ncontent in 3\n')),
147
            ])
148
        builder.finish_series()
149
        b = builder.get_branch()
150
        tree = b.create_checkout('tree', revision_id='rev-2', lightweight=True)
151
        tree.lock_write()
152
        self.addCleanup(tree.unlock)
153
        tree.set_parent_ids(['rev-2', 'rev-3'])
154
        self.build_tree_contents([('tree/file',
155
                                   'initial content\ncontent in 3\n')])
156
        annotations = tree.annotate_iter('file-id')
157
        self.assertEqual([('rev-1', 'initial content\n'),
158
                          ('rev-3', 'content in 3\n'),
159
                         ], annotations)
160
161
    def test_annotate_same_as_merge_parent_supersedes(self):
162
        builder = self.make_branch_builder('branch')
163
        builder.start_series()
164
        builder.build_snapshot('rev-1', None, [
165
            ('add', ('', 'TREE_ROOT', 'directory', None)),
166
            ('add', ('file', 'file-id', 'file', 'initial content\n')),
167
            ])
168
        builder.build_snapshot('rev-2', ['rev-1'], [
169
            ('modify', ('file-id', 'initial content\nnew content\n')),
170
            ])
171
        builder.build_snapshot('rev-3', ['rev-2'], [
172
            ('modify', ('file-id', 'initial content\ncontent in 3\n')),
173
            ])
174
        builder.build_snapshot('rev-4', ['rev-3'], [
175
            ('modify', ('file-id', 'initial content\nnew content\n')),
176
            ])
177
        # In this case, the content locally is the same as content in basis
178
        # tree, but the merge revision states that *it* should win
179
        builder.finish_series()
180
        b = builder.get_branch()
181
        tree = b.create_checkout('tree', revision_id='rev-2', lightweight=True)
182
        tree.lock_write()
183
        self.addCleanup(tree.unlock)
184
        tree.set_parent_ids(['rev-2', 'rev-4'])
185
        annotations = tree.annotate_iter('file-id')
186
        self.assertEqual([('rev-1', 'initial content\n'),
187
                          ('rev-4', 'new content\n'),
188
                         ], annotations)
189