bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2052.3.2
by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical |
1 |
# Copyright (C) 2006 Canonical Ltd
|
|
1908.5.2
by Robert Collins
Create and test set_parent_trees. |
2 |
#
|
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.
|
|
7 |
#
|
|
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.
|
|
12 |
#
|
|
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
|
|
16 |
||
|
1908.5.3
by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert. |
17 |
"""Tests of the parent related functions of WorkingTrees."""
|
18 |
||
|
2865.1.1
by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit. |
19 |
from errno import EEXIST |
|
1908.5.2
by Robert Collins
Create and test set_parent_trees. |
20 |
import os |
21 |
||
|
2598.5.2
by Aaron Bentley
Got all tests passing with Branch returning 'null:' for null revision |
22 |
from bzrlib import ( |
23 |
errors, |
|
|
2865.1.1
by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit. |
24 |
osutils, |
|
2598.5.2
by Aaron Bentley
Got all tests passing with Branch returning 'null:' for null revision |
25 |
revision as _mod_revision, |
26 |
symbol_versioning, |
|
27 |
)
|
|
|
2865.1.1
by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit. |
28 |
from bzrlib.inventory import ( |
29 |
Inventory, |
|
30 |
InventoryFile, |
|
31 |
InventoryDirectory, |
|
32 |
InventoryLink, |
|
33 |
)
|
|
34 |
from bzrlib.revision import Revision |
|
35 |
from bzrlib.tests import SymlinkFeature, TestNotApplicable |
|
|
1908.5.2
by Robert Collins
Create and test set_parent_trees. |
36 |
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree |
37 |
from bzrlib.uncommit import uncommit |
|
38 |
||
39 |
||
|
1908.5.3
by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert. |
40 |
class TestParents(TestCaseWithWorkingTree): |
41 |
||
42 |
def assertConsistentParents(self, expected, tree): |
|
|
1908.7.6
by Robert Collins
Deprecate WorkingTree.last_revision. |
43 |
"""Check that the parents found are as expected. |
44 |
||
45 |
This test helper also checks that they are consistent with
|
|
46 |
the pre-get_parent_ids() api - which is now deprecated.
|
|
47 |
"""
|
|
|
1908.5.3
by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert. |
48 |
self.assertEqual(expected, tree.get_parent_ids()) |
49 |
if expected == []: |
|
|
2598.5.7
by Aaron Bentley
Updates from review |
50 |
self.assertEqual(_mod_revision.NULL_REVISION, |
51 |
_mod_revision.ensure_null(tree.last_revision())) |
|
|
1908.5.3
by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert. |
52 |
else: |
|
1908.7.11
by Robert Collins
Merge bzr.dev and undeprecated WorkingTree.last_revision as per review feedback. |
53 |
self.assertEqual(expected[0], tree.last_revision()) |
|
1908.7.6
by Robert Collins
Deprecate WorkingTree.last_revision. |
54 |
self.assertEqual(expected[1:], |
|
1908.7.8
by Robert Collins
Merge improved test deprecation helpers, simplifying handling of deprecated WorkingTree function tests. |
55 |
self.applyDeprecated(symbol_versioning.zero_eleven, |
56 |
tree.pending_merges)) |
|
|
1908.5.3
by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert. |
57 |
|
58 |
||
|
2598.5.2
by Aaron Bentley
Got all tests passing with Branch returning 'null:' for null revision |
59 |
class TestGetParents(TestParents): |
60 |
||
61 |
def test_get_parents(self): |
|
62 |
t = self.make_branch_and_tree('.') |
|
63 |
self.assertEqual([], t.get_parent_ids()) |
|
64 |
||
65 |
||
|
1908.5.3
by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert. |
66 |
class TestSetParents(TestParents): |
|
1908.5.2
by Robert Collins
Create and test set_parent_trees. |
67 |
|
68 |
def test_set_no_parents(self): |
|
69 |
t = self.make_branch_and_tree('.') |
|
70 |
t.set_parent_trees([]) |
|
71 |
self.assertEqual([], t.get_parent_ids()) |
|
72 |
# now give it a real parent, and then set it to no parents again.
|
|
73 |
t.commit('first post') |
|
74 |
t.set_parent_trees([]) |
|
|
1908.5.3
by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert. |
75 |
self.assertConsistentParents([], t) |
|
1908.5.2
by Robert Collins
Create and test set_parent_trees. |
76 |
|
|
2598.5.2
by Aaron Bentley
Got all tests passing with Branch returning 'null:' for null revision |
77 |
def test_set_null_parent(self): |
78 |
t = self.make_branch_and_tree('.') |
|
79 |
self.assertRaises(errors.ReservedId, t.set_parent_ids, ['null:'], |
|
80 |
allow_leftmost_as_ghost=True) |
|
81 |
self.assertRaises(errors.ReservedId, t.set_parent_trees, |
|
82 |
[('null:', None)], allow_leftmost_as_ghost=True) |
|
83 |
||
|
1908.5.9
by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api. |
84 |
def test_set_one_ghost_parent_rejects(self): |
85 |
t = self.make_branch_and_tree('.') |
|
|
1908.5.12
by Robert Collins
Apply review feedback - paired with Martin. |
86 |
self.assertRaises(errors.GhostRevisionUnusableHere, |
|
1908.5.9
by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api. |
87 |
t.set_parent_trees, [('missing-revision-id', None)]) |
88 |
||
89 |
def test_set_one_ghost_parent_force(self): |
|
90 |
t = self.make_branch_and_tree('.') |
|
91 |
t.set_parent_trees([('missing-revision-id', None)], |
|
92 |
allow_leftmost_as_ghost=True) |
|
|
1908.5.3
by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert. |
93 |
self.assertConsistentParents(['missing-revision-id'], t) |
|
1908.5.2
by Robert Collins
Create and test set_parent_trees. |
94 |
|
95 |
def test_set_two_parents_one_ghost(self): |
|
96 |
t = self.make_branch_and_tree('.') |
|
97 |
revision_in_repo = t.commit('first post') |
|
98 |
# remove the tree's history
|
|
99 |
uncommit(t.branch, tree=t) |
|
100 |
rev_tree = t.branch.repository.revision_tree(revision_in_repo) |
|
101 |
t.set_parent_trees([(revision_in_repo, rev_tree), |
|
102 |
('another-missing', None)]) |
|
|
1908.5.3
by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert. |
103 |
self.assertConsistentParents([revision_in_repo, 'another-missing'], t) |
|
1908.5.2
by Robert Collins
Create and test set_parent_trees. |
104 |
|
105 |
def test_set_three_parents(self): |
|
106 |
t = self.make_branch_and_tree('.') |
|
107 |
first_revision = t.commit('first post') |
|
108 |
uncommit(t.branch, tree=t) |
|
109 |
second_revision = t.commit('second post') |
|
110 |
uncommit(t.branch, tree=t) |
|
111 |
third_revision = t.commit('third post') |
|
112 |
uncommit(t.branch, tree=t) |
|
113 |
rev_tree1 = t.branch.repository.revision_tree(first_revision) |
|
114 |
rev_tree2 = t.branch.repository.revision_tree(second_revision) |
|
115 |
rev_tree3 = t.branch.repository.revision_tree(third_revision) |
|
116 |
t.set_parent_trees([(first_revision, rev_tree1), |
|
117 |
(second_revision, rev_tree2), |
|
118 |
(third_revision, rev_tree3)]) |
|
|
1908.5.3
by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert. |
119 |
self.assertConsistentParents( |
120 |
[first_revision, second_revision, third_revision], t) |
|
|
1908.5.4
by Robert Collins
Add add_parent_tree_id WorkingTree helper api. |
121 |
|
|
1908.5.5
by Robert Collins
Add WorkingTree.set_parent_ids. |
122 |
def test_set_no_parents_ids(self): |
123 |
t = self.make_branch_and_tree('.') |
|
124 |
t.set_parent_ids([]) |
|
125 |
self.assertEqual([], t.get_parent_ids()) |
|
126 |
# now give it a real parent, and then set it to no parents again.
|
|
127 |
t.commit('first post') |
|
128 |
t.set_parent_ids([]) |
|
129 |
self.assertConsistentParents([], t) |
|
130 |
||
|
1908.5.9
by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api. |
131 |
def test_set_one_ghost_parent_ids_rejects(self): |
132 |
t = self.make_branch_and_tree('.') |
|
|
1908.5.12
by Robert Collins
Apply review feedback - paired with Martin. |
133 |
self.assertRaises(errors.GhostRevisionUnusableHere, |
|
1908.5.9
by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api. |
134 |
t.set_parent_ids, ['missing-revision-id']) |
135 |
||
136 |
def test_set_one_ghost_parent_ids_force(self): |
|
137 |
t = self.make_branch_and_tree('.') |
|
138 |
t.set_parent_ids(['missing-revision-id'], |
|
139 |
allow_leftmost_as_ghost=True) |
|
|
1908.5.5
by Robert Collins
Add WorkingTree.set_parent_ids. |
140 |
self.assertConsistentParents(['missing-revision-id'], t) |
141 |
||
142 |
def test_set_two_parents_one_ghost_ids(self): |
|
143 |
t = self.make_branch_and_tree('.') |
|
144 |
revision_in_repo = t.commit('first post') |
|
145 |
# remove the tree's history
|
|
146 |
uncommit(t.branch, tree=t) |
|
147 |
rev_tree = t.branch.repository.revision_tree(revision_in_repo) |
|
148 |
t.set_parent_ids([revision_in_repo, 'another-missing']) |
|
149 |
self.assertConsistentParents([revision_in_repo, 'another-missing'], t) |
|
150 |
||
151 |
def test_set_three_parents_ids(self): |
|
152 |
t = self.make_branch_and_tree('.') |
|
153 |
first_revision = t.commit('first post') |
|
154 |
uncommit(t.branch, tree=t) |
|
155 |
second_revision = t.commit('second post') |
|
156 |
uncommit(t.branch, tree=t) |
|
157 |
third_revision = t.commit('third post') |
|
158 |
uncommit(t.branch, tree=t) |
|
159 |
rev_tree1 = t.branch.repository.revision_tree(first_revision) |
|
160 |
rev_tree2 = t.branch.repository.revision_tree(second_revision) |
|
161 |
rev_tree3 = t.branch.repository.revision_tree(third_revision) |
|
162 |
t.set_parent_ids([first_revision, second_revision, third_revision]) |
|
163 |
self.assertConsistentParents( |
|
164 |
[first_revision, second_revision, third_revision], t) |
|
165 |
||
|
1908.5.4
by Robert Collins
Add add_parent_tree_id WorkingTree helper api. |
166 |
|
|
1908.5.6
by Robert Collins
Add add_parent_tree to WorkingTree. |
167 |
class TestAddParent(TestParents): |
|
1908.5.4
by Robert Collins
Add add_parent_tree_id WorkingTree helper api. |
168 |
|
169 |
def test_add_first_parent_id(self): |
|
170 |
"""Test adding the first parent id""" |
|
171 |
tree = self.make_branch_and_tree('.') |
|
172 |
first_revision = tree.commit('first post') |
|
173 |
uncommit(tree.branch, tree=tree) |
|
174 |
tree.add_parent_tree_id(first_revision) |
|
175 |
self.assertConsistentParents([first_revision], tree) |
|
176 |
||
|
1908.5.9
by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api. |
177 |
def test_add_first_parent_id_ghost_rejects(self): |
178 |
"""Test adding the first parent id - as a ghost""" |
|
179 |
tree = self.make_branch_and_tree('.') |
|
|
1908.5.12
by Robert Collins
Apply review feedback - paired with Martin. |
180 |
self.assertRaises(errors.GhostRevisionUnusableHere, |
|
1908.5.9
by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api. |
181 |
tree.add_parent_tree_id, 'first-revision') |
182 |
||
183 |
def test_add_first_parent_id_ghost_force(self): |
|
184 |
"""Test adding the first parent id - as a ghost""" |
|
185 |
tree = self.make_branch_and_tree('.') |
|
186 |
tree.add_parent_tree_id('first-revision', allow_leftmost_as_ghost=True) |
|
|
1908.5.4
by Robert Collins
Add add_parent_tree_id WorkingTree helper api. |
187 |
self.assertConsistentParents(['first-revision'], tree) |
|
1908.5.13
by Robert Collins
Adding a parent when the first is a ghost already should not require forcing it. |
188 |
|
189 |
def test_add_second_parent_id_with_ghost_first(self): |
|
190 |
"""Test adding the second parent when the first is a ghost.""" |
|
191 |
tree = self.make_branch_and_tree('.') |
|
192 |
tree.add_parent_tree_id('first-revision', allow_leftmost_as_ghost=True) |
|
193 |
tree.add_parent_tree_id('second') |
|
194 |
self.assertConsistentParents(['first-revision', 'second'], tree) |
|
|
1908.5.4
by Robert Collins
Add add_parent_tree_id WorkingTree helper api. |
195 |
|
196 |
def test_add_second_parent_id(self): |
|
197 |
"""Test adding the second parent id""" |
|
198 |
tree = self.make_branch_and_tree('.') |
|
199 |
first_revision = tree.commit('first post') |
|
200 |
uncommit(tree.branch, tree=tree) |
|
201 |
second_revision = tree.commit('second post') |
|
202 |
tree.add_parent_tree_id(first_revision) |
|
203 |
self.assertConsistentParents([second_revision, first_revision], tree) |
|
204 |
||
205 |
def test_add_second_parent_id_ghost(self): |
|
206 |
"""Test adding the second parent id - as a ghost""" |
|
207 |
tree = self.make_branch_and_tree('.') |
|
208 |
first_revision = tree.commit('first post') |
|
209 |
tree.add_parent_tree_id('second') |
|
210 |
self.assertConsistentParents([first_revision, 'second'], tree) |
|
|
1908.5.6
by Robert Collins
Add add_parent_tree to WorkingTree. |
211 |
|
212 |
def test_add_first_parent_tree(self): |
|
213 |
"""Test adding the first parent id""" |
|
214 |
tree = self.make_branch_and_tree('.') |
|
215 |
first_revision = tree.commit('first post') |
|
216 |
uncommit(tree.branch, tree=tree) |
|
217 |
tree.add_parent_tree((first_revision, |
|
218 |
tree.branch.repository.revision_tree(first_revision))) |
|
219 |
self.assertConsistentParents([first_revision], tree) |
|
220 |
||
|
1908.5.9
by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api. |
221 |
def test_add_first_parent_tree_ghost_rejects(self): |
222 |
"""Test adding the first parent id - as a ghost""" |
|
223 |
tree = self.make_branch_and_tree('.') |
|
|
1908.5.12
by Robert Collins
Apply review feedback - paired with Martin. |
224 |
self.assertRaises(errors.GhostRevisionUnusableHere, |
|
1908.5.9
by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api. |
225 |
tree.add_parent_tree, ('first-revision', None)) |
226 |
||
227 |
def test_add_first_parent_tree_ghost_force(self): |
|
228 |
"""Test adding the first parent id - as a ghost""" |
|
229 |
tree = self.make_branch_and_tree('.') |
|
230 |
tree.add_parent_tree(('first-revision', None), |
|
231 |
allow_leftmost_as_ghost=True) |
|
|
1908.5.6
by Robert Collins
Add add_parent_tree to WorkingTree. |
232 |
self.assertConsistentParents(['first-revision'], tree) |
233 |
||
234 |
def test_add_second_parent_tree(self): |
|
235 |
"""Test adding the second parent id""" |
|
236 |
tree = self.make_branch_and_tree('.') |
|
237 |
first_revision = tree.commit('first post') |
|
238 |
uncommit(tree.branch, tree=tree) |
|
239 |
second_revision = tree.commit('second post') |
|
240 |
tree.add_parent_tree((first_revision, |
|
241 |
tree.branch.repository.revision_tree(first_revision))) |
|
242 |
self.assertConsistentParents([second_revision, first_revision], tree) |
|
243 |
||
244 |
def test_add_second_parent_tree_ghost(self): |
|
245 |
"""Test adding the second parent id - as a ghost""" |
|
246 |
tree = self.make_branch_and_tree('.') |
|
247 |
first_revision = tree.commit('first post') |
|
248 |
tree.add_parent_tree(('second', None)) |
|
249 |
self.assertConsistentParents([first_revision, 'second'], tree) |
|
|
2865.1.1
by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit. |
250 |
|
251 |
||
252 |
class UpdateToOneParentViaDeltaTests(TestParents): |
|
|
2903.2.7
by Martin Pool
Rename update_to_one_parent_via_delta to more wieldy update_basis_by_delta |
253 |
"""Tests for the update_basis_by_delta call. |
|
2865.1.1
by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit. |
254 |
|
255 |
This is intuitively defined as 'apply an inventory delta to the basis and
|
|
256 |
discard other parents', but for trees that have an inventory that is not
|
|
257 |
managed as a tree-by-id, the implementation requires roughly duplicated
|
|
258 |
tests with those for apply_inventory_delta on the main tree.
|
|
259 |
"""
|
|
260 |
||
261 |
def assertDeltaApplicationResultsInExpectedBasis(self, tree, revid, delta, |
|
262 |
expected_inventory): |
|
|
2903.2.7
by Martin Pool
Rename update_to_one_parent_via_delta to more wieldy update_basis_by_delta |
263 |
tree.update_basis_by_delta(revid, delta) |
|
2865.1.1
by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit. |
264 |
# check the last revision was adjusted to rev_id
|
265 |
self.assertEqual(revid, tree.last_revision()) |
|
266 |
# check the parents are what we expect
|
|
267 |
self.assertEqual([revid], tree.get_parent_ids()) |
|
268 |
# check that the basis tree has the inventory we expect from applying
|
|
269 |
# the delta.
|
|
270 |
result_basis = tree.basis_tree() |
|
271 |
result_basis.lock_read() |
|
272 |
self.addCleanup(result_basis.unlock) |
|
273 |
self.assertEqual(expected_inventory, result_basis.inventory) |
|
274 |
||
275 |
def make_inv_delta(self, old, new): |
|
276 |
"""Make an inventory delta from two inventories.""" |
|
277 |
old_ids = set(old._byid.iterkeys()) |
|
278 |
new_ids = set(new._byid.iterkeys()) |
|
279 |
adds = new_ids - old_ids |
|
280 |
deletes = old_ids - new_ids |
|
281 |
common = old_ids.intersection(new_ids) |
|
282 |
delta = [] |
|
283 |
for file_id in deletes: |
|
284 |
delta.append((old.id2path(file_id), None, file_id, None)) |
|
285 |
for file_id in adds: |
|
286 |
delta.append((None, new.id2path(file_id), file_id, new[file_id])) |
|
287 |
for file_id in common: |
|
288 |
if old[file_id] != new[file_id]: |
|
289 |
delta.append((old.id2path(file_id), new.id2path(file_id), |
|
290 |
file_id, new[file_id])) |
|
291 |
return delta |
|
292 |
||
293 |
def fake_up_revision(self, tree, revid, shape): |
|
294 |
tree.lock_write() |
|
295 |
try: |
|
296 |
tree.branch.repository.start_write_group() |
|
297 |
try: |
|
298 |
if shape.root.revision is None: |
|
299 |
shape.root.revision = revid |
|
300 |
sha1 = tree.branch.repository.add_inventory(revid, shape, []) |
|
301 |
rev = Revision(timestamp=0, |
|
302 |
timezone=None, |
|
303 |
committer="Foo Bar <foo@example.com>", |
|
304 |
message="Message", |
|
305 |
inventory_sha1=sha1, |
|
306 |
revision_id=revid) |
|
307 |
tree.branch.repository.add_revision(revid, rev) |
|
308 |
except: |
|
309 |
tree.branch.repository.abort_write_group() |
|
310 |
raise
|
|
311 |
else: |
|
312 |
tree.branch.repository.commit_write_group() |
|
313 |
finally: |
|
314 |
tree.unlock() |
|
315 |
||
316 |
def add_entry(self, inv, rev_id, entry): |
|
317 |
entry.revision = rev_id |
|
318 |
inv.add(entry) |
|
319 |
||
320 |
def add_dir(self, inv, rev_id, file_id, parent_id, name): |
|
321 |
new_dir = InventoryDirectory(file_id, name, parent_id) |
|
322 |
self.add_entry(inv, rev_id, new_dir) |
|
323 |
||
324 |
def add_file(self, inv, rev_id, file_id, parent_id, name, sha, size): |
|
325 |
new_file = InventoryFile(file_id, name, parent_id) |
|
326 |
new_file.text_sha1 = sha |
|
327 |
new_file.text_size = size |
|
328 |
self.add_entry(inv, rev_id, new_file) |
|
329 |
||
330 |
def add_link(self, inv, rev_id, file_id, parent_id, name, target): |
|
331 |
new_link = InventoryLink(file_id, name, parent_id) |
|
332 |
new_link.symlink_target = target |
|
333 |
self.add_entry(inv, rev_id, new_link) |
|
334 |
||
335 |
def add_new_root(self, new_shape, old_revid, new_revid): |
|
336 |
if self.bzrdir_format.repository_format.rich_root_data: |
|
337 |
self.add_dir(new_shape, old_revid, 'root-id', None, '') |
|
338 |
else: |
|
339 |
self.add_dir(new_shape, new_revid, 'root-id', None, '') |
|
340 |
||
341 |
def assertTransitionFromBasisToShape(self, basis_shape, basis_revid, |
|
342 |
new_shape, new_revid, extra_parent=None): |
|
|
2889.1.1
by Robert Collins
* The class ``bzrlib.repofmt.knitrepo.KnitRepository3`` has been folded into |
343 |
# set the inventory revision ids.
|
344 |
basis_shape.revision_id = basis_revid |
|
345 |
new_shape.revision_id = new_revid |
|
|
2865.1.1
by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit. |
346 |
delta = self.make_inv_delta(basis_shape, new_shape) |
347 |
tree = self.make_branch_and_tree('tree') |
|
348 |
# the shapes need to be in the tree's repository to be able to set them
|
|
349 |
# as a parent, but the file content is not needed.
|
|
350 |
if basis_revid is not None: |
|
351 |
self.fake_up_revision(tree, basis_revid, basis_shape) |
|
352 |
parents = [basis_revid] |
|
353 |
if extra_parent is not None: |
|
354 |
parents.append(extra_parent) |
|
355 |
tree.set_parent_ids(parents) |
|
356 |
self.fake_up_revision(tree, new_revid, new_shape) |
|
357 |
self.assertDeltaApplicationResultsInExpectedBasis(tree, new_revid, |
|
358 |
delta, new_shape) |
|
359 |
osutils.rmtree('tree') |
|
360 |
||
361 |
def test_no_parents_just_root(self): |
|
362 |
"""Test doing an empty commit - no parent, set a root only.""" |
|
363 |
basis_shape = Inventory(root_id=None) # empty tree |
|
364 |
new_shape = Inventory() # tree with a root |
|
365 |
self.assertTransitionFromBasisToShape(basis_shape, None, new_shape, |
|
366 |
'new_parent') |
|
367 |
||
368 |
def test_no_parents_full_tree(self): |
|
369 |
"""Test doing a regular initial commit with files and dirs.""" |
|
370 |
basis_shape = Inventory(root_id=None) # empty tree |
|
371 |
revid = 'new-parent' |
|
372 |
new_shape = Inventory(root_id=None) |
|
373 |
self.add_dir(new_shape, revid, 'root-id', None, '') |
|
374 |
self.add_link(new_shape, revid, 'link-id', 'root-id', 'link', 'target') |
|
375 |
self.add_file(new_shape, revid, 'file-id', 'root-id', 'file', '1' * 32, |
|
376 |
12) |
|
377 |
self.add_dir(new_shape, revid, 'dir-id', 'root-id', 'dir') |
|
378 |
self.add_file(new_shape, revid, 'subfile-id', 'dir-id', 'subfile', |
|
379 |
'2' * 32, 24) |
|
380 |
self.assertTransitionFromBasisToShape(basis_shape, None, new_shape, |
|
381 |
revid) |
|
382 |
||
383 |
def test_file_content_change(self): |
|
384 |
old_revid = 'old-parent' |
|
385 |
basis_shape = Inventory(root_id=None) |
|
386 |
self.add_dir(basis_shape, old_revid, 'root-id', None, '') |
|
387 |
self.add_file(basis_shape, old_revid, 'file-id', 'root-id', 'file', |
|
388 |
'1' * 32, 12) |
|
389 |
new_revid = 'new-parent' |
|
390 |
new_shape = Inventory(root_id=None) |
|
391 |
self.add_new_root(new_shape, old_revid, new_revid) |
|
392 |
self.add_file(new_shape, new_revid, 'file-id', 'root-id', 'file', |
|
393 |
'2' * 32, 24) |
|
394 |
self.assertTransitionFromBasisToShape(basis_shape, old_revid, |
|
395 |
new_shape, new_revid) |
|
396 |
||
397 |
def test_link_content_change(self): |
|
398 |
old_revid = 'old-parent' |
|
399 |
basis_shape = Inventory(root_id=None) |
|
400 |
self.add_dir(basis_shape, old_revid, 'root-id', None, '') |
|
401 |
self.add_link(basis_shape, old_revid, 'link-id', 'root-id', 'link', |
|
402 |
'old-target') |
|
403 |
new_revid = 'new-parent' |
|
404 |
new_shape = Inventory(root_id=None) |
|
405 |
self.add_new_root(new_shape, old_revid, new_revid) |
|
406 |
self.add_link(new_shape, new_revid, 'link-id', 'root-id', 'link', |
|
407 |
'new-target') |
|
408 |
self.assertTransitionFromBasisToShape(basis_shape, old_revid, |
|
409 |
new_shape, new_revid) |
|
410 |
||
411 |
def test_kind_changes(self): |
|
412 |
def do_file(inv, revid): |
|
413 |
self.add_file(inv, revid, 'path-id', 'root-id', 'path', '1' * 32, |
|
414 |
12) |
|
415 |
def do_link(inv, revid): |
|
416 |
self.add_link(inv, revid, 'path-id', 'root-id', 'path', 'target') |
|
417 |
def do_dir(inv, revid): |
|
418 |
self.add_dir(inv, revid, 'path-id', 'root-id', 'path') |
|
419 |
for old_factory in (do_file, do_link, do_dir): |
|
420 |
for new_factory in (do_file, do_link, do_dir): |
|
421 |
if old_factory == new_factory: |
|
422 |
continue
|
|
423 |
old_revid = 'old-parent' |
|
424 |
basis_shape = Inventory(root_id=None) |
|
425 |
self.add_dir(basis_shape, old_revid, 'root-id', None, '') |
|
426 |
old_factory(basis_shape, old_revid) |
|
427 |
new_revid = 'new-parent' |
|
428 |
new_shape = Inventory(root_id=None) |
|
429 |
self.add_new_root(new_shape, old_revid, new_revid) |
|
430 |
new_factory(new_shape, new_revid) |
|
431 |
self.assertTransitionFromBasisToShape(basis_shape, old_revid, |
|
432 |
new_shape, new_revid) |
|
433 |
||
434 |
def test_content_from_second_parent_is_dropped(self): |
|
435 |
left_revid = 'left-parent' |
|
436 |
basis_shape = Inventory(root_id=None) |
|
437 |
self.add_dir(basis_shape, left_revid, 'root-id', None, '') |
|
438 |
self.add_link(basis_shape, left_revid, 'link-id', 'root-id', 'link', |
|
439 |
'left-target') |
|
440 |
# the right shape has content - file, link, subdir with a child,
|
|
441 |
# that should all be discarded by the call.
|
|
442 |
right_revid = 'right-parent' |
|
443 |
right_shape = Inventory(root_id=None) |
|
444 |
self.add_dir(right_shape, left_revid, 'root-id', None, '') |
|
445 |
self.add_link(right_shape, right_revid, 'link-id', 'root-id', 'link', |
|
|
2865.1.3
by Robert Collins
Review feedback. |
446 |
'some-target') |
|
2865.1.1
by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit. |
447 |
self.add_dir(right_shape, right_revid, 'subdir-id', 'root-id', 'dir') |
448 |
self.add_file(right_shape, right_revid, 'file-id', 'subdir-id', 'file', |
|
449 |
'2' * 32, 24) |
|
450 |
new_revid = 'new-parent' |
|
451 |
new_shape = Inventory(root_id=None) |
|
452 |
self.add_new_root(new_shape, left_revid, new_revid) |
|
453 |
self.add_link(new_shape, new_revid, 'link-id', 'root-id', 'link', |
|
454 |
'new-target') |
|
455 |
self.assertTransitionFromBasisToShape(basis_shape, left_revid, |
|
456 |
new_shape, new_revid, right_revid) |
|
457 |
||
458 |
def test_parent_id_changed(self): |
|
|
2865.1.3
by Robert Collins
Review feedback. |
459 |
# test that when the only change to an entry is its parent id changing
|
|
2865.1.1
by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit. |
460 |
# that it is handled correctly (that is it keeps the same path)
|
461 |
old_revid = 'old-parent' |
|
462 |
basis_shape = Inventory(root_id=None) |
|
463 |
self.add_dir(basis_shape, old_revid, 'root-id', None, '') |
|
464 |
self.add_dir(basis_shape, old_revid, 'orig-parent-id', 'root-id', 'dir') |
|
465 |
self.add_dir(basis_shape, old_revid, 'dir-id', 'orig-parent-id', 'dir') |
|
466 |
new_revid = 'new-parent' |
|
467 |
new_shape = Inventory(root_id=None) |
|
468 |
self.add_new_root(new_shape, old_revid, new_revid) |
|
469 |
self.add_dir(new_shape, new_revid, 'new-parent-id', 'root-id', 'dir') |
|
470 |
self.add_dir(new_shape, new_revid, 'dir-id', 'new-parent-id', 'dir') |
|
471 |
self.assertTransitionFromBasisToShape(basis_shape, old_revid, |
|
472 |
new_shape, new_revid) |
|
473 |
||
474 |
def test_name_changed(self): |
|
|
2865.1.3
by Robert Collins
Review feedback. |
475 |
# test that when the only change to an entry is its name changing that
|
476 |
# it is handled correctly (that is it keeps the same parent id)
|
|
|
2865.1.1
by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit. |
477 |
old_revid = 'old-parent' |
478 |
basis_shape = Inventory(root_id=None) |
|
479 |
self.add_dir(basis_shape, old_revid, 'root-id', None, '') |
|
480 |
self.add_dir(basis_shape, old_revid, 'parent-id', 'root-id', 'origdir') |
|
481 |
self.add_dir(basis_shape, old_revid, 'dir-id', 'parent-id', 'olddir') |
|
482 |
new_revid = 'new-parent' |
|
483 |
new_shape = Inventory(root_id=None) |
|
484 |
self.add_new_root(new_shape, old_revid, new_revid) |
|
485 |
self.add_dir(new_shape, new_revid, 'parent-id', 'root-id', 'newdir') |
|
486 |
self.add_dir(new_shape, new_revid, 'dir-id', 'parent-id', 'newdir') |
|
487 |
self.assertTransitionFromBasisToShape(basis_shape, old_revid, |
|
488 |
new_shape, new_revid) |
|
489 |
||
490 |
def test_path_swap(self): |
|
491 |
# test a A->B and B->A path swap.
|
|
492 |
old_revid = 'old-parent' |
|
493 |
basis_shape = Inventory(root_id=None) |
|
494 |
self.add_dir(basis_shape, old_revid, 'root-id', None, '') |
|
495 |
self.add_dir(basis_shape, old_revid, 'dir-id-A', 'root-id', 'A') |
|
496 |
self.add_dir(basis_shape, old_revid, 'dir-id-B', 'root-id', 'B') |
|
497 |
self.add_link(basis_shape, old_revid, 'link-id-C', 'root-id', 'C', 'C') |
|
498 |
self.add_link(basis_shape, old_revid, 'link-id-D', 'root-id', 'D', 'D') |
|
499 |
self.add_file(basis_shape, old_revid, 'file-id-E', 'root-id', 'E', |
|
500 |
'1' * 32, 12) |
|
501 |
self.add_file(basis_shape, old_revid, 'file-id-F', 'root-id', 'F', |
|
502 |
'2' * 32, 24) |
|
503 |
new_revid = 'new-parent' |
|
504 |
new_shape = Inventory(root_id=None) |
|
505 |
self.add_new_root(new_shape, old_revid, new_revid) |
|
506 |
self.add_dir(new_shape, new_revid, 'dir-id-A', 'root-id', 'B') |
|
507 |
self.add_dir(new_shape, new_revid, 'dir-id-B', 'root-id', 'A') |
|
508 |
self.add_link(new_shape, new_revid, 'link-id-C', 'root-id', 'D', 'C') |
|
509 |
self.add_link(new_shape, new_revid, 'link-id-D', 'root-id', 'C', 'D') |
|
510 |
self.add_file(new_shape, new_revid, 'file-id-E', 'root-id', 'F', |
|
511 |
'1' * 32, 12) |
|
512 |
self.add_file(new_shape, new_revid, 'file-id-F', 'root-id', 'E', |
|
513 |
'2' * 32, 24) |
|
514 |
self.assertTransitionFromBasisToShape(basis_shape, old_revid, |
|
515 |
new_shape, new_revid) |
|
516 |
||
517 |
def test_adds(self): |
|
518 |
# test adding paths and dirs, including adding to a newly added dir.
|
|
519 |
old_revid = 'old-parent' |
|
520 |
basis_shape = Inventory(root_id=None) |
|
521 |
# with a root, so its a commit after the first.
|
|
522 |
self.add_dir(basis_shape, old_revid, 'root-id', None, '') |
|
523 |
new_revid = 'new-parent' |
|
524 |
new_shape = Inventory(root_id=None) |
|
525 |
self.add_new_root(new_shape, old_revid, new_revid) |
|
526 |
self.add_dir(new_shape, new_revid, 'dir-id-A', 'root-id', 'A') |
|
527 |
self.add_link(new_shape, new_revid, 'link-id-B', 'root-id', 'B', 'C') |
|
528 |
self.add_file(new_shape, new_revid, 'file-id-C', 'root-id', 'C', |
|
529 |
'1' * 32, 12) |
|
530 |
self.add_file(new_shape, new_revid, 'file-id-D', 'dir-id-A', 'D', |
|
531 |
'2' * 32, 24) |
|
532 |
self.assertTransitionFromBasisToShape(basis_shape, old_revid, |
|
533 |
new_shape, new_revid) |
|
534 |
||
535 |
def test_removes(self): |
|
536 |
# test removing paths, including paths that are within other also
|
|
537 |
# removed paths.
|
|
538 |
old_revid = 'old-parent' |
|
539 |
basis_shape = Inventory(root_id=None) |
|
540 |
self.add_dir(basis_shape, old_revid, 'root-id', None, '') |
|
541 |
self.add_dir(basis_shape, old_revid, 'dir-id-A', 'root-id', 'A') |
|
542 |
self.add_link(basis_shape, old_revid, 'link-id-B', 'root-id', 'B', 'C') |
|
543 |
self.add_file(basis_shape, old_revid, 'file-id-C', 'root-id', 'C', |
|
544 |
'1' * 32, 12) |
|
545 |
self.add_file(basis_shape, old_revid, 'file-id-D', 'dir-id-A', 'D', |
|
546 |
'2' * 32, 24) |
|
547 |
new_revid = 'new-parent' |
|
548 |
new_shape = Inventory(root_id=None) |
|
549 |
self.add_new_root(new_shape, old_revid, new_revid) |
|
550 |
self.assertTransitionFromBasisToShape(basis_shape, old_revid, |
|
551 |
new_shape, new_revid) |
|
552 |
||
553 |
def test_move_to_added_dir(self): |
|
554 |
old_revid = 'old-parent' |
|
555 |
basis_shape = Inventory(root_id=None) |
|
556 |
self.add_dir(basis_shape, old_revid, 'root-id', None, '') |
|
557 |
self.add_link(basis_shape, old_revid, 'link-id-B', 'root-id', 'B', 'C') |
|
558 |
new_revid = 'new-parent' |
|
559 |
new_shape = Inventory(root_id=None) |
|
560 |
self.add_new_root(new_shape, old_revid, new_revid) |
|
561 |
self.add_dir(new_shape, new_revid, 'dir-id-A', 'root-id', 'A') |
|
562 |
self.add_link(new_shape, new_revid, 'link-id-B', 'dir-id-A', 'B', 'C') |
|
563 |
self.assertTransitionFromBasisToShape(basis_shape, old_revid, |
|
564 |
new_shape, new_revid) |
|
565 |
||
566 |
def test_move_from_removed_dir(self): |
|
567 |
old_revid = 'old-parent' |
|
568 |
basis_shape = Inventory(root_id=None) |
|
569 |
self.add_dir(basis_shape, old_revid, 'root-id', None, '') |
|
570 |
self.add_dir(basis_shape, old_revid, 'dir-id-A', 'root-id', 'A') |
|
571 |
self.add_link(basis_shape, old_revid, 'link-id-B', 'dir-id-A', 'B', 'C') |
|
572 |
new_revid = 'new-parent' |
|
573 |
new_shape = Inventory(root_id=None) |
|
574 |
self.add_new_root(new_shape, old_revid, new_revid) |
|
575 |
self.add_link(new_shape, new_revid, 'link-id-B', 'root-id', 'B', 'C') |
|
576 |
self.assertTransitionFromBasisToShape(basis_shape, old_revid, |
|
577 |
new_shape, new_revid) |