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
19
from bzrlib.add import smart_add
20
from bzrlib.branch import Branch
21
from bzrlib.builtins import merge
22
from bzrlib.clone import copy_branch
23
from bzrlib.delta import compare_trees
24
from bzrlib.fetch import greedy_fetch
25
from bzrlib.merge import merge_inner
26
from bzrlib.revision import common_ancestor
27
from bzrlib.tests import TestCaseWithTransport
28
from bzrlib.workingtree import WorkingTree
31
class TestFileIdInvolved(TestCaseWithTransport):
33
def touch(self,filename):
34
f = file(filename,"a")
35
f.write("appended line\n")
38
def merge(self, branch_from, wt_to):
39
# minimal ui-less merge.
40
greedy_fetch(to_branch=wt_to.branch, from_branch=branch_from,
41
revision=branch_from.last_revision())
42
base_rev = common_ancestor(branch_from.last_revision(),
43
wt_to.branch.last_revision(),
44
wt_to.branch.repository)
45
merge_inner(wt_to.branch, branch_from.basis_tree(),
46
wt_to.branch.repository.revision_tree(base_rev),
48
wt_to.add_pending_merge(branch_from.last_revision())
51
super(TestFileIdInvolved, self).setUp()
52
# create three branches, and merge it
54
# /-->J ------>K (branch2)
56
# A ---> B --->C ---->D->G (main)
58
# \---> E---/----> F (branch1)
60
main_wt = self.make_branch_and_tree('main')
61
main_branch = main_wt.branch
62
self.build_tree(["main/a","main/b","main/c"])
64
main_wt.add(['a', 'b', 'c'], ['a-file-id-2006-01-01-abcd',
65
'b-file-id-2006-01-01-defg',
66
'c-funky<file-id> quiji%bo'])
67
main_wt.commit("Commit one", rev_id="rev-A")
68
#-------- end A -----------
70
b1 = main_branch.clone("branch1")
71
self.build_tree(["branch1/d"])
72
bt1 = WorkingTree('branch1', b1)
74
bt1.commit("branch1, Commit one", rev_id="rev-E")
76
#-------- end E -----------
79
main_wt.commit("Commit two", rev_id="rev-B")
81
#-------- end B -----------
83
branch2_branch = main_branch.clone("branch2")
84
os.chmod("branch2/b",0770)
85
bt2 = WorkingTree('branch2', branch2_branch)
86
bt2.commit("branch2, Commit one", rev_id="rev-J")
88
#-------- end J -----------
90
self.merge(b1, main_wt)
91
main_wt.commit("merge branch1, rev-11", rev_id="rev-C")
93
#-------- end C -----------
95
bt1.rename_one("d","e")
96
bt1.commit("branch1, commit two", rev_id="rev-F")
98
#-------- end F -----------
100
self.touch("branch2/c")
101
bt2.commit("branch2, commit two", rev_id="rev-K")
103
#-------- end K -----------
106
self.merge(b1, main_wt)
107
# D gets some funky characters to make sure the unescaping works
108
main_wt.commit("merge branch1, rev-12", rev_id="rev-<D>")
112
self.merge(branch2_branch, main_wt)
113
main_wt.commit("merge branch1, rev-22", rev_id="rev-G")
116
self.branch = main_branch
119
def test_fileid_involved_all_revs(self):
121
l = self.branch.fileid_involved( )
122
self.assertEquals( sorted(map( lambda x: x[0], l )), ["a","b","c","d"])
124
def test_fileid_involved_one_rev(self):
126
l = self.branch.fileid_involved("rev-B" )
127
self.assertEquals( sorted(map( lambda x: x[0], l )), ["a","b","c"])
129
def test_fileid_involved_two_revs(self):
131
l = self.branch.fileid_involved_between_revs("rev-B","rev-K" )
132
self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","c"])
134
l = self.branch.fileid_involved_between_revs("rev-C","rev-<D>" )
135
self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","d"])
137
l = self.branch.fileid_involved_between_revs("rev-C","rev-G" )
138
self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","c","d"])
140
l = self.branch.fileid_involved_between_revs("rev-E","rev-G" )
141
self.assertEquals( sorted(map( lambda x: x[0], l )), ["a", "b","c","d"])
143
def test_fileid_involved_sets(self):
145
l = self.branch.fileid_involved_by_set(set(["rev-B"]))
146
self.assertEquals( sorted(map( lambda x: x[0], l )), ["a"])
148
l = self.branch.fileid_involved_by_set(set(["rev-<D>"]))
149
self.assertEquals( sorted(map( lambda x: x[0], l )), ["b"])
151
def test_fileid_involved_compare(self):
153
l1 = self.branch.fileid_involved_between_revs("rev-E", "rev-<D>")
154
l2 = self.branch.fileid_involved_by_set(set(["rev-<D>","rev-F","rev-C","rev-B"]))
155
self.assertEquals( l1, l2 )
157
l1 = self.branch.fileid_involved_between_revs("rev-C", "rev-G")
158
l2 = self.branch.fileid_involved_by_set(
159
set(["rev-G","rev-<D>","rev-F","rev-K","rev-J"]))
160
self.assertEquals( l1, l2 )
162
def test_fileid_involved_full_compare(self):
163
from bzrlib.tsort import topo_sort
165
history = self.branch.revision_history( )
167
if len(history) < 2: return
169
for start in range(0,len(history)-1):
170
for end in range(start+1,len(history)):
172
l1 = self.branch.fileid_involved_between_revs(
173
history[start], history[end])
175
old_tree = self.branch.repository.revision_tree(history[start])
176
new_tree = self.branch.repository.revision_tree(history[end])
177
delta = compare_trees(old_tree, new_tree )
179
l2 = [id for path, id, kind in delta.added] + \
180
[id for oldpath, newpath, id, kind, text_modified, \
181
meta_modified in delta.renamed] + \
182
[id for path, id, kind, text_modified, meta_modified in \
185
self.assertEquals(l1, set(l2))