/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

  • Committer: John Arbash Meinel
  • Date: 2006-01-19 21:25:01 UTC
  • mto: (1185.50.49 bzr-jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1549.
  • Revision ID: john@arbash-meinel.com-20060119212501-cb28cf532a878c41
fileid_involved needs to unescape the file id and revision id

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