/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

Add RepositoryFormats and allow bzrdir.open or create _repository to be used.

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.clone import copy_branch
 
23
from bzrlib.delta import compare_trees
 
24
from bzrlib.fetch import greedy_fetch
 
25
from bzrlib.merge import merge_inner
 
26
from bzrlib.revision import common_ancestor
 
27
from bzrlib.tests import TestCaseWithTransport
 
28
from bzrlib.workingtree import WorkingTree
 
29
 
 
30
 
 
31
class TestFileIdInvolved(TestCaseWithTransport):
 
32
 
 
33
    def touch(self,filename):
 
34
        f = file(filename,"a")
 
35
        f.write("appended line\n")
 
36
        f.close( )
 
37
 
 
38
    def merge(self, branch_from, wt_to):
 
39
        # minimal ui-less merge.
 
40
        greedy_fetch(to_branch=wt_to.branch, from_branch=branch_from,
 
41
                     revision=branch_from.last_revision())
 
42
        base_rev = common_ancestor(branch_from.last_revision(),
 
43
                                    wt_to.branch.last_revision(),
 
44
                                    wt_to.branch.repository)
 
45
        merge_inner(wt_to.branch, branch_from.basis_tree(), 
 
46
                    wt_to.branch.repository.revision_tree(base_rev),
 
47
                    this_tree=wt_to)
 
48
        wt_to.add_pending_merge(branch_from.last_revision())
 
49
 
 
50
    def setUp(self):
 
51
        super(TestFileIdInvolved, self).setUp()
 
52
        # create three branches, and merge it
 
53
        #
 
54
        #           /-->J ------>K                (branch2)
 
55
        #          /              \
 
56
        #  A ---> B --->C ---->D->G               (main)
 
57
        #  \           /      /
 
58
        #   \---> E---/----> F                 (branch1)
 
59
 
 
60
        main_wt = self.make_branch_and_tree('main')
 
61
        main_branch = main_wt.branch
 
62
        self.build_tree(["main/a","main/b","main/c"])
 
63
 
 
64
        main_wt.add(['a', 'b', 'c'], ['a-file-id-2006-01-01-abcd',
 
65
                                 'b-file-id-2006-01-01-defg',
 
66
                                 'c-funky<file-id> quiji%bo'])
 
67
        main_wt.commit("Commit one", rev_id="rev-A")
 
68
        #-------- end A -----------
 
69
 
 
70
        b1 = main_branch.clone("branch1")
 
71
        self.build_tree(["branch1/d"])
 
72
        bt1 = WorkingTree('branch1', b1)
 
73
        bt1.add('d')
 
74
        bt1.commit("branch1, Commit one", rev_id="rev-E")
 
75
 
 
76
        #-------- end E -----------
 
77
 
 
78
        self.touch("main/a")
 
79
        main_wt.commit("Commit two", rev_id="rev-B")
 
80
 
 
81
        #-------- end B -----------
 
82
 
 
83
        branch2_branch = main_branch.clone("branch2")
 
84
        os.chmod("branch2/b",0770)
 
85
        bt2 = WorkingTree('branch2', branch2_branch)
 
86
        bt2.commit("branch2, Commit one", rev_id="rev-J")
 
87
 
 
88
        #-------- end J -----------
 
89
 
 
90
        self.merge(b1, main_wt)
 
91
        main_wt.commit("merge branch1, rev-11", rev_id="rev-C")
 
92
 
 
93
        #-------- end C -----------
 
94
 
 
95
        bt1.rename_one("d","e")
 
96
        bt1.commit("branch1, commit two", rev_id="rev-F")
 
97
 
 
98
        #-------- end F -----------
 
99
 
 
100
        self.touch("branch2/c")
 
101
        bt2.commit("branch2, commit two", rev_id="rev-K")
 
102
 
 
103
        #-------- end K -----------
 
104
 
 
105
        self.touch("main/b")
 
106
        self.merge(b1, main_wt)
 
107
        # D gets some funky characters to make sure the unescaping works
 
108
        main_wt.commit("merge branch1, rev-12", rev_id="rev-<D>")
 
109
 
 
110
        # end D
 
111
 
 
112
        self.merge(branch2_branch, main_wt)
 
113
        main_wt.commit("merge branch1, rev-22",  rev_id="rev-G")
 
114
 
 
115
        # end G
 
116
        self.branch = main_branch
 
117
 
 
118
 
 
119
    def test_fileid_involved_all_revs(self):
 
120
 
 
121
        l = self.branch.fileid_involved( )
 
122
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["a","b","c","d"])
 
123
 
 
124
    def test_fileid_involved_one_rev(self):
 
125
 
 
126
        l = self.branch.fileid_involved("rev-B" )
 
127
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["a","b","c"])
 
128
 
 
129
    def test_fileid_involved_two_revs(self):
 
130
 
 
131
        l = self.branch.fileid_involved_between_revs("rev-B","rev-K" )
 
132
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","c"])
 
133
 
 
134
        l = self.branch.fileid_involved_between_revs("rev-C","rev-<D>" )
 
135
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","d"])
 
136
 
 
137
        l = self.branch.fileid_involved_between_revs("rev-C","rev-G" )
 
138
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","c","d"])
 
139
 
 
140
        l = self.branch.fileid_involved_between_revs("rev-E","rev-G" )
 
141
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["a", "b","c","d"])
 
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.repository.revision_tree(history[start])
 
176
                new_tree = self.branch.repository.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
 
 
187