/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_fileid_involved.py

Merge integration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
16
 
 
17
from bzrlib.tests import TestCaseInTempDir
 
18
import os
 
19
from bzrlib.commit import commit
 
20
from bzrlib.add import smart_add
 
21
from bzrlib.branch import Branch
 
22
from bzrlib.merge import merge
 
23
from bzrlib.workingtree import WorkingTree
 
24
from bzrlib.delta import compare_trees
 
25
 
 
26
 
 
27
class TestFileIdInvolved(TestCaseInTempDir):
 
28
 
 
29
    def touch(self,filename):
 
30
        f = file(filename,"a")
 
31
        f.write("appended line\n")
 
32
        f.close( )
 
33
 
 
34
    def merge( self, branch_from, force=False ):
 
35
        from bzrlib.merge_core import ApplyMerge3
 
36
 
 
37
        merge([branch_from,-1],[None,None], merge_type=ApplyMerge3,
 
38
            check_clean=(not force) )
 
39
 
 
40
    def setUp(self):
 
41
        super(TestFileIdInvolved, self).setUp()
 
42
        # create three branches, and merge it
 
43
        #
 
44
        #           /-->J ------>K                (branch2)
 
45
        #          /              \
 
46
        #  A ---> B --->C ---->D->G               (main)
 
47
        #  \           /      /
 
48
        #   \---> E---/----> F                 (branch1)
 
49
 
 
50
        os.mkdir("main")
 
51
        os.chdir("main")
 
52
 
 
53
        main_branch = Branch.initialize('.')
 
54
        self.build_tree(["a","b","c"])
 
55
 
 
56
        b = Branch.open('.')
 
57
        wt = b.working_tree()
 
58
        wt.add(['a', 'b', 'c'], ['a-file-id-2006-01-01-abcd',
 
59
                                 'b-file-id-2006-01-01-defg',
 
60
                                 'c-funky<file-id> quiji%bo'])
 
61
        commit(b, "Commit one", rev_id="rev-A")
 
62
        del b, wt
 
63
        #-------- end A -----------
 
64
 
 
65
        main_branch.clone("../branch1")
 
66
        os.chdir("../branch1")
 
67
 
 
68
        #branch1_branch = Branch.open(".")
 
69
        self.build_tree(["d"])
 
70
        smart_add(".")
 
71
        commit(Branch.open("."), "branch1, Commit one", rev_id="rev-E")
 
72
 
 
73
        #-------- end E -----------
 
74
 
 
75
        os.chdir("../main")
 
76
        self.touch("a")
 
77
        commit(Branch.open("."), "Commit two", rev_id="rev-B")
 
78
 
 
79
        #-------- end B -----------
 
80
 
 
81
        Branch.open(".").clone("../branch2")
 
82
        os.chdir("../branch2")
 
83
 
 
84
        branch2_branch = Branch.open(".")
 
85
        os.chmod("b",0770)
 
86
        commit(Branch.open("."), "branch2, Commit one", rev_id="rev-J")
 
87
 
 
88
        #-------- end J -----------
 
89
 
 
90
        os.chdir("../main")
 
91
 
 
92
        self.merge("../branch1")
 
93
        commit(Branch.open("."), "merge branch1, rev-11", rev_id="rev-C")
 
94
 
 
95
        #-------- end C -----------
 
96
 
 
97
        os.chdir("../branch1")
 
98
        tree = WorkingTree('.', Branch.open("."))
 
99
        tree.rename_one("d","e")
 
100
        commit(Branch.open("."), "branch1, commit two", rev_id="rev-F")
 
101
 
 
102
 
 
103
        #-------- end F -----------
 
104
 
 
105
        os.chdir("../branch2")
 
106
 
 
107
        self.touch("c")
 
108
        commit(Branch.open("."), "branch2, commit two", rev_id="rev-K")
 
109
 
 
110
        #-------- end K -----------
 
111
 
 
112
        os.chdir("../main")
 
113
 
 
114
        self.touch("b")
 
115
        self.merge("../branch1",force=True)
 
116
 
 
117
        # D gets some funky characters to make sure the unescaping works
 
118
        commit(Branch.open("."), "merge branch1, rev-12", rev_id="rev-<D>")
 
119
 
 
120
        # end D
 
121
 
 
122
        self.merge("../branch2")
 
123
        commit(Branch.open("."), "merge branch1, rev-22",  rev_id="rev-G")
 
124
 
 
125
        # end G
 
126
        os.chdir("../main")
 
127
        self.branch = Branch.open(".")
 
128
 
 
129
 
 
130
    def test_fileid_involved_all_revs(self):
 
131
 
 
132
        l = self.branch.fileid_involved( )
 
133
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["a","b","c","d"])
 
134
 
 
135
    def test_fileid_involved_one_rev(self):
 
136
 
 
137
        l = self.branch.fileid_involved("rev-B" )
 
138
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["a","b","c"])
 
139
 
 
140
    def test_fileid_involved_two_revs(self):
 
141
 
 
142
        l = self.branch.fileid_involved_between_revs("rev-B","rev-K" )
 
143
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","c"])
 
144
 
 
145
        l = self.branch.fileid_involved_between_revs("rev-C","rev-<D>" )
 
146
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","d"])
 
147
 
 
148
        l = self.branch.fileid_involved_between_revs("rev-C","rev-G" )
 
149
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","c","d"])
 
150
 
 
151
        l = self.branch.fileid_involved_between_revs("rev-E","rev-G" )
 
152
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["a", "b","c","d"])
 
153
 
 
154
    def test_fileid_involved_sets(self):
 
155
 
 
156
        l = self.branch.fileid_involved_by_set(set(["rev-B"]))
 
157
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["a"])
 
158
 
 
159
        l = self.branch.fileid_involved_by_set(set(["rev-<D>"]))
 
160
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["b"])
 
161
 
 
162
    def test_fileid_involved_compare(self):
 
163
 
 
164
        l1 = self.branch.fileid_involved_between_revs("rev-E", "rev-<D>")
 
165
        l2 = self.branch.fileid_involved_by_set(set(["rev-<D>","rev-F","rev-C","rev-B"]))
 
166
        self.assertEquals( l1, l2 )
 
167
 
 
168
        l1 = self.branch.fileid_involved_between_revs("rev-C", "rev-G")
 
169
        l2 = self.branch.fileid_involved_by_set(
 
170
            set(["rev-G","rev-<D>","rev-F","rev-K","rev-J"]))
 
171
        self.assertEquals( l1, l2 )
 
172
 
 
173
    def test_fileid_involved_full_compare(self):
 
174
        from bzrlib.tsort import topo_sort
 
175
        pp=[]
 
176
        history = self.branch.revision_history( )
 
177
 
 
178
        if len(history) < 2: return
 
179
 
 
180
        for start in range(0,len(history)-1):
 
181
            for end in range(start+1,len(history)):
 
182
 
 
183
                l1 = self.branch.fileid_involved_between_revs(
 
184
                    history[start], history[end])
 
185
 
 
186
                old_tree = self.branch.repository.revision_tree(history[start])
 
187
                new_tree = self.branch.repository.revision_tree(history[end])
 
188
                delta = compare_trees(old_tree, new_tree )
 
189
 
 
190
                l2 = [ id for path, id, kind in delta.added ] + \
 
191
                     [ id for oldpath, newpath, id, kind, text_modified, \
 
192
                            meta_modified in delta.renamed ] + \
 
193
                     [ id for path, id, kind, text_modified, meta_modified in \
 
194
                            delta.modified ]
 
195
 
 
196
                self.assertEquals( l1, set(l2) )
 
197
 
 
198