/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1540.1.7 by John Arbash Meinel
Added copyright statement to test_fileid_involved, and minor pep8 cleanup.
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
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
16
17
import os
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
18
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
19
from bzrlib.add import smart_add
20
from bzrlib.branch import Branch
1545.2.9 by Aaron Bentley
Moved merge.merge to builtins
21
from bzrlib.builtins import merge
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
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
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
27
from bzrlib.workingtree import WorkingTree
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
28
29
30
class TestFileIdInvolved(TestCaseWithTransport):
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
31
32
    def touch(self,filename):
33
        f = file(filename,"a")
34
        f.write("appended line\n")
35
        f.close( )
36
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
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(),
1534.4.28 by Robert Collins
first cut at merge from integration.
43
                                    wt_to.branch.repository)
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
44
        merge_inner(wt_to.branch, branch_from.working_tree(), 
1534.4.28 by Robert Collins
first cut at merge from integration.
45
                    wt_to.branch.repository.revision_tree(base_rev),
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
46
                    this_tree=wt_to)
47
        wt_to.add_pending_merge(branch_from.last_revision())
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
48
49
    def setUp(self):
1185.64.9 by Goffredo Baroncelli
renamed test_file_involved -> test_fileid_involved
50
        super(TestFileIdInvolved, self).setUp()
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
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
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
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',
1540.1.6 by John Arbash Meinel
fileid_involved needs to unescape the file id and revision id
64
                                 'b-file-id-2006-01-01-defg',
65
                                 'c-funky<file-id> quiji%bo'])
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
66
        main_wt.commit("Commit one", rev_id="rev-A")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
67
        #-------- end A -----------
68
1534.4.28 by Robert Collins
first cut at merge from integration.
69
        b1 = main_branch.clone("branch1")
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
70
        self.build_tree(["branch1/d"])
71
        b1.working_tree().add('d')
72
        b1.working_tree().commit("branch1, Commit one", rev_id="rev-E")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
73
74
        #-------- end E -----------
75
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
76
        self.touch("main/a")
77
        main_wt.commit("Commit two", rev_id="rev-B")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
78
79
        #-------- end B -----------
80
1534.4.28 by Robert Collins
first cut at merge from integration.
81
        branch2_branch = main_branch.clone("branch2")
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
82
        os.chmod("branch2/b",0770)
83
        branch2_branch.working_tree().commit("branch2, Commit one", 
84
                                             rev_id="rev-J")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
85
86
        #-------- end J -----------
87
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
88
        self.merge(b1, main_wt)
89
        main_wt.commit("merge branch1, rev-11", rev_id="rev-C")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
90
91
        #-------- end C -----------
92
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
93
        tree = WorkingTree('branch1', b1)
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
94
        tree.rename_one("d","e")
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
95
        tree.commit("branch1, commit two", rev_id="rev-F")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
96
97
        #-------- end F -----------
98
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
99
        self.touch("branch2/c")
100
        branch2_branch.working_tree().commit("branch2, commit two", rev_id="rev-K")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
101
102
        #-------- end K -----------
103
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
104
        self.touch("main/b")
105
        self.merge(b1, main_wt)
1540.1.6 by John Arbash Meinel
fileid_involved needs to unescape the file id and revision id
106
        # D gets some funky characters to make sure the unescaping works
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
107
        main_wt.commit("merge branch1, rev-12", rev_id="rev-<D>")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
108
109
        # end D
110
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
111
        self.merge(branch2_branch, main_wt)
112
        main_wt.commit("merge branch1, rev-22",  rev_id="rev-G")
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
113
114
        # end G
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
115
        self.branch = main_branch
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
116
117
1185.64.9 by Goffredo Baroncelli
renamed test_file_involved -> test_fileid_involved
118
    def test_fileid_involved_all_revs(self):
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
119
120
        l = self.branch.fileid_involved( )
121
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["a","b","c","d"])
122
1185.64.9 by Goffredo Baroncelli
renamed test_file_involved -> test_fileid_involved
123
    def test_fileid_involved_one_rev(self):
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
124
125
        l = self.branch.fileid_involved("rev-B" )
126
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["a","b","c"])
127
1185.64.9 by Goffredo Baroncelli
renamed test_file_involved -> test_fileid_involved
128
    def test_fileid_involved_two_revs(self):
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
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
1540.1.6 by John Arbash Meinel
fileid_involved needs to unescape the file id and revision id
133
        l = self.branch.fileid_involved_between_revs("rev-C","rev-<D>" )
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
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
1185.64.9 by Goffredo Baroncelli
renamed test_file_involved -> test_fileid_involved
142
    def test_fileid_involved_sets(self):
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
143
144
        l = self.branch.fileid_involved_by_set(set(["rev-B"]))
145
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["a"])
146
1540.1.6 by John Arbash Meinel
fileid_involved needs to unescape the file id and revision id
147
        l = self.branch.fileid_involved_by_set(set(["rev-<D>"]))
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
148
        self.assertEquals( sorted(map( lambda x: x[0], l )), ["b"])
149
1185.64.9 by Goffredo Baroncelli
renamed test_file_involved -> test_fileid_involved
150
    def test_fileid_involved_compare(self):
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
151
1540.1.6 by John Arbash Meinel
fileid_involved needs to unescape the file id and revision id
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"]))
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
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(
1540.1.6 by John Arbash Meinel
fileid_involved needs to unescape the file id and revision id
158
            set(["rev-G","rev-<D>","rev-F","rev-K","rev-J"]))
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
159
        self.assertEquals( l1, l2 )
160
1185.64.9 by Goffredo Baroncelli
renamed test_file_involved -> test_fileid_involved
161
    def test_fileid_involved_full_compare(self):
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
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
1185.65.30 by Robert Collins
Merge integration.
174
                old_tree = self.branch.repository.revision_tree(history[start])
175
                new_tree = self.branch.repository.revision_tree(history[end])
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
176
                delta = compare_trees(old_tree, new_tree )
177
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
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]
1185.64.7 by Goffredo Baroncelli
added test for function fileid_involved
183
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
184
                self.assertEquals(l1, set(l2))
1185.64.8 by Goffredo Baroncelli
small clean-up
185
1540.1.7 by John Arbash Meinel
Added copyright statement to test_fileid_involved, and minor pep8 cleanup.
186