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.clone import copy_branch
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
27
from bzrlib.workingtree import WorkingTree
30
class TestFileIdInvolved(TestCaseWithTransport):
32
def touch(self,filename):
33
f = file(filename,"a")
34
f.write("appended line\n")
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(),
44
merge_inner(wt_to.branch, branch_from.working_tree(),
45
wt_to.branch.revision_tree(base_rev),
47
wt_to.add_pending_merge(branch_from.last_revision())
50
super(TestFileIdInvolved, self).setUp()
51
# create three branches, and merge it
53
# /-->J ------>K (branch2)
55
# A ---> B --->C ---->D->G (main)
57
# \---> E---/----> F (branch1)
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"])
63
main_wt.add(['a', 'b', 'c'], ['a-file-id-2006-01-01-abcd',
64
'b-file-id-2006-01-01-defg',
65
'c-funky<file-id> quiji%bo'])
66
main_wt.commit("Commit one", rev_id="rev-A")
67
#-------- end A -----------
69
b1 = copy_branch(main_branch, "branch1")
70
self.build_tree(["branch1/d"])
71
b1.working_tree().add('d')
72
b1.working_tree().commit("branch1, Commit one", rev_id="rev-E")
74
#-------- end E -----------
77
main_wt.commit("Commit two", rev_id="rev-B")
79
#-------- end B -----------
81
branch2_branch = copy_branch(main_branch, "branch2")
82
os.chmod("branch2/b",0770)
83
branch2_branch.working_tree().commit("branch2, Commit one",
86
#-------- end J -----------
88
self.merge(b1, main_wt)
89
main_wt.commit("merge branch1, rev-11", rev_id="rev-C")
91
#-------- end C -----------
93
tree = WorkingTree('branch1', b1)
94
tree.rename_one("d","e")
95
tree.commit("branch1, commit two", rev_id="rev-F")
97
#-------- end F -----------
99
self.touch("branch2/c")
100
branch2_branch.working_tree().commit("branch2, commit two", rev_id="rev-K")
102
#-------- end K -----------
105
self.merge(b1, main_wt)
106
# D gets some funky characters to make sure the unescaping works
107
main_wt.commit("merge branch1, rev-12", rev_id="rev-<D>")
111
self.merge(branch2_branch, main_wt)
112
main_wt.commit("merge branch1, rev-22", rev_id="rev-G")
115
self.branch = main_branch
118
def test_fileid_involved_all_revs(self):
120
l = self.branch.fileid_involved( )
121
self.assertEquals( sorted(map( lambda x: x[0], l )), ["a","b","c","d"])
123
def test_fileid_involved_one_rev(self):
125
l = self.branch.fileid_involved("rev-B" )
126
self.assertEquals( sorted(map( lambda x: x[0], l )), ["a","b","c"])
128
def test_fileid_involved_two_revs(self):
130
l = self.branch.fileid_involved_between_revs("rev-B","rev-K" )
131
self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","c"])
133
l = self.branch.fileid_involved_between_revs("rev-C","rev-<D>" )
134
self.assertEquals( sorted(map( lambda x: x[0], l )), ["b","d"])
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"])
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"])
142
def test_fileid_involved_sets(self):
144
l = self.branch.fileid_involved_by_set(set(["rev-B"]))
145
self.assertEquals( sorted(map( lambda x: x[0], l )), ["a"])
147
l = self.branch.fileid_involved_by_set(set(["rev-<D>"]))
148
self.assertEquals( sorted(map( lambda x: x[0], l )), ["b"])
150
def test_fileid_involved_compare(self):
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"]))
154
self.assertEquals( l1, l2 )
156
l1 = self.branch.fileid_involved_between_revs("rev-C", "rev-G")
157
l2 = self.branch.fileid_involved_by_set(
158
set(["rev-G","rev-<D>","rev-F","rev-K","rev-J"]))
159
self.assertEquals( l1, l2 )
161
def test_fileid_involved_full_compare(self):
162
from bzrlib.tsort import topo_sort
164
history = self.branch.revision_history( )
166
if len(history) < 2: return
168
for start in range(0,len(history)-1):
169
for end in range(start+1,len(history)):
171
l1 = self.branch.fileid_involved_between_revs(
172
history[start], history[end])
174
old_tree = self.branch.revision_tree(history[start])
175
new_tree = self.branch.revision_tree(history[end])
176
delta = compare_trees(old_tree, new_tree )
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 \
184
self.assertEquals(l1, set(l2))