/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-02-15 15:42:09 UTC
  • mto: (1185.79.1 bzr-jam-pending)
  • mto: This revision was merged to the branch mainline in revision 1554.
  • Revision ID: john@arbash-meinel.com-20060215154209-1db9dff063341810
Adding sign-my-commits as a builtin, along with some simple tests.

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