~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_fileid_involved.py

[merge] 0.7-bugfix: Fix fileid_involved to unescape xml characters, fix StubServer to handle paramiko > 1.5.2

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