~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_file_involved.py

 added test for function fileid_involved

Show diffs side-by-side

added added

removed removed

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