1
# Copyright (C) 2005 by Canonical Ltd
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.
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.
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
17
from bzrlib.tests import TestCaseInTempDir
19
from bzrlib.commit import commit
20
from bzrlib.add import smart_add
21
from bzrlib.branch import Branch
22
from bzrlib.merge import merge
23
from bzrlib.workingtree import WorkingTree
24
from bzrlib.delta import compare_trees
27
class TestFileIdInvolved(TestCaseInTempDir):
29
def touch(self,filename):
30
f = file(filename,"a")
31
f.write("appended line\n")
34
def merge( self, branch_from, force=False ):
35
from bzrlib.merge_core import ApplyMerge3
37
merge([branch_from,-1],[None,None], merge_type=ApplyMerge3,
38
check_clean=(not force) )
41
super(TestFileIdInvolved, self).setUp()
42
# create three branches, and merge it
44
# /-->J ------>K (branch2)
46
# A ---> B --->C ---->D->G (main)
48
# \---> E---/----> F (branch1)
53
main_branch = Branch.initialize('.')
54
self.build_tree(["a","b","c"])
58
wt.add(['a', 'b', 'c'], ['a-file-id-2006-01-01-abcd',
59
'b-file-id-2006-01-01-defg',
60
'c-funky<file-id> quiji%bo'])
61
commit(b, "Commit one", rev_id="rev-A")
63
#-------- end A -----------
65
main_branch.clone("../branch1")
66
os.chdir("../branch1")
68
#branch1_branch = Branch.open(".")
69
self.build_tree(["d"])
71
commit(Branch.open("."), "branch1, Commit one", rev_id="rev-E")
73
#-------- end E -----------
77
commit(Branch.open("."), "Commit two", rev_id="rev-B")
79
#-------- end B -----------
81
Branch.open(".").clone("../branch2")
82
os.chdir("../branch2")
84
branch2_branch = Branch.open(".")
86
commit(Branch.open("."), "branch2, Commit one", rev_id="rev-J")
88
#-------- end J -----------
92
self.merge("../branch1")
93
commit(Branch.open("."), "merge branch1, rev-11", rev_id="rev-C")
95
#-------- end C -----------
97
os.chdir("../branch1")
98
tree = WorkingTree('.', Branch.open("."))
99
tree.rename_one("d","e")
100
commit(Branch.open("."), "branch1, commit two", rev_id="rev-F")
103
#-------- end F -----------
105
os.chdir("../branch2")
108
commit(Branch.open("."), "branch2, commit two", rev_id="rev-K")
110
#-------- end K -----------
115
self.merge("../branch1",force=True)
117
# D gets some funky characters to make sure the unescaping works
118
commit(Branch.open("."), "merge branch1, rev-12", rev_id="rev-<D>")
122
self.merge("../branch2")
123
commit(Branch.open("."), "merge branch1, rev-22", rev_id="rev-G")
127
self.branch = Branch.open(".")
130
def test_fileid_involved_all_revs(self):
132
l = self.branch.fileid_involved( )
133
self.assertEquals( sorted(map( lambda x: x[0], l )), ["a","b","c","d"])
135
def test_fileid_involved_one_rev(self):
137
l = self.branch.fileid_involved("rev-B" )
138
self.assertEquals( sorted(map( lambda x: x[0], l )), ["a","b","c"])
140
def test_fileid_involved_two_revs(self):
142
l = self.branch.fileid_involved_between_revs("rev-B","rev-K" )
143
self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","c"])
145
l = self.branch.fileid_involved_between_revs("rev-C","rev-<D>" )
146
self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","d"])
148
l = self.branch.fileid_involved_between_revs("rev-C","rev-G" )
149
self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","c","d"])
151
l = self.branch.fileid_involved_between_revs("rev-E","rev-G" )
152
self.assertEquals( sorted(map( lambda x: x[0], l )), ["a", "b","c","d"])
154
def test_fileid_involved_sets(self):
156
l = self.branch.fileid_involved_by_set(set(["rev-B"]))
157
self.assertEquals( sorted(map( lambda x: x[0], l )), ["a"])
159
l = self.branch.fileid_involved_by_set(set(["rev-<D>"]))
160
self.assertEquals( sorted(map( lambda x: x[0], l )), ["b"])
162
def test_fileid_involved_compare(self):
164
l1 = self.branch.fileid_involved_between_revs("rev-E", "rev-<D>")
165
l2 = self.branch.fileid_involved_by_set(set(["rev-<D>","rev-F","rev-C","rev-B"]))
166
self.assertEquals( l1, l2 )
168
l1 = self.branch.fileid_involved_between_revs("rev-C", "rev-G")
169
l2 = self.branch.fileid_involved_by_set(
170
set(["rev-G","rev-<D>","rev-F","rev-K","rev-J"]))
171
self.assertEquals( l1, l2 )
173
def test_fileid_involved_full_compare(self):
174
from bzrlib.tsort import topo_sort
176
history = self.branch.revision_history( )
178
if len(history) < 2: return
180
for start in range(0,len(history)-1):
181
for end in range(start+1,len(history)):
183
l1 = self.branch.fileid_involved_between_revs(
184
history[start], history[end])
186
old_tree = self.branch.repository.revision_tree(history[start])
187
new_tree = self.branch.repository.revision_tree(history[end])
188
delta = compare_trees(old_tree, new_tree )
190
l2 = [ id for path, id, kind in delta.added ] + \
191
[ id for oldpath, newpath, id, kind, text_modified, \
192
meta_modified in delta.renamed ] + \
193
[ id for path, id, kind, text_modified, meta_modified in \
196
self.assertEquals( l1, set(l2) )