/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
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1540.1.7 by John Arbash Meinel
Added copyright statement to test_fileid_involved, and minor pep8 cleanup.
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1540.1.7 by John Arbash Meinel
Added copyright statement to test_fileid_involved, and minor pep8 cleanup.
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1540.1.7 by John Arbash Meinel
Added copyright statement to test_fileid_involved, and minor pep8 cleanup.
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
1711.7.29 by John Arbash Meinel
Switch to using TestSkipped for fileid_involved tests.
18
import sys
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
19
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
20
from bzrlib.add import smart_add
1545.2.9 by Aaron Bentley
Moved merge.merge to builtins
21
from bzrlib.builtins import merge
1551.2.55 by abentley
Fix fileid involed tests on win32 (by skipping them for unescaped weave formats)
22
from bzrlib.errors import IllegalPath
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
1711.7.4 by John Arbash Meinel
Fix test_fileid_involved so it uses TreeTransform to set the executable bits rather than chmod()
25
from bzrlib.transform import TreeTransform
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
26
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.
27
1534.7.154 by Aaron Bentley
Removed changes from bzr.ab 1529..1536
28
1534.4.54 by Robert Collins
Merge from integration.
29
class FileIdInvolvedBase(TestCaseWithRepository):
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
30
31
    def touch(self,filename):
32
        f = file(filename,"a")
33
        f.write("appended line\n")
34
        f.close( )
35
1551.2.7 by Aaron Bentley
Test case for discrepancy between fileid_involved and compare_tree [recommit]
36
    def compare_tree_fileids(self, branch, old_rev, new_rev):
37
        old_tree = self.branch.repository.revision_tree(old_rev)
38
        new_tree = self.branch.repository.revision_tree(new_rev)
1852.10.3 by Robert Collins
Remove all uses of compare_trees and replace with Tree.changes_from throughout bzrlib.
39
        delta = new_tree.changes_from(old_tree)
1551.2.7 by Aaron Bentley
Test case for discrepancy between fileid_involved and compare_tree [recommit]
40
41
        l2 = [id for path, id, kind in delta.added] + \
42
             [id for oldpath, newpath, id, kind, text_modified, \
43
                meta_modified in delta.renamed] + \
44
             [id for path, id, kind, text_modified, meta_modified in \
45
                delta.modified]
46
        return set(l2)
47
48
    
49
class TestFileIdInvolved(FileIdInvolvedBase):
50
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
51
    def setUp(self):
1185.64.9 by Goffredo Baroncelli
renamed test_file_involved -> test_fileid_involved
52
        super(TestFileIdInvolved, self).setUp()
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
53
        # create three branches, and merge it
54
        #
55
        #           /-->J ------>K                (branch2)
56
        #          /              \
57
        #  A ---> B --->C ---->D->G               (main)
58
        #  \           /      /
59
        #   \---> E---/----> F                 (branch1)
60
1694.2.6 by Martin Pool
[merge] bzr.dev
61
        # A changes: 
62
        # B changes: 'a-file-id-2006-01-01-abcd'
63
        # C changes:  Nothing (perfect merge)
64
        # D changes: 'b-file-id-2006-01-01-defg'
65
        # E changes: 'file-d'
66
        # F changes: 'file-d'
67
        # G changes: 'b-file-id-2006-01-01-defg'
68
        # J changes: 'b-file-id-2006-01-01-defg'
69
        # K changes: 'c-funky<file-id> quiji%bo'
70
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
71
        main_wt = self.make_branch_and_tree('main')
72
        main_branch = main_wt.branch
73
        self.build_tree(["main/a","main/b","main/c"])
74
75
        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
76
                                 'b-file-id-2006-01-01-defg',
77
                                 'c-funky<file-id> quiji%bo'])
1551.2.55 by abentley
Fix fileid involed tests on win32 (by skipping them for unescaped weave formats)
78
        try:
79
            main_wt.commit("Commit one", rev_id="rev-A")
80
        except IllegalPath:
1711.7.29 by John Arbash Meinel
Switch to using TestSkipped for fileid_involved tests.
81
            # TODO: jam 20060701 Consider raising a different exception
82
            #       newer formats do support this, and nothin can done to 
83
            #       correct this test - its not a bug.
84
            if sys.platform == 'win32':
85
                raise TestSkipped('Old repository formats do not'
86
                                  ' support file ids with <> on win32')
87
            # This is not a known error condition
88
            raise
89
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
90
        #-------- end A -----------
91
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.
92
        d1 = main_branch.bzrdir.clone('branch1')
93
        b1 = d1.open_branch()
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
94
        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.
95
        bt1 = d1.open_workingtree()
1694.2.6 by Martin Pool
[merge] bzr.dev
96
        bt1.add(['d'], ['file-d'])
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
97
        bt1.commit("branch1, Commit one", rev_id="rev-E")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
98
99
        #-------- end E -----------
100
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
101
        self.touch("main/a")
102
        main_wt.commit("Commit two", rev_id="rev-B")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
103
104
        #-------- end B -----------
105
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.
106
        d2 = main_branch.bzrdir.clone('branch2')
107
        branch2_branch = d2.open_branch()
108
        bt2 = d2.open_workingtree()
1711.7.4 by John Arbash Meinel
Fix test_fileid_involved so it uses TreeTransform to set the executable bits rather than chmod()
109
        set_executability(bt2, 'b', True)
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
110
        bt2.commit("branch2, Commit one", rev_id="rev-J")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
111
112
        #-------- end J -----------
113
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
114
        self.merge(b1, main_wt)
115
        main_wt.commit("merge branch1, rev-11", rev_id="rev-C")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
116
117
        #-------- end C -----------
118
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
119
        bt1.rename_one("d","e")
120
        bt1.commit("branch1, commit two", rev_id="rev-F")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
121
122
        #-------- end F -----------
123
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
124
        self.touch("branch2/c")
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
125
        bt2.commit("branch2, commit two", rev_id="rev-K")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
126
127
        #-------- end K -----------
128
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
129
        self.touch("main/b")
130
        self.merge(b1, main_wt)
1540.1.6 by John Arbash Meinel
fileid_involved needs to unescape the file id and revision id
131
        # 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.
132
        main_wt.commit("merge branch1, rev-12", rev_id="rev-<D>")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
133
134
        # end D
135
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
136
        self.merge(branch2_branch, main_wt)
137
        main_wt.commit("merge branch1, rev-22",  rev_id="rev-G")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
138
139
        # end G
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
140
        self.branch = main_branch
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
141
1694.2.6 by Martin Pool
[merge] bzr.dev
142
    def test_fileids_altered_between_two_revs(self):
143
        def foo(old, new):
144
            print set(self.branch.repository.get_ancestry(new)).difference(set(self.branch.repository.get_ancestry(old)))
145
1711.7.16 by John Arbash Meinel
remove assertDictsEqual
146
        self.assertEqual(
1694.2.6 by Martin Pool
[merge] bzr.dev
147
            {'b-file-id-2006-01-01-defg':set(['rev-J']),
148
             'c-funky<file-id> quiji%bo':set(['rev-K'])
149
             },
150
            self.branch.repository.fileids_altered_by_revision_ids(["rev-J","rev-K"]))
151
1711.7.16 by John Arbash Meinel
remove assertDictsEqual
152
        self.assertEqual(
1694.2.6 by Martin Pool
[merge] bzr.dev
153
            {'b-file-id-2006-01-01-defg': set(['rev-<D>']),
154
             'file-d': set(['rev-F']),
155
             },
156
            self.branch.repository.fileids_altered_by_revision_ids(['rev-<D>', 'rev-F']))
157
1711.7.16 by John Arbash Meinel
remove assertDictsEqual
158
        self.assertEqual(
1694.2.6 by Martin Pool
[merge] bzr.dev
159
            {
160
             'b-file-id-2006-01-01-defg': set(['rev-<D>', 'rev-G', 'rev-J']), 
161
             'c-funky<file-id> quiji%bo': set(['rev-K']),
162
             'file-d': set(['rev-F']), 
163
             },
164
            self.branch.repository.fileids_altered_by_revision_ids(
165
                ['rev-<D>', 'rev-G', 'rev-F', 'rev-K', 'rev-J']))
166
1711.7.16 by John Arbash Meinel
remove assertDictsEqual
167
        self.assertEqual(
1694.2.6 by Martin Pool
[merge] bzr.dev
168
            {'a-file-id-2006-01-01-abcd': set(['rev-B']),
169
             'b-file-id-2006-01-01-defg': set(['rev-<D>', 'rev-G', 'rev-J']),
170
             'c-funky<file-id> quiji%bo': set(['rev-K']),
171
             'file-d': set(['rev-F']),
172
             },
173
            self.branch.repository.fileids_altered_by_revision_ids(
174
                ['rev-G', 'rev-F', 'rev-C', 'rev-B', 'rev-<D>', 'rev-K', 'rev-J']))
175
176
    def test_fileids_altered_by_revision_ids(self):
1711.7.16 by John Arbash Meinel
remove assertDictsEqual
177
        self.assertEqual(
1694.2.6 by Martin Pool
[merge] bzr.dev
178
            {'a-file-id-2006-01-01-abcd':set(['rev-A']),
179
             'b-file-id-2006-01-01-defg': set(['rev-A']),
180
             'c-funky<file-id> quiji%bo': set(['rev-A']),
181
             }, 
182
            self.branch.repository.fileids_altered_by_revision_ids(["rev-A"]))
1711.7.16 by John Arbash Meinel
remove assertDictsEqual
183
        self.assertEqual(
1694.2.6 by Martin Pool
[merge] bzr.dev
184
            {'a-file-id-2006-01-01-abcd':set(['rev-B'])
185
             }, 
186
            self.branch.repository.fileids_altered_by_revision_ids(["rev-B"]))
1711.7.16 by John Arbash Meinel
remove assertDictsEqual
187
        self.assertEqual(
1694.2.6 by Martin Pool
[merge] bzr.dev
188
            {'b-file-id-2006-01-01-defg':set(['rev-<D>'])
189
             },
190
            self.branch.repository.fileids_altered_by_revision_ids(["rev-<D>"]))
191
192
    def test_fileids_involved_full_compare(self):
193
        # this tests that the result of each fileid_involved calculation 
194
        # along a revision history selects only the fileids selected by
195
        # comparing the trees - no less, and no more. This is correct 
196
        # because in our sample data we do not revert any file ids along
197
        # the revision history.
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
198
        pp=[]
199
        history = self.branch.revision_history( )
200
201
        if len(history) < 2: return
202
203
        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]
204
            start_id = history[start]
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
205
            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]
206
                end_id = history[end]
1694.2.6 by Martin Pool
[merge] bzr.dev
207
                old_revs = set(self.branch.repository.get_ancestry(start_id))
208
                new_revs = set(self.branch.repository.get_ancestry(end_id))
209
                l1 = self.branch.repository.fileids_altered_by_revision_ids(
210
                    new_revs.difference(old_revs))
211
                l1 = set(l1.keys())
212
1551.2.7 by Aaron Bentley
Test case for discrepancy between fileid_involved and compare_tree [recommit]
213
                l2 = self.compare_tree_fileids(self.branch, start_id, end_id)
214
                self.assertEquals(l1, l2)
215
216
217
class TestFileIdInvolvedSuperset(FileIdInvolvedBase):
218
219
    def setUp(self):
220
        super(TestFileIdInvolvedSuperset, self).setUp()
221
1711.7.4 by John Arbash Meinel
Fix test_fileid_involved so it uses TreeTransform to set the executable bits rather than chmod()
222
        self.branch = None
1551.2.7 by Aaron Bentley
Test case for discrepancy between fileid_involved and compare_tree [recommit]
223
        main_wt = self.make_branch_and_tree('main')
224
        main_branch = main_wt.branch
225
        self.build_tree(["main/a","main/b","main/c"])
226
227
        main_wt.add(['a', 'b', 'c'], ['a-file-id-2006-01-01-abcd',
228
                                 'b-file-id-2006-01-01-defg',
1843.2.3 by Aaron Bentley
Add test case for fileid_involved
229
                                 'c-funky<file-id> quiji\'"%bo'])
1551.2.55 by abentley
Fix fileid involed tests on win32 (by skipping them for unescaped weave formats)
230
        try:
231
            main_wt.commit("Commit one", rev_id="rev-A")
1694.2.6 by Martin Pool
[merge] bzr.dev
232
        except IllegalPath: 
1711.7.29 by John Arbash Meinel
Switch to using TestSkipped for fileid_involved tests.
233
            # TODO: jam 20060701 Consider raising a different exception
234
            #       newer formats do support this, and nothin can done to 
235
            #       correct this test - its not a bug.
236
            if sys.platform == 'win32':
237
                raise TestSkipped('Old repository formats do not'
238
                                  ' support file ids with <> on win32')
239
            # This is not a known error condition
240
            raise
1551.2.7 by Aaron Bentley
Test case for discrepancy between fileid_involved and compare_tree [recommit]
241
1534.5.3 by Robert Collins
Make format 4/5/6 branches share a single LockableFiles instance across wt/branch/repository.
242
        branch2_bzrdir = main_branch.bzrdir.sprout("branch2")
243
        branch2_branch = branch2_bzrdir.open_branch()
244
        branch2_wt = branch2_bzrdir.open_workingtree()
1711.7.4 by John Arbash Meinel
Fix test_fileid_involved so it uses TreeTransform to set the executable bits rather than chmod()
245
        set_executability(branch2_wt, 'b', True)
1534.5.3 by Robert Collins
Make format 4/5/6 branches share a single LockableFiles instance across wt/branch/repository.
246
        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]
247
248
        self.merge(branch2_branch, main_wt)
1711.7.15 by John Arbash Meinel
Properly handle the case when you want to turn off executability.
249
        set_executability(main_wt, 'b', False)
1551.2.7 by Aaron Bentley
Test case for discrepancy between fileid_involved and compare_tree [recommit]
250
        main_wt.commit("merge branch1, rev-22",  rev_id="rev-G")
251
252
        # end G
253
        self.branch = main_branch
254
255
    def test_fileid_involved_full_compare2(self):
1694.2.6 by Martin Pool
[merge] bzr.dev
256
        # this tests that fileids_alteted_by_revision_ids returns 
257
        # more information than compare_tree can, because it 
258
        # 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]
259
        history = self.branch.revision_history()
260
        old_rev = history[0]
261
        new_rev = history[1]
1694.2.6 by Martin Pool
[merge] bzr.dev
262
        old_revs = set(self.branch.repository.get_ancestry(old_rev))
263
        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]
264
1694.2.6 by Martin Pool
[merge] bzr.dev
265
        l1 = self.branch.repository.fileids_altered_by_revision_ids(
266
            new_revs.difference(old_revs))
267
        l1 = set(l1.keys())
1551.2.7 by Aaron Bentley
Test case for discrepancy between fileid_involved and compare_tree [recommit]
268
269
        l2 = self.compare_tree_fileids(self.branch, old_rev, new_rev)
270
        self.assertNotEqual(l2, l1)
1553.5.28 by Martin Pool
[merge] from bzr.dev before integration
271
        self.assertSubset(l2, l1)
1711.7.4 by John Arbash Meinel
Fix test_fileid_involved so it uses TreeTransform to set the executable bits rather than chmod()
272
273
274
def set_executability(wt, path, executable=True):
275
    """Set the executable bit for the file at path in the working tree
276
277
    os.chmod() doesn't work on windows. But TreeTransform can mark or
278
    unmark a file as executable.
279
    """
280
    file_id = wt.path2id(path)
281
    tt = TreeTransform(wt)
1711.7.5 by John Arbash Meinel
Call finalize() though it doesn't help to release resources to allow cleanup.
282
    try:
1711.7.15 by John Arbash Meinel
Properly handle the case when you want to turn off executability.
283
        tt.set_executability(executable, tt.trans_id_tree_file_id(file_id))
1711.7.5 by John Arbash Meinel
Call finalize() though it doesn't help to release resources to allow cleanup.
284
        tt.apply()
285
    finally:
286
        tt.finalize()