~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_fileid_involved.py

update TODO

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.clone import copy_branch
 
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
 
 
30
class TestFileIdInvolved(TestCaseWithTransport):
 
31
 
 
32
    def touch(self,filename):
 
33
        f = file(filename,"a")
 
34
        f.write("appended line\n")
 
35
        f.close( )
 
36
 
 
37
    def merge(self, branch_from, wt_to):
 
38
        # minimal ui-less merge.
 
39
        greedy_fetch(to_branch=wt_to.branch, from_branch=branch_from,
 
40
                     revision=branch_from.last_revision())
 
41
        base_rev = common_ancestor(branch_from.last_revision(),
 
42
                                    wt_to.branch.last_revision(),
 
43
                                    wt_to.branch)
 
44
        merge_inner(wt_to.branch, branch_from.working_tree(), 
 
45
                    wt_to.branch.revision_tree(base_rev),
 
46
                    this_tree=wt_to)
 
47
        wt_to.add_pending_merge(branch_from.last_revision())
 
48
 
 
49
    def setUp(self):
 
50
        super(TestFileIdInvolved, self).setUp()
 
51
        # create three branches, and merge it
 
52
        #
 
53
        #           /-->J ------>K                (branch2)
 
54
        #          /              \
 
55
        #  A ---> B --->C ---->D->G               (main)
 
56
        #  \           /      /
 
57
        #   \---> E---/----> F                 (branch1)
 
58
 
 
59
        main_wt = self.make_branch_and_tree('main')
 
60
        main_branch = main_wt.branch
 
61
        self.build_tree(["main/a","main/b","main/c"])
 
62
 
 
63
        main_wt.add(['a', 'b', 'c'], ['a-file-id-2006-01-01-abcd',
 
64
                                 'b-file-id-2006-01-01-defg',
 
65
                                 'c-funky<file-id> quiji%bo'])
 
66
        main_wt.commit("Commit one", rev_id="rev-A")
 
67
        #-------- end A -----------
 
68
 
 
69
        b1 = copy_branch(main_branch, "branch1")
 
70
        self.build_tree(["branch1/d"])
 
71
        b1.working_tree().add('d')
 
72
        b1.working_tree().commit("branch1, Commit one", rev_id="rev-E")
 
73
 
 
74
        #-------- end E -----------
 
75
 
 
76
        self.touch("main/a")
 
77
        main_wt.commit("Commit two", rev_id="rev-B")
 
78
 
 
79
        #-------- end B -----------
 
80
 
 
81
        branch2_branch = copy_branch(main_branch, "branch2")
 
82
        os.chmod("branch2/b",0770)
 
83
        branch2_branch.working_tree().commit("branch2, Commit one", 
 
84
                                             rev_id="rev-J")
 
85
 
 
86
        #-------- end J -----------
 
87
 
 
88
        self.merge(b1, main_wt)
 
89
        main_wt.commit("merge branch1, rev-11", rev_id="rev-C")
 
90
 
 
91
        #-------- end C -----------
 
92
 
 
93
        tree = WorkingTree('branch1', b1)
 
94
        tree.rename_one("d","e")
 
95
        tree.commit("branch1, commit two", rev_id="rev-F")
 
96
 
 
97
        #-------- end F -----------
 
98
 
 
99
        self.touch("branch2/c")
 
100
        branch2_branch.working_tree().commit("branch2, commit two", rev_id="rev-K")
 
101
 
 
102
        #-------- end K -----------
 
103
 
 
104
        self.touch("main/b")
 
105
        self.merge(b1, main_wt)
 
106
        # D gets some funky characters to make sure the unescaping works
 
107
        main_wt.commit("merge branch1, rev-12", rev_id="rev-<D>")
 
108
 
 
109
        # end D
 
110
 
 
111
        self.merge(branch2_branch, main_wt)
 
112
        main_wt.commit("merge branch1, rev-22",  rev_id="rev-G")
 
113
 
 
114
        # end G
 
115
        self.branch = main_branch
 
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
    def test_fileid_involved_sets(self):
 
143
 
 
144
        l = self.branch.fileid_involved_by_set(set(["rev-B"]))
 
145
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["a"])
 
146
 
 
147
        l = self.branch.fileid_involved_by_set(set(["rev-<D>"]))
 
148
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["b"])
 
149
 
 
150
    def test_fileid_involved_compare(self):
 
151
 
 
152
        l1 = self.branch.fileid_involved_between_revs("rev-E", "rev-<D>")
 
153
        l2 = self.branch.fileid_involved_by_set(set(["rev-<D>","rev-F","rev-C","rev-B"]))
 
154
        self.assertEquals( l1, l2 )
 
155
 
 
156
        l1 = self.branch.fileid_involved_between_revs("rev-C", "rev-G")
 
157
        l2 = self.branch.fileid_involved_by_set(
 
158
            set(["rev-G","rev-<D>","rev-F","rev-K","rev-J"]))
 
159
        self.assertEquals( l1, l2 )
 
160
 
 
161
    def test_fileid_involved_full_compare(self):
 
162
        from bzrlib.tsort import topo_sort
 
163
        pp=[]
 
164
        history = self.branch.revision_history( )
 
165
 
 
166
        if len(history) < 2: return
 
167
 
 
168
        for start in range(0,len(history)-1):
 
169
            for end in range(start+1,len(history)):
 
170
 
 
171
                l1 = self.branch.fileid_involved_between_revs(
 
172
                    history[start], history[end])
 
173
 
 
174
                old_tree = self.branch.revision_tree(history[start])
 
175
                new_tree = self.branch.revision_tree(history[end])
 
176
                delta = compare_trees(old_tree, new_tree )
 
177
 
 
178
                l2 = [id for path, id, kind in delta.added] + \
 
179
                     [id for oldpath, newpath, id, kind, text_modified, \
 
180
                        meta_modified in delta.renamed] + \
 
181
                     [id for path, id, kind, text_modified, meta_modified in \
 
182
                        delta.modified]
 
183
 
 
184
                self.assertEquals(l1, set(l2))
 
185
 
 
186