/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1540.1.7 by John Arbash Meinel
Added copyright statement to test_fileid_involved, and minor pep8 cleanup.
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
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
16
17
import os
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
18
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
19
from bzrlib.add import smart_add
1545.2.9 by Aaron Bentley
Moved merge.merge to builtins
20
from bzrlib.builtins import merge
1551.2.55 by abentley
Fix fileid involed tests on win32 (by skipping them for unescaped weave formats)
21
from bzrlib.errors import IllegalPath
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
22
from bzrlib.delta import compare_trees
1551.2.55 by abentley
Fix fileid involed tests on win32 (by skipping them for unescaped weave formats)
23
from bzrlib.tests import TestSkipped
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
24
from bzrlib.tests.repository_implementations.test_repository import TestCaseWithRepository
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
25
from bzrlib.workingtree import WorkingTree
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
26
1534.7.154 by Aaron Bentley
Removed changes from bzr.ab 1529..1536
27
1534.4.54 by Robert Collins
Merge from integration.
28
class FileIdInvolvedBase(TestCaseWithRepository):
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
29
30
    def touch(self,filename):
31
        f = file(filename,"a")
32
        f.write("appended line\n")
33
        f.close( )
34
1551.2.7 by Aaron Bentley
Test case for discrepancy between fileid_involved and compare_tree [recommit]
35
    def compare_tree_fileids(self, branch, old_rev, new_rev):
36
        old_tree = self.branch.repository.revision_tree(old_rev)
37
        new_tree = self.branch.repository.revision_tree(new_rev)
38
        delta = compare_trees(old_tree, new_tree)
39
40
        l2 = [id for path, id, kind in delta.added] + \
41
             [id for oldpath, newpath, id, kind, text_modified, \
42
                meta_modified in delta.renamed] + \
43
             [id for path, id, kind, text_modified, meta_modified in \
44
                delta.modified]
45
        return set(l2)
46
47
    
48
class TestFileIdInvolved(FileIdInvolvedBase):
49
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
50
    def setUp(self):
1185.64.9 by Goffredo Baroncelli
renamed test_file_involved -> test_fileid_involved
51
        super(TestFileIdInvolved, self).setUp()
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
52
        # create three branches, and merge it
53
        #
54
        #           /-->J ------>K                (branch2)
55
        #          /              \
56
        #  A ---> B --->C ---->D->G               (main)
57
        #  \           /      /
58
        #   \---> E---/----> F                 (branch1)
59
1694.2.6 by Martin Pool
[merge] bzr.dev
60
        # A changes: 
61
        # B changes: 'a-file-id-2006-01-01-abcd'
62
        # C changes:  Nothing (perfect merge)
63
        # D changes: 'b-file-id-2006-01-01-defg'
64
        # E changes: 'file-d'
65
        # F changes: 'file-d'
66
        # G changes: 'b-file-id-2006-01-01-defg'
67
        # J changes: 'b-file-id-2006-01-01-defg'
68
        # K changes: 'c-funky<file-id> quiji%bo'
69
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
70
        main_wt = self.make_branch_and_tree('main')
71
        main_branch = main_wt.branch
72
        self.build_tree(["main/a","main/b","main/c"])
73
74
        main_wt.add(['a', 'b', 'c'], ['a-file-id-2006-01-01-abcd',
1540.1.6 by John Arbash Meinel
fileid_involved needs to unescape the file id and revision id
75
                                 'b-file-id-2006-01-01-defg',
76
                                 'c-funky<file-id> quiji%bo'])
1551.2.55 by abentley
Fix fileid involed tests on win32 (by skipping them for unescaped weave formats)
77
        try:
78
            main_wt.commit("Commit one", rev_id="rev-A")
79
        except IllegalPath:
1694.2.6 by Martin Pool
[merge] bzr.dev
80
            # ("File-id with <> not supported with this format")
81
            # this is not a skip because newer formats do support this,
82
            # and nothin can done to correct this test - its not a bug.
83
            return
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
84
        #-------- end A -----------
85
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
86
        d1 = main_branch.bzrdir.clone('branch1')
87
        b1 = d1.open_branch()
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
88
        self.build_tree(["branch1/d"])
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
89
        bt1 = d1.open_workingtree()
1694.2.6 by Martin Pool
[merge] bzr.dev
90
        bt1.add(['d'], ['file-d'])
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
91
        bt1.commit("branch1, Commit one", rev_id="rev-E")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
92
93
        #-------- end E -----------
94
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
95
        self.touch("main/a")
96
        main_wt.commit("Commit two", rev_id="rev-B")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
97
98
        #-------- end B -----------
99
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
100
        d2 = main_branch.bzrdir.clone('branch2')
101
        branch2_branch = d2.open_branch()
102
        bt2 = d2.open_workingtree()
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
103
        os.chmod("branch2/b",0770)
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
104
        bt2.commit("branch2, Commit one", rev_id="rev-J")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
105
106
        #-------- end J -----------
107
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
108
        self.merge(b1, main_wt)
109
        main_wt.commit("merge branch1, rev-11", rev_id="rev-C")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
110
111
        #-------- end C -----------
112
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
113
        bt1.rename_one("d","e")
114
        bt1.commit("branch1, commit two", rev_id="rev-F")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
115
116
        #-------- end F -----------
117
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
118
        self.touch("branch2/c")
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
119
        bt2.commit("branch2, commit two", rev_id="rev-K")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
120
121
        #-------- end K -----------
122
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
123
        self.touch("main/b")
124
        self.merge(b1, main_wt)
1540.1.6 by John Arbash Meinel
fileid_involved needs to unescape the file id and revision id
125
        # D gets some funky characters to make sure the unescaping works
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
126
        main_wt.commit("merge branch1, rev-12", rev_id="rev-<D>")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
127
128
        # end D
129
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
130
        self.merge(branch2_branch, main_wt)
131
        main_wt.commit("merge branch1, rev-22",  rev_id="rev-G")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
132
133
        # end G
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
134
        self.branch = main_branch
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
135
1694.2.6 by Martin Pool
[merge] bzr.dev
136
    def test_fileids_altered_between_two_revs(self):
137
        def foo(old, new):
138
            print set(self.branch.repository.get_ancestry(new)).difference(set(self.branch.repository.get_ancestry(old)))
139
140
        self.assertEqual(
141
            {'b-file-id-2006-01-01-defg':set(['rev-J']),
142
             'c-funky<file-id> quiji%bo':set(['rev-K'])
143
             },
144
            self.branch.repository.fileids_altered_by_revision_ids(["rev-J","rev-K"]))
145
146
        self.assertEqual(
147
            {'b-file-id-2006-01-01-defg': set(['rev-<D>']),
148
             'file-d': set(['rev-F']),
149
             },
150
            self.branch.repository.fileids_altered_by_revision_ids(['rev-<D>', 'rev-F']))
151
152
        self.assertEqual(
153
            {
154
             'b-file-id-2006-01-01-defg': set(['rev-<D>', 'rev-G', 'rev-J']), 
155
             'c-funky<file-id> quiji%bo': set(['rev-K']),
156
             'file-d': set(['rev-F']), 
157
             },
158
            self.branch.repository.fileids_altered_by_revision_ids(
159
                ['rev-<D>', 'rev-G', 'rev-F', 'rev-K', 'rev-J']))
160
161
        self.assertEqual(
162
            {'a-file-id-2006-01-01-abcd': set(['rev-B']),
163
             'b-file-id-2006-01-01-defg': set(['rev-<D>', 'rev-G', 'rev-J']),
164
             'c-funky<file-id> quiji%bo': set(['rev-K']),
165
             'file-d': set(['rev-F']),
166
             },
167
            self.branch.repository.fileids_altered_by_revision_ids(
168
                ['rev-G', 'rev-F', 'rev-C', 'rev-B', 'rev-<D>', 'rev-K', 'rev-J']))
169
170
    def test_fileids_altered_by_revision_ids(self):
171
        self.assertEqual(
172
            {'a-file-id-2006-01-01-abcd':set(['rev-A']),
173
             'b-file-id-2006-01-01-defg': set(['rev-A']),
174
             'c-funky<file-id> quiji%bo': set(['rev-A']),
175
             }, 
176
            self.branch.repository.fileids_altered_by_revision_ids(["rev-A"]))
177
        self.assertEqual(
178
            {'a-file-id-2006-01-01-abcd':set(['rev-B'])
179
             }, 
180
            self.branch.repository.fileids_altered_by_revision_ids(["rev-B"]))
181
        self.assertEqual(
182
            {'b-file-id-2006-01-01-defg':set(['rev-<D>'])
183
             },
184
            self.branch.repository.fileids_altered_by_revision_ids(["rev-<D>"]))
185
186
    def test_fileids_involved_full_compare(self):
187
        # this tests that the result of each fileid_involved calculation 
188
        # along a revision history selects only the fileids selected by
189
        # comparing the trees - no less, and no more. This is correct 
190
        # because in our sample data we do not revert any file ids along
191
        # the revision history.
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
192
        pp=[]
193
        history = self.branch.revision_history( )
194
195
        if len(history) < 2: return
196
197
        for start in range(0,len(history)-1):
1551.2.7 by Aaron Bentley
Test case for discrepancy between fileid_involved and compare_tree [recommit]
198
            start_id = history[start]
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
199
            for end in range(start+1,len(history)):
1551.2.7 by Aaron Bentley
Test case for discrepancy between fileid_involved and compare_tree [recommit]
200
                end_id = history[end]
1694.2.6 by Martin Pool
[merge] bzr.dev
201
                old_revs = set(self.branch.repository.get_ancestry(start_id))
202
                new_revs = set(self.branch.repository.get_ancestry(end_id))
203
                l1 = self.branch.repository.fileids_altered_by_revision_ids(
204
                    new_revs.difference(old_revs))
205
                l1 = set(l1.keys())
206
1551.2.7 by Aaron Bentley
Test case for discrepancy between fileid_involved and compare_tree [recommit]
207
                l2 = self.compare_tree_fileids(self.branch, start_id, end_id)
208
                self.assertEquals(l1, l2)
209
210
211
class TestFileIdInvolvedSuperset(FileIdInvolvedBase):
212
213
    def setUp(self):
214
        super(TestFileIdInvolvedSuperset, self).setUp()
215
216
        main_wt = self.make_branch_and_tree('main')
217
        main_branch = main_wt.branch
218
        self.build_tree(["main/a","main/b","main/c"])
219
220
        main_wt.add(['a', 'b', 'c'], ['a-file-id-2006-01-01-abcd',
221
                                 'b-file-id-2006-01-01-defg',
222
                                 'c-funky<file-id> quiji%bo'])
1551.2.55 by abentley
Fix fileid involed tests on win32 (by skipping them for unescaped weave formats)
223
        try:
224
            main_wt.commit("Commit one", rev_id="rev-A")
1694.2.6 by Martin Pool
[merge] bzr.dev
225
        except IllegalPath: 
226
            return # not an error, and not fixable. New formats are fixed.
1551.2.7 by Aaron Bentley
Test case for discrepancy between fileid_involved and compare_tree [recommit]
227
1534.5.3 by Robert Collins
Make format 4/5/6 branches share a single LockableFiles instance across wt/branch/repository.
228
        branch2_bzrdir = main_branch.bzrdir.sprout("branch2")
229
        branch2_branch = branch2_bzrdir.open_branch()
230
        branch2_wt = branch2_bzrdir.open_workingtree()
1551.2.7 by Aaron Bentley
Test case for discrepancy between fileid_involved and compare_tree [recommit]
231
        os.chmod("branch2/b",0770)
1534.5.3 by Robert Collins
Make format 4/5/6 branches share a single LockableFiles instance across wt/branch/repository.
232
        branch2_wt.commit("branch2, Commit one", rev_id="rev-J")
1551.2.7 by Aaron Bentley
Test case for discrepancy between fileid_involved and compare_tree [recommit]
233
234
        self.merge(branch2_branch, main_wt)
235
        os.chmod("main/b",0660)
236
        main_wt.commit("merge branch1, rev-22",  rev_id="rev-G")
237
238
        # end G
239
        self.branch = main_branch
240
241
    def test_fileid_involved_full_compare2(self):
1694.2.6 by Martin Pool
[merge] bzr.dev
242
        # this tests that fileids_alteted_by_revision_ids returns 
243
        # more information than compare_tree can, because it 
244
        # sees each change rather than the aggregate delta.
1551.2.7 by Aaron Bentley
Test case for discrepancy between fileid_involved and compare_tree [recommit]
245
        history = self.branch.revision_history()
246
        old_rev = history[0]
247
        new_rev = history[1]
1694.2.6 by Martin Pool
[merge] bzr.dev
248
        old_revs = set(self.branch.repository.get_ancestry(old_rev))
249
        new_revs = set(self.branch.repository.get_ancestry(new_rev))
1551.2.7 by Aaron Bentley
Test case for discrepancy between fileid_involved and compare_tree [recommit]
250
1694.2.6 by Martin Pool
[merge] bzr.dev
251
        l1 = self.branch.repository.fileids_altered_by_revision_ids(
252
            new_revs.difference(old_revs))
253
        l1 = set(l1.keys())
1551.2.7 by Aaron Bentley
Test case for discrepancy between fileid_involved and compare_tree [recommit]
254
255
        l2 = self.compare_tree_fileids(self.branch, old_rev, new_rev)
256
        self.assertNotEqual(l2, l1)
1553.5.28 by Martin Pool
[merge] from bzr.dev before integration
257
        self.assertSubset(l2, l1)