4
from bzrlib.tests import TestCaseInTempDir
6
from bzrlib.commit import commit
7
from bzrlib.add import smart_add
8
from bzrlib.branch import Branch
9
from bzrlib.clone import copy_branch
10
from bzrlib.merge import merge
11
from bzrlib.workingtree import WorkingTree
12
from bzrlib.delta import compare_trees
14
class TestFileInvolved(TestCaseInTempDir):
16
def touch(self,filename):
17
f = file(filename,"a")
18
f.write("appended line\n")
22
def merge( self, branch_from, force=False ):
23
from bzrlib.merge_core import ApplyMerge3
25
merge([branch_from,-1],[None,None], merge_type=ApplyMerge3,
26
check_clean=(not force) )
29
super(TestFileInvolved, self).setUp()
30
# create three branches, and merge it
32
# /-->J ------>K (branch2)
34
# A ---> B --->C ---->D->G (main)
36
# \---> E---/----> F (branch1)
41
main_branch = Branch.initialize('.')
42
self.build_tree(["a","b","c"])
45
commit(Branch.open("."), "Commit one", rev_id="rev-A")
46
#-------- end A -----------
48
copy_branch(main_branch,"../branch1")
49
os.chdir("../branch1")
51
#branch1_branch = Branch.open(".")
52
self.build_tree(["d"])
54
commit(Branch.open("."), "branch1, Commit one", rev_id="rev-E")
56
#-------- end E -----------
60
commit(Branch.open("."), "Commit two", rev_id="rev-B")
62
#-------- end B -----------
64
copy_branch(Branch.open("."),"../branch2")
65
os.chdir("../branch2")
67
branch2_branch = Branch.open(".")
69
commit(Branch.open("."), "branch2, Commit one", rev_id="rev-J")
71
#-------- end J -----------
75
self.merge("../branch1")
76
commit(Branch.open("."), "merge branch1, rev-11", rev_id="rev-C")
78
#-------- end C -----------
80
os.chdir("../branch1")
81
tree = WorkingTree('.', Branch.open("."))
82
tree.rename_one("d","e")
83
commit(Branch.open("."), "branch1, commit two", rev_id="rev-F")
86
#-------- end F -----------
88
os.chdir("../branch2")
92
commit(Branch.open("."), "branch2, commit two", rev_id="rev-K")
94
#-------- end K -----------
99
self.merge("../branch1",force=True)
101
commit(Branch.open("."), "merge branch1, rev-12", rev_id="rev-D")
105
self.merge("../branch2")
106
commit(Branch.open("."), "merge branch1, rev-22", rev_id="rev-G")
110
self.branch = Branch.open(".")
113
def test_file_involved_all_revs(self):
115
l = self.branch.fileid_involved( )
116
self.assertEquals( sorted(map( lambda x: x[0], l )), ["a","b","c","d"])
118
def test_file_involved_one_rev(self):
120
l = self.branch.fileid_involved("rev-B" )
121
self.assertEquals( sorted(map( lambda x: x[0], l )), ["a","b","c"])
123
def test_file_involved_two_revs(self):
125
l = self.branch.fileid_involved_between_revs("rev-B","rev-K" )
126
self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","c"])
128
l = self.branch.fileid_involved_between_revs("rev-C","rev-D" )
129
self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","d"])
131
l = self.branch.fileid_involved_between_revs("rev-C","rev-G" )
132
self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","c","d"])
134
l = self.branch.fileid_involved_between_revs("rev-E","rev-G" )
135
self.assertEquals( sorted(map( lambda x: x[0], l )), ["a", "b","c","d"])
138
def test_file_involved_sets(self):
140
l = self.branch.fileid_involved_by_set(set(["rev-B"]))
141
self.assertEquals( sorted(map( lambda x: x[0], l )), ["a"])
143
l = self.branch.fileid_involved_by_set(set(["rev-D"]))
144
self.assertEquals( sorted(map( lambda x: x[0], l )), ["b"])
146
def test_file_involved_compare(self):
148
l1 = self.branch.fileid_involved_between_revs("rev-E", "rev-D")
149
l2 = self.branch.fileid_involved_by_set(set(["rev-D","rev-F","rev-C","rev-B"]))
150
self.assertEquals( l1, l2 )
152
l1 = self.branch.fileid_involved_between_revs("rev-C", "rev-G")
153
l2 = self.branch.fileid_involved_by_set(
154
set(["rev-G","rev-D","rev-F","rev-K","rev-J"]))
155
self.assertEquals( l1, l2 )
157
def test_file_involved_full_compare(self):
158
from bzrlib.tsort import topo_sort
160
history = self.branch.revision_history( )
162
if len(history) < 2: return
164
for start in range(0,len(history)-1):
165
for end in range(start+1,len(history)):
167
l1 = self.branch.fileid_involved_between_revs(
168
history[start], history[end])
170
old_tree = self.branch.revision_tree(history[start])
171
new_tree = self.branch.revision_tree(history[end])
172
delta = compare_trees(old_tree, new_tree )
174
l2 = [ id for path, id, kind in delta.added ] + \
175
[ id for oldpath, newpath, id, kind, text_modified, \
176
meta_modified in delta.renamed ] + \
177
[ id for path, id, kind, text_modified, meta_modified in \
180
self.assertEquals( l1, set(l2) )
b'\\ No newline at end of file'