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 |
||
|
4392.2.2
by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry. |
18 |
from bzrlib import ( |
19 |
branch, |
|
20 |
errors, |
|
|
5539.2.7
by Andrew Bennetts
Add a test, revise a comment. |
21 |
graph, |
|
4392.2.2
by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry. |
22 |
)
|
23 |
from bzrlib.smart import ( |
|
24 |
server, |
|
25 |
)
|
|
|
4343.3.10
by John Arbash Meinel
Add a per_repository_reference test with real stacked repos. |
26 |
from bzrlib.tests.per_repository import TestCaseWithRepository |
27 |
||
28 |
||
|
5539.2.7
by Andrew Bennetts
Add a test, revise a comment. |
29 |
class TestFetchBase(TestCaseWithRepository): |
|
4343.3.10
by John Arbash Meinel
Add a per_repository_reference test with real stacked repos. |
30 |
|
|
4343.3.17
by John Arbash Meinel
Finally found a way to write a test case to exercise the code path. |
31 |
def make_source_branch(self): |
32 |
# 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. |
33 |
builder = self.make_branch_builder('source') |
34 |
content = ['content lines\n' |
|
35 |
'for the first revision\n' |
|
36 |
'which is a marginal amount of content\n' |
|
37 |
]
|
|
38 |
builder.start_series() |
|
39 |
builder.build_snapshot('A-id', None, [ |
|
40 |
('add', ('', 'root-id', 'directory', None)), |
|
41 |
('add', ('a', 'a-id', 'file', ''.join(content))), |
|
42 |
])
|
|
43 |
content.append('and some more lines for B\n') |
|
44 |
builder.build_snapshot('B-id', ['A-id'], [ |
|
45 |
('modify', ('a-id', ''.join(content)))]) |
|
46 |
content.append('and yet even more content for C\n') |
|
47 |
builder.build_snapshot('C-id', ['B-id'], [ |
|
48 |
('modify', ('a-id', ''.join(content)))]) |
|
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') |
|
64 |
stack_b.pull(source_b, stop_revision='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') |
|
4343.3.10
by John Arbash Meinel
Add a per_repository_reference test with real stacked repos. |
67 |
target_b.pull(source_b, stop_revision='C-id') |
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) |
|
74 |
self.assertEqual('C-id', final_b.last_revision()) |
|
75 |
text_keys = [('a-id', 'A-id'), ('a-id', 'B-id'), ('a-id', 'C-id')] |
|
76 |
stream = final_b.repository.texts.get_record_stream(text_keys, |
|
77 |
'unordered', True) |
|
|
4343.3.36
by John Arbash Meinel
Some review feedback from Andrew. |
78 |
records = sorted([(r.key, r.get_bytes_as('fulltext')) for r in stream]) |
79 |
self.assertEqual([ |
|
80 |
(('a-id', 'A-id'), ''.join(content[:-2])), |
|
81 |
(('a-id', 'B-id'), ''.join(content[:-1])), |
|
82 |
(('a-id', 'C-id'), ''.join(content)), |
|
83 |
], records) |
|
|
4343.3.17
by John Arbash Meinel
Finally found a way to write a test case to exercise the code path. |
84 |
|
85 |
def test_sprout_from_smart_stacked_with_short_history(self): |
|
86 |
content, source_b = self.make_source_branch() |
|
87 |
transport = self.make_smart_server('server') |
|
88 |
transport.ensure_base() |
|
89 |
url = transport.abspath('') |
|
90 |
stack_b = source_b.bzrdir.sprout(url + '/stack-on', revision_id='B-id') |
|
91 |
# self.make_branch only takes relative paths, so we do it the 'hard'
|
|
92 |
# way
|
|
93 |
target_transport = transport.clone('target') |
|
94 |
target_transport.ensure_base() |
|
95 |
target_bzrdir = self.bzrdir_format.initialize_on_transport( |
|
96 |
target_transport) |
|
97 |
target_bzrdir.create_repository() |
|
98 |
target_b = target_bzrdir.create_branch() |
|
99 |
target_b.set_stacked_on_url('../stack-on') |
|
100 |
target_b.pull(source_b, stop_revision='C-id') |
|
101 |
# Now we should be able to branch from the remote location to a local
|
|
102 |
# location
|
|
103 |
final_b = target_b.bzrdir.sprout('final').open_branch() |
|
104 |
self.assertEqual('C-id', final_b.last_revision()) |
|
105 |
||
106 |
# bzrdir.sprout() has slightly different code paths if you supply a
|
|
107 |
# revision_id versus not. If you supply revision_id, then you get a
|
|
108 |
# PendingAncestryResult for the search, versus a SearchResult...
|
|
109 |
final2_b = target_b.bzrdir.sprout('final2', |
|
110 |
revision_id='C-id').open_branch() |
|
111 |
self.assertEqual('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. |
112 |
|
113 |
def make_source_with_ghost_and_stacked_target(self): |
|
114 |
builder = self.make_branch_builder('source') |
|
115 |
builder.start_series() |
|
116 |
builder.build_snapshot('A-id', None, [ |
|
117 |
('add', ('', 'root-id', 'directory', None)), |
|
118 |
('add', ('file', 'file-id', 'file', 'content\n'))]) |
|
119 |
builder.build_snapshot('B-id', ['A-id', 'ghost-id'], []) |
|
120 |
builder.finish_series() |
|
121 |
source_b = builder.get_branch() |
|
122 |
source_b.lock_read() |
|
123 |
self.addCleanup(source_b.unlock) |
|
124 |
base = self.make_branch('base') |
|
125 |
base.pull(source_b, stop_revision='A-id') |
|
126 |
stacked = self.make_branch('stacked') |
|
127 |
stacked.set_stacked_on_url('../base') |
|
128 |
return source_b, base, stacked |
|
129 |
||
130 |
def test_fetch_with_ghost_stacked(self): |
|
131 |
(source_b, base, |
|
132 |
stacked) = self.make_source_with_ghost_and_stacked_target() |
|
133 |
stacked.pull(source_b, stop_revision='B-id') |
|
134 |
||
135 |
def test_fetch_into_smart_stacked_with_ghost(self): |
|
136 |
(source_b, base, |
|
137 |
stacked) = self.make_source_with_ghost_and_stacked_target() |
|
138 |
# Now, create a smart server on 'stacked' and re-open to force the
|
|
139 |
# target to be a smart target
|
|
140 |
trans = self.make_smart_server('stacked') |
|
141 |
stacked = branch.Branch.open(trans.base) |
|
142 |
stacked.lock_write() |
|
143 |
self.addCleanup(stacked.unlock) |
|
144 |
stacked.pull(source_b, stop_revision='B-id') |
|
145 |
||
146 |
def test_fetch_to_stacked_from_smart_with_ghost(self): |
|
147 |
(source_b, base, |
|
148 |
stacked) = self.make_source_with_ghost_and_stacked_target() |
|
149 |
# Now, create a smart server on 'source' and re-open to force the
|
|
150 |
# target to be a smart target
|
|
151 |
trans = self.make_smart_server('source') |
|
152 |
source_b = branch.Branch.open(trans.base) |
|
153 |
source_b.lock_read() |
|
154 |
self.addCleanup(source_b.unlock) |
|
155 |
stacked.pull(source_b, stop_revision='B-id') |
|
|
5539.2.7
by Andrew Bennetts
Add a test, revise a comment. |
156 |
|
157 |
||
158 |
class TestFetchFromRepoWithUnconfiguredFallbacks(TestFetchBase): |
|
159 |
||
160 |
def make_stacked_source_repo(self): |
|
161 |
_, source_b = self.make_source_branch() |
|
162 |
# Use 'make_branch' which gives us a bzr:// branch when appropriate,
|
|
163 |
# rather than creating a branch-on-disk
|
|
164 |
stack_b = self.make_branch('stack-on') |
|
165 |
stack_b.pull(source_b, stop_revision='B-id') |
|
166 |
stacked_b = self.make_branch('stacked') |
|
167 |
stacked_b.set_stacked_on_url('../stack-on') |
|
168 |
stacked_b.pull(source_b, stop_revision='C-id') |
|
169 |
return stacked_b.repository |
|
170 |
||
171 |
def test_fetch_everything_includes_parent_invs(self): |
|
172 |
stacked = self.make_stacked_source_repo() |
|
173 |
repo_missing_fallbacks = stacked.bzrdir.open_repository() |
|
174 |
self.addCleanup(repo_missing_fallbacks.lock_read().unlock) |
|
175 |
target = self.make_repository('target') |
|
176 |
self.addCleanup(target.lock_write().unlock) |
|
177 |
target.fetch( |
|
178 |
repo_missing_fallbacks, |
|
179 |
fetch_spec=graph.EverythingResult(repo_missing_fallbacks)) |
|
180 |
self.assertEqual(repo_missing_fallbacks.revisions.keys(), |
|
181 |
target.revisions.keys()) |
|
182 |
self.assertEqual(repo_missing_fallbacks.inventories.keys(), |
|
183 |
target.inventories.keys()) |
|
184 |
self.assertEqual(['C-id'], |
|
185 |
sorted(k[-1] for k in target.revisions.keys())) |
|
186 |
self.assertEqual(['B-id', 'C-id'], |
|
187 |
sorted(k[-1] for k in target.inventories.keys())) |
|
188 |
||
189 |
||
190 |