bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4343.3.10
by John Arbash Meinel
Add a per_repository_reference test with real stacked repos. |
1 |
# Copyright (C) 2009 Canonical Ltd
|
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
16 |
||
17 |
||
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
18 |
from breezy import ( |
4392.2.2
by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry. |
19 |
branch, |
6670.4.3
by Jelmer Vernooij
Fix more imports. |
20 |
)
|
21 |
from breezy.bzr import ( |
|
6341.1.4
by Jelmer Vernooij
Move more functionality to vf_search. |
22 |
vf_search, |
4392.2.2
by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry. |
23 |
)
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
24 |
from breezy.tests.per_repository import TestCaseWithRepository |
4343.3.10
by John Arbash Meinel
Add a per_repository_reference test with real stacked repos. |
25 |
|
26 |
||
5539.2.7
by Andrew Bennetts
Add a test, revise a comment. |
27 |
class TestFetchBase(TestCaseWithRepository): |
4343.3.10
by John Arbash Meinel
Add a per_repository_reference test with real stacked repos. |
28 |
|
4343.3.17
by John Arbash Meinel
Finally found a way to write a test case to exercise the code path. |
29 |
def make_source_branch(self): |
30 |
# It would be nice if there was a way to force this to be memory-only
|
|
4343.3.10
by John Arbash Meinel
Add a per_repository_reference test with real stacked repos. |
31 |
builder = self.make_branch_builder('source') |
6883.22.11
by Jelmer Vernooij
merge trunk |
32 |
content = [b'content lines\n' |
33 |
b'for the first revision\n' |
|
34 |
b'which is a marginal amount of content\n' |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
35 |
]
|
4343.3.10
by John Arbash Meinel
Add a per_repository_reference test with real stacked repos. |
36 |
builder.start_series() |
6816.2.1
by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument. |
37 |
builder.build_snapshot(None, [ |
6855.3.1
by Jelmer Vernooij
Several more fixes. |
38 |
('add', ('', b'root-id', 'directory', None)), |
7027.3.3
by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents. |
39 |
('add', ('a', b'a-id', 'file', b''.join(content))), |
6855.3.1
by Jelmer Vernooij
Several more fixes. |
40 |
], revision_id=b'A-id') |
6883.22.11
by Jelmer Vernooij
merge trunk |
41 |
content.append(b'and some more lines for B\n') |
6855.3.1
by Jelmer Vernooij
Several more fixes. |
42 |
builder.build_snapshot([b'A-id'], [ |
6883.22.11
by Jelmer Vernooij
merge trunk |
43 |
('modify', ('a', b''.join(content)))], |
6855.3.1
by Jelmer Vernooij
Several more fixes. |
44 |
revision_id=b'B-id') |
7027.3.3
by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents. |
45 |
content.append(b'and yet even more content for C\n') |
6855.3.1
by Jelmer Vernooij
Several more fixes. |
46 |
builder.build_snapshot([b'B-id'], [ |
6883.22.11
by Jelmer Vernooij
merge trunk |
47 |
('modify', ('a', b''.join(content)))], |
6855.3.1
by Jelmer Vernooij
Several more fixes. |
48 |
revision_id=b'C-id') |
4343.3.10
by John Arbash Meinel
Add a per_repository_reference test with real stacked repos. |
49 |
builder.finish_series() |
50 |
source_b = builder.get_branch() |
|
51 |
source_b.lock_read() |
|
52 |
self.addCleanup(source_b.unlock) |
|
4343.3.17
by John Arbash Meinel
Finally found a way to write a test case to exercise the code path. |
53 |
return content, source_b |
54 |
||
5539.2.7
by Andrew Bennetts
Add a test, revise a comment. |
55 |
|
56 |
class TestFetch(TestFetchBase): |
|
57 |
||
4343.3.17
by John Arbash Meinel
Finally found a way to write a test case to exercise the code path. |
58 |
def test_sprout_from_stacked_with_short_history(self): |
4343.3.36
by John Arbash Meinel
Some review feedback from Andrew. |
59 |
content, source_b = self.make_source_branch() |
60 |
# Split the generated content into a base branch, and a stacked branch
|
|
4343.3.13
by John Arbash Meinel
Update the fetch tests to make sure we are properly testing a smart base branch |
61 |
# Use 'make_branch' which gives us a bzr:// branch when appropriate,
|
62 |
# rather than creating a branch-on-disk
|
|
63 |
stack_b = self.make_branch('stack-on') |
|
6973.6.2
by Jelmer Vernooij
Fix more tests. |
64 |
stack_b.pull(source_b, stop_revision=b'B-id') |
4343.3.10
by John Arbash Meinel
Add a per_repository_reference test with real stacked repos. |
65 |
target_b = self.make_branch('target') |
4343.3.13
by John Arbash Meinel
Update the fetch tests to make sure we are properly testing a smart base branch |
66 |
target_b.set_stacked_on_url('../stack-on') |
6973.6.2
by Jelmer Vernooij
Fix more tests. |
67 |
target_b.pull(source_b, stop_revision=b'C-id') |
4343.3.10
by John Arbash Meinel
Add a per_repository_reference test with real stacked repos. |
68 |
# At this point, we should have a target branch, with 1 revision, on
|
69 |
# top of the source.
|
|
4343.3.17
by John Arbash Meinel
Finally found a way to write a test case to exercise the code path. |
70 |
final_b = self.make_branch('final') |
71 |
final_b.pull(target_b) |
|
4343.3.10
by John Arbash Meinel
Add a per_repository_reference test with real stacked repos. |
72 |
final_b.lock_read() |
73 |
self.addCleanup(final_b.unlock) |
|
6973.6.2
by Jelmer Vernooij
Fix more tests. |
74 |
self.assertEqual(b'C-id', final_b.last_revision()) |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
75 |
text_keys = [(b'a-id', b'A-id'), (b'a-id', b'B-id'), |
76 |
(b'a-id', b'C-id')] |
|
7467.2.1
by Jelmer Vernooij
Replace write_inventory_to_string with write_inventory_to_chunks. |
77 |
stream = final_b.repository.texts.get_record_stream( |
78 |
text_keys, 'unordered', True) |
|
4343.3.36
by John Arbash Meinel
Some review feedback from Andrew. |
79 |
records = sorted([(r.key, r.get_bytes_as('fulltext')) for r in stream]) |
80 |
self.assertEqual([ |
|
6973.6.2
by Jelmer Vernooij
Fix more tests. |
81 |
((b'a-id', b'A-id'), b''.join(content[:-2])), |
82 |
((b'a-id', b'B-id'), b''.join(content[:-1])), |
|
83 |
((b'a-id', b'C-id'), b''.join(content)), |
|
4343.3.36
by John Arbash Meinel
Some review feedback from Andrew. |
84 |
], records) |
4343.3.17
by John Arbash Meinel
Finally found a way to write a test case to exercise the code path. |
85 |
|
86 |
def test_sprout_from_smart_stacked_with_short_history(self): |
|
87 |
content, source_b = self.make_source_branch() |
|
88 |
transport = self.make_smart_server('server') |
|
89 |
transport.ensure_base() |
|
90 |
url = transport.abspath('') |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
91 |
stack_b = source_b.controldir.sprout( |
92 |
url + '/stack-on', revision_id=b'B-id') |
|
4343.3.17
by John Arbash Meinel
Finally found a way to write a test case to exercise the code path. |
93 |
# self.make_branch only takes relative paths, so we do it the 'hard'
|
94 |
# way
|
|
95 |
target_transport = transport.clone('target') |
|
96 |
target_transport.ensure_base() |
|
97 |
target_bzrdir = self.bzrdir_format.initialize_on_transport( |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
98 |
target_transport) |
4343.3.17
by John Arbash Meinel
Finally found a way to write a test case to exercise the code path. |
99 |
target_bzrdir.create_repository() |
100 |
target_b = target_bzrdir.create_branch() |
|
101 |
target_b.set_stacked_on_url('../stack-on') |
|
6973.6.2
by Jelmer Vernooij
Fix more tests. |
102 |
target_b.pull(source_b, stop_revision=b'C-id') |
4343.3.17
by John Arbash Meinel
Finally found a way to write a test case to exercise the code path. |
103 |
# Now we should be able to branch from the remote location to a local
|
104 |
# location
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
105 |
final_b = target_b.controldir.sprout('final').open_branch() |
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
106 |
self.assertEqual(b'C-id', final_b.last_revision()) |
4343.3.17
by John Arbash Meinel
Finally found a way to write a test case to exercise the code path. |
107 |
|
108 |
# bzrdir.sprout() has slightly different code paths if you supply a
|
|
109 |
# revision_id versus not. If you supply revision_id, then you get a
|
|
110 |
# PendingAncestryResult for the search, versus a SearchResult...
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
111 |
final2_b = target_b.controldir.sprout('final2', |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
112 |
revision_id=b'C-id').open_branch() |
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
113 |
self.assertEqual(b'C-id', final_b.last_revision()) |
4392.2.2
by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry. |
114 |
|
115 |
def make_source_with_ghost_and_stacked_target(self): |
|
116 |
builder = self.make_branch_builder('source') |
|
117 |
builder.start_series() |
|
6816.2.1
by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument. |
118 |
builder.build_snapshot(None, [ |
6973.6.2
by Jelmer Vernooij
Fix more tests. |
119 |
('add', ('', b'root-id', 'directory', None)), |
120 |
('add', ('file', b'file-id', 'file', b'content\n'))], |
|
6973.5.2
by Jelmer Vernooij
Add more bees. |
121 |
revision_id=b'A-id') |
6973.6.2
by Jelmer Vernooij
Fix more tests. |
122 |
builder.build_snapshot([b'A-id', b'ghost-id'], [], revision_id=b'B-id') |
4392.2.2
by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry. |
123 |
builder.finish_series() |
124 |
source_b = builder.get_branch() |
|
125 |
source_b.lock_read() |
|
126 |
self.addCleanup(source_b.unlock) |
|
127 |
base = self.make_branch('base') |
|
6973.6.2
by Jelmer Vernooij
Fix more tests. |
128 |
base.pull(source_b, stop_revision=b'A-id') |
4392.2.2
by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry. |
129 |
stacked = self.make_branch('stacked') |
130 |
stacked.set_stacked_on_url('../base') |
|
131 |
return source_b, base, stacked |
|
132 |
||
133 |
def test_fetch_with_ghost_stacked(self): |
|
134 |
(source_b, base, |
|
135 |
stacked) = self.make_source_with_ghost_and_stacked_target() |
|
6973.6.2
by Jelmer Vernooij
Fix more tests. |
136 |
stacked.pull(source_b, stop_revision=b'B-id') |
4392.2.2
by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry. |
137 |
|
138 |
def test_fetch_into_smart_stacked_with_ghost(self): |
|
139 |
(source_b, base, |
|
140 |
stacked) = self.make_source_with_ghost_and_stacked_target() |
|
141 |
# Now, create a smart server on 'stacked' and re-open to force the
|
|
142 |
# target to be a smart target
|
|
143 |
trans = self.make_smart_server('stacked') |
|
144 |
stacked = branch.Branch.open(trans.base) |
|
145 |
stacked.lock_write() |
|
146 |
self.addCleanup(stacked.unlock) |
|
6973.6.2
by Jelmer Vernooij
Fix more tests. |
147 |
stacked.pull(source_b, stop_revision=b'B-id') |
4392.2.2
by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry. |
148 |
|
149 |
def test_fetch_to_stacked_from_smart_with_ghost(self): |
|
150 |
(source_b, base, |
|
151 |
stacked) = self.make_source_with_ghost_and_stacked_target() |
|
152 |
# Now, create a smart server on 'source' and re-open to force the
|
|
153 |
# target to be a smart target
|
|
154 |
trans = self.make_smart_server('source') |
|
155 |
source_b = branch.Branch.open(trans.base) |
|
156 |
source_b.lock_read() |
|
157 |
self.addCleanup(source_b.unlock) |
|
6973.6.2
by Jelmer Vernooij
Fix more tests. |
158 |
stacked.pull(source_b, stop_revision=b'B-id') |
5539.2.7
by Andrew Bennetts
Add a test, revise a comment. |
159 |
|
160 |
||
161 |
class TestFetchFromRepoWithUnconfiguredFallbacks(TestFetchBase): |
|
162 |
||
163 |
def make_stacked_source_repo(self): |
|
164 |
_, source_b = self.make_source_branch() |
|
165 |
# Use 'make_branch' which gives us a bzr:// branch when appropriate,
|
|
166 |
# rather than creating a branch-on-disk
|
|
167 |
stack_b = self.make_branch('stack-on') |
|
6973.6.2
by Jelmer Vernooij
Fix more tests. |
168 |
stack_b.pull(source_b, stop_revision=b'B-id') |
5539.2.7
by Andrew Bennetts
Add a test, revise a comment. |
169 |
stacked_b = self.make_branch('stacked') |
170 |
stacked_b.set_stacked_on_url('../stack-on') |
|
6973.6.2
by Jelmer Vernooij
Fix more tests. |
171 |
stacked_b.pull(source_b, stop_revision=b'C-id') |
5539.2.7
by Andrew Bennetts
Add a test, revise a comment. |
172 |
return stacked_b.repository |
173 |
||
174 |
def test_fetch_everything_includes_parent_invs(self): |
|
175 |
stacked = self.make_stacked_source_repo() |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
176 |
repo_missing_fallbacks = stacked.controldir.open_repository() |
5539.2.7
by Andrew Bennetts
Add a test, revise a comment. |
177 |
self.addCleanup(repo_missing_fallbacks.lock_read().unlock) |
178 |
target = self.make_repository('target') |
|
179 |
self.addCleanup(target.lock_write().unlock) |
|
180 |
target.fetch( |
|
181 |
repo_missing_fallbacks, |
|
6341.1.4
by Jelmer Vernooij
Move more functionality to vf_search. |
182 |
fetch_spec=vf_search.EverythingResult(repo_missing_fallbacks)) |
5539.2.7
by Andrew Bennetts
Add a test, revise a comment. |
183 |
self.assertEqual(repo_missing_fallbacks.revisions.keys(), |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
184 |
target.revisions.keys()) |
5539.2.7
by Andrew Bennetts
Add a test, revise a comment. |
185 |
self.assertEqual(repo_missing_fallbacks.inventories.keys(), |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
186 |
target.inventories.keys()) |
6973.6.2
by Jelmer Vernooij
Fix more tests. |
187 |
self.assertEqual([b'C-id'], |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
188 |
sorted(k[-1] for k in target.revisions.keys())) |
6973.6.2
by Jelmer Vernooij
Fix more tests. |
189 |
self.assertEqual([b'B-id', b'C-id'], |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
190 |
sorted(k[-1] for k in target.inventories.keys())) |