/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
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
21
from bzrlib.delta import compare_trees
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
22
from bzrlib.tests.repository_implementations.test_repository import TestCaseWithRepository
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
23
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.
24
1534.7.154 by Aaron Bentley
Removed changes from bzr.ab 1529..1536
25
1534.4.54 by Robert Collins
Merge from integration.
26
class FileIdInvolvedBase(TestCaseWithRepository):
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
27
28
    def touch(self,filename):
29
        f = file(filename,"a")
30
        f.write("appended line\n")
31
        f.close( )
32
1551.2.7 by Aaron Bentley
Test case for discrepancy between fileid_involved and compare_tree [recommit]
33
    def compare_tree_fileids(self, branch, old_rev, new_rev):
34
        old_tree = self.branch.repository.revision_tree(old_rev)
35
        new_tree = self.branch.repository.revision_tree(new_rev)
36
        delta = compare_trees(old_tree, new_tree)
37
38
        l2 = [id for path, id, kind in delta.added] + \
39
             [id for oldpath, newpath, id, kind, text_modified, \
40
                meta_modified in delta.renamed] + \
41
             [id for path, id, kind, text_modified, meta_modified in \
42
                delta.modified]
43
        return set(l2)
44
45
    
46
class TestFileIdInvolved(FileIdInvolvedBase):
47
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
48
    def setUp(self):
1185.64.9 by Goffredo Baroncelli
renamed test_file_involved -> test_fileid_involved
49
        super(TestFileIdInvolved, self).setUp()
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
50
        # create three branches, and merge it
51
        #
52
        #           /-->J ------>K                (branch2)
53
        #          /              \
54
        #  A ---> B --->C ---->D->G               (main)
55
        #  \           /      /
56
        #   \---> E---/----> F                 (branch1)
57
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
58
        main_wt = self.make_branch_and_tree('main')
59
        main_branch = main_wt.branch
60
        self.build_tree(["main/a","main/b","main/c"])
61
62
        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
63
                                 'b-file-id-2006-01-01-defg',
64
                                 'c-funky<file-id> quiji%bo'])
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
65
        main_wt.commit("Commit one", rev_id="rev-A")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
66
        #-------- end A -----------
67
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.
68
        d1 = main_branch.bzrdir.clone('branch1')
69
        b1 = d1.open_branch()
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
70
        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.
71
        bt1 = d1.open_workingtree()
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
72
        bt1.add('d')
73
        bt1.commit("branch1, Commit one", rev_id="rev-E")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
74
75
        #-------- end E -----------
76
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
77
        self.touch("main/a")
78
        main_wt.commit("Commit two", rev_id="rev-B")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
79
80
        #-------- end B -----------
81
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.
82
        d2 = main_branch.bzrdir.clone('branch2')
83
        branch2_branch = d2.open_branch()
84
        bt2 = d2.open_workingtree()
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
85
        os.chmod("branch2/b",0770)
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
86
        bt2.commit("branch2, Commit one", rev_id="rev-J")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
87
88
        #-------- end J -----------
89
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
90
        self.merge(b1, main_wt)
91
        main_wt.commit("merge branch1, rev-11", rev_id="rev-C")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
92
93
        #-------- end C -----------
94
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
95
        bt1.rename_one("d","e")
96
        bt1.commit("branch1, commit two", rev_id="rev-F")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
97
98
        #-------- end F -----------
99
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
100
        self.touch("branch2/c")
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
101
        bt2.commit("branch2, commit two", rev_id="rev-K")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
102
103
        #-------- end K -----------
104
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
105
        self.touch("main/b")
106
        self.merge(b1, main_wt)
1540.1.6 by John Arbash Meinel
fileid_involved needs to unescape the file id and revision id
107
        # 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.
108
        main_wt.commit("merge branch1, rev-12", rev_id="rev-<D>")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
109
110
        # end D
111
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
112
        self.merge(branch2_branch, main_wt)
113
        main_wt.commit("merge branch1, rev-22",  rev_id="rev-G")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
114
115
        # end G
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
116
        self.branch = main_branch
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
117
118
1185.64.9 by Goffredo Baroncelli
renamed test_file_involved -> test_fileid_involved
119
    def test_fileid_involved_all_revs(self):
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
120
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
121
        l = self.branch.repository.fileid_involved( )
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
122
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["a","b","c","d"])
123
1185.64.9 by Goffredo Baroncelli
renamed test_file_involved -> test_fileid_involved
124
    def test_fileid_involved_one_rev(self):
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
125
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
126
        l = self.branch.repository.fileid_involved("rev-B" )
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
127
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["a","b","c"])
128
1185.64.9 by Goffredo Baroncelli
renamed test_file_involved -> test_fileid_involved
129
    def test_fileid_involved_two_revs(self):
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
130
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
131
        l = self.branch.repository.fileid_involved_between_revs("rev-B","rev-K" )
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
132
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","c"])
133
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
134
        l = self.branch.repository.fileid_involved_between_revs("rev-C","rev-<D>" )
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
135
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","d"])
136
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
137
        l = self.branch.repository.fileid_involved_between_revs("rev-C","rev-G" )
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
138
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","c","d"])
139
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
140
        l = self.branch.repository.fileid_involved_between_revs("rev-E","rev-G" )
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
141
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["a", "b","c","d"])
142
1185.64.9 by Goffredo Baroncelli
renamed test_file_involved -> test_fileid_involved
143
    def test_fileid_involved_sets(self):
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
144
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
145
        l = self.branch.repository.fileid_involved_by_set(set(["rev-B"]))
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
146
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["a"])
147
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
148
        l = self.branch.repository.fileid_involved_by_set(set(["rev-<D>"]))
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
149
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["b"])
150
1185.64.9 by Goffredo Baroncelli
renamed test_file_involved -> test_fileid_involved
151
    def test_fileid_involved_compare(self):
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
152
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
153
        l1 = self.branch.repository.fileid_involved_between_revs("rev-E", "rev-<D>")
154
        l2 = self.branch.repository.fileid_involved_by_set(set(["rev-<D>","rev-F","rev-C","rev-B"]))
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
155
        self.assertEquals( l1, l2 )
156
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
157
        l1 = self.branch.repository.fileid_involved_between_revs("rev-C", "rev-G")
158
        l2 = self.branch.repository.fileid_involved_by_set(
1540.1.6 by John Arbash Meinel
fileid_involved needs to unescape the file id and revision id
159
            set(["rev-G","rev-<D>","rev-F","rev-K","rev-J"]))
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
160
        self.assertEquals( l1, l2 )
161
1185.64.9 by Goffredo Baroncelli
renamed test_file_involved -> test_fileid_involved
162
    def test_fileid_involved_full_compare(self):
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
163
        pp=[]
164
        history = self.branch.revision_history( )
165
166
        if len(history) < 2: return
167
168
        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]
169
            start_id = history[start]
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
170
            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]
171
                end_id = history[end]
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
172
                l1 = self.branch.repository.fileid_involved_between_revs(
1534.4.54 by Robert Collins
Merge from integration.
173
                    start_id, end_id)
1551.2.7 by Aaron Bentley
Test case for discrepancy between fileid_involved and compare_tree [recommit]
174
                l2 = self.compare_tree_fileids(self.branch, start_id, end_id)
175
                self.assertEquals(l1, l2)
176
177
178
class TestFileIdInvolvedSuperset(FileIdInvolvedBase):
179
180
    def setUp(self):
181
        super(TestFileIdInvolvedSuperset, self).setUp()
182
183
        main_wt = self.make_branch_and_tree('main')
184
        main_branch = main_wt.branch
185
        self.build_tree(["main/a","main/b","main/c"])
186
187
        main_wt.add(['a', 'b', 'c'], ['a-file-id-2006-01-01-abcd',
188
                                 'b-file-id-2006-01-01-defg',
189
                                 'c-funky<file-id> quiji%bo'])
190
        main_wt.commit("Commit one", rev_id="rev-A")
191
1534.5.3 by Robert Collins
Make format 4/5/6 branches share a single LockableFiles instance across wt/branch/repository.
192
        branch2_bzrdir = main_branch.bzrdir.sprout("branch2")
193
        branch2_branch = branch2_bzrdir.open_branch()
194
        branch2_wt = branch2_bzrdir.open_workingtree()
1551.2.7 by Aaron Bentley
Test case for discrepancy between fileid_involved and compare_tree [recommit]
195
        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.
196
        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]
197
198
        self.merge(branch2_branch, main_wt)
199
        os.chmod("main/b",0660)
200
        main_wt.commit("merge branch1, rev-22",  rev_id="rev-G")
201
202
        # end G
203
        self.branch = main_branch
204
205
    def test_fileid_involved_full_compare2(self):
206
        history = self.branch.revision_history()
207
        old_rev = history[0]
208
        new_rev = history[1]
209
1534.4.54 by Robert Collins
Merge from integration.
210
        l1 = self.branch.repository.fileid_involved_between_revs(old_rev, new_rev)
1551.2.7 by Aaron Bentley
Test case for discrepancy between fileid_involved and compare_tree [recommit]
211
212
        l2 = self.compare_tree_fileids(self.branch, old_rev, new_rev)
213
        self.assertNotEqual(l2, l1)
1553.5.28 by Martin Pool
[merge] from bzr.dev before integration
214
        self.assertSubset(l2, l1)