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.clone import copy_branch
23
from bzrlib.merge import merge
24
from bzrlib.workingtree import WorkingTree
25
from bzrlib.delta import compare_trees
28
class TestFileIdInvolved(TestCaseInTempDir):
30
def touch(self,filename):
31
f = file(filename,"a")
32
f.write("appended line\n")
35
def merge( self, branch_from, force=False ):
36
from bzrlib.merge_core import ApplyMerge3
38
merge([branch_from,-1],[None,None], merge_type=ApplyMerge3,
39
check_clean=(not force) )
42
super(TestFileIdInvolved, self).setUp()
43
# create three branches, and merge it
45
# /-->J ------>K (branch2)
47
# A ---> B --->C ---->D->G (main)
49
# \---> E---/----> F (branch1)
54
main_branch = Branch.initialize('.')
55
self.build_tree(["a","b","c"])
59
wt.add(['a', 'b', 'c'], ['a-file-id-2006-01-01-abcd',
60
'b-file-id-2006-01-01-defg',
61
'c-funky<file-id> quiji%bo'])
62
commit(b, "Commit one", rev_id="rev-A")
64
#-------- end A -----------
66
copy_branch(main_branch,"../branch1")
67
os.chdir("../branch1")
69
#branch1_branch = Branch.open(".")
70
self.build_tree(["d"])
72
commit(Branch.open("."), "branch1, Commit one", rev_id="rev-E")
74
#-------- end E -----------
78
commit(Branch.open("."), "Commit two", rev_id="rev-B")
80
#-------- end B -----------
82
copy_branch(Branch.open("."),"../branch2")
83
os.chdir("../branch2")
85
branch2_branch = Branch.open(".")
87
commit(Branch.open("."), "branch2, Commit one", rev_id="rev-J")
89
#-------- end J -----------
93
self.merge("../branch1")
94
commit(Branch.open("."), "merge branch1, rev-11", rev_id="rev-C")
96
#-------- end C -----------
98
os.chdir("../branch1")
99
tree = WorkingTree('.', Branch.open("."))
100
tree.rename_one("d","e")
101
commit(Branch.open("."), "branch1, commit two", rev_id="rev-F")
104
#-------- end F -----------
106
os.chdir("../branch2")
109
commit(Branch.open("."), "branch2, commit two", rev_id="rev-K")
111
#-------- end K -----------
116
self.merge("../branch1",force=True)
118
# D gets some funky characters to make sure the unescaping works
119
commit(Branch.open("."), "merge branch1, rev-12", rev_id="rev-<D>")
123
self.merge("../branch2")
124
commit(Branch.open("."), "merge branch1, rev-22", rev_id="rev-G")
128
self.branch = Branch.open(".")
131
def test_fileid_involved_all_revs(self):
133
l = self.branch.fileid_involved( )
134
self.assertEquals( sorted(map( lambda x: x[0], l )), ["a","b","c","d"])
136
def test_fileid_involved_one_rev(self):
138
l = self.branch.fileid_involved("rev-B" )
139
self.assertEquals( sorted(map( lambda x: x[0], l )), ["a","b","c"])
141
def test_fileid_involved_two_revs(self):
143
l = self.branch.fileid_involved_between_revs("rev-B","rev-K" )
144
self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","c"])
146
l = self.branch.fileid_involved_between_revs("rev-C","rev-<D>" )
147
self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","d"])
149
l = self.branch.fileid_involved_between_revs("rev-C","rev-G" )
150
self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","c","d"])
152
l = self.branch.fileid_involved_between_revs("rev-E","rev-G" )
153
self.assertEquals( sorted(map( lambda x: x[0], l )), ["a", "b","c","d"])
155
def test_fileid_involved_sets(self):
157
l = self.branch.fileid_involved_by_set(set(["rev-B"]))
158
self.assertEquals( sorted(map( lambda x: x[0], l )), ["a"])
160
l = self.branch.fileid_involved_by_set(set(["rev-<D>"]))
161
self.assertEquals( sorted(map( lambda x: x[0], l )), ["b"])
163
def test_fileid_involved_compare(self):
165
l1 = self.branch.fileid_involved_between_revs("rev-E", "rev-<D>")
166
l2 = self.branch.fileid_involved_by_set(set(["rev-<D>","rev-F","rev-C","rev-B"]))
167
self.assertEquals( l1, l2 )
169
l1 = self.branch.fileid_involved_between_revs("rev-C", "rev-G")
170
l2 = self.branch.fileid_involved_by_set(
171
set(["rev-G","rev-<D>","rev-F","rev-K","rev-J"]))
172
self.assertEquals( l1, l2 )
174
def test_fileid_involved_full_compare(self):
175
from bzrlib.tsort import topo_sort
177
history = self.branch.revision_history( )
179
if len(history) < 2: return
181
for start in range(0,len(history)-1):
182
for end in range(start+1,len(history)):
184
l1 = self.branch.fileid_involved_between_revs(
185
history[start], history[end])
187
old_tree = self.branch.revision_tree(history[start])
188
new_tree = self.branch.revision_tree(history[end])
189
delta = compare_trees(old_tree, new_tree )
191
l2 = [ id for path, id, kind in delta.added ] + \
192
[ id for oldpath, newpath, id, kind, text_modified, \
193
meta_modified in delta.renamed ] + \
194
[ id for path, id, kind, text_modified, meta_modified in \
197
self.assertEquals( l1, set(l2) )