31
31
def has_revision(branch, revision_id):
33
branch.repository.get_revision_xml_file(revision_id)
35
except bzrlib.errors.NoSuchRevision:
32
return branch.repository.has_revision(revision_id)
39
34
def fetch_steps(self, br_a, br_b, writable_a):
40
35
"""A foreign test method for testing fetch locally and remotely."""
43
return WorkingTree.create_standalone(name).branch
45
self.assertFalse(has_revision(br_b, br_a.revision_history()[3]))
46
self.assert_(has_revision(br_b, br_a.revision_history()[2]))
47
self.assertEquals(len(br_b.revision_history()), 7)
48
self.assertEquals(greedy_fetch(br_b, br_a, br_a.revision_history()[2])[0], 0)
50
# greedy_fetch is not supposed to alter the revision history
51
self.assertEquals(len(br_b.revision_history()), 7)
52
self.assertFalse(has_revision(br_b, br_a.revision_history()[3]))
54
self.assertEquals(len(br_b.revision_history()), 7)
55
self.assertEquals(greedy_fetch(br_b, br_a, br_a.revision_history()[3])[0], 1)
56
self.assert_(has_revision(br_b, br_a.revision_history()[3]))
37
# TODO RBC 20060201 make this a repository test.
38
repo_b = br_b.repository
39
self.assertFalse(repo_b.has_revision(br_a.revision_history()[3]))
40
self.assertTrue(repo_b.has_revision(br_a.revision_history()[2]))
41
self.assertEquals(len(br_b.revision_history()), 7)
42
self.assertEquals(br_b.fetch(br_a, br_a.revision_history()[2])[0], 0)
43
# branch.fetch is not supposed to alter the revision history
44
self.assertEquals(len(br_b.revision_history()), 7)
45
self.assertFalse(repo_b.has_revision(br_a.revision_history()[3]))
47
# fetching the next revision up in sample data copies one revision
48
self.assertEquals(br_b.fetch(br_a, br_a.revision_history()[3])[0], 1)
49
self.assertTrue(repo_b.has_revision(br_a.revision_history()[3]))
57
50
self.assertFalse(has_revision(br_a, br_b.revision_history()[6]))
58
self.assert_(has_revision(br_a, br_b.revision_history()[5]))
51
self.assertTrue(br_a.repository.has_revision(br_b.revision_history()[5]))
60
53
# When a non-branch ancestor is missing, it should be unlisted...
61
54
# as its not reference from the inventory weave.
62
br_b4 = new_branch('br_4')
63
count, failures = greedy_fetch(br_b4, br_b)
55
br_b4 = self.make_branch('br_4')
56
count, failures = br_b4.fetch(br_b)
64
57
self.assertEqual(count, 7)
65
58
self.assertEqual(failures, [])
67
self.assertEqual(greedy_fetch(writable_a, br_b)[0], 1)
68
self.assert_(has_revision(br_a, br_b.revision_history()[3]))
69
self.assert_(has_revision(br_a, br_b.revision_history()[4]))
60
self.assertEqual(writable_a.fetch(br_b)[0], 1)
61
self.assertTrue(has_revision(br_a, br_b.revision_history()[3]))
62
self.assertTrue(has_revision(br_a, br_b.revision_history()[4]))
71
br_b2 = new_branch('br_b2')
72
self.assertEquals(greedy_fetch(br_b2, br_b)[0], 7)
73
self.assert_(has_revision(br_b2, br_b.revision_history()[4]))
74
self.assert_(has_revision(br_b2, br_a.revision_history()[2]))
64
br_b2 = self.make_branch('br_b2')
65
self.assertEquals(br_b2.fetch(br_b)[0], 7)
66
self.assertTrue(has_revision(br_b2, br_b.revision_history()[4]))
67
self.assertTrue(has_revision(br_b2, br_a.revision_history()[2]))
75
68
self.assertFalse(has_revision(br_b2, br_a.revision_history()[3]))
77
br_a2 = new_branch('br_a2')
78
self.assertEquals(greedy_fetch(br_a2, br_a)[0], 9)
79
self.assert_(has_revision(br_a2, br_b.revision_history()[4]))
80
self.assert_(has_revision(br_a2, br_a.revision_history()[3]))
81
self.assert_(has_revision(br_a2, br_a.revision_history()[2]))
70
br_a2 = self.make_branch('br_a2')
71
self.assertEquals(br_a2.fetch(br_a)[0], 9)
72
self.assertTrue(has_revision(br_a2, br_b.revision_history()[4]))
73
self.assertTrue(has_revision(br_a2, br_a.revision_history()[3]))
74
self.assertTrue(has_revision(br_a2, br_a.revision_history()[2]))
83
br_a3 = new_branch('br_a3')
84
self.assertEquals(greedy_fetch(br_a3, br_a2)[0], 0)
76
br_a3 = self.make_branch('br_a3')
77
# pulling a branch with no revisions grabs nothing, regardless of
78
# whats in the inventory.
79
self.assertEquals(br_a3.fetch(br_a2)[0], 0)
85
80
for revno in range(4):
86
self.assertFalse(has_revision(br_a3, br_a.revision_history()[revno]))
87
self.assertEqual(greedy_fetch(br_a3, br_a2, br_a.revision_history()[2])[0], 3)
88
fetched = greedy_fetch(br_a3, br_a2, br_a.revision_history()[3])[0]
89
self.assertEquals(fetched, 6, "fetched %d instead of 6" % fetched)
82
br_a3.repository.has_revision(br_a.revision_history()[revno]))
83
self.assertEqual(br_a3.fetch(br_a2, br_a.revision_history()[2])[0], 3)
84
# pull the 3 revisions introduced by a@u-0-3
85
fetched = br_a3.fetch(br_a2, br_a.revision_history()[3])[0]
86
self.assertEquals(fetched, 3, "fetched %d instead of 3" % fetched)
90
87
# InstallFailed should be raised if the branch is missing the revision
91
88
# that was requested.
92
self.assertRaises(bzrlib.errors.InstallFailed, greedy_fetch, br_a3,
89
self.assertRaises(bzrlib.errors.InstallFailed, br_a3.fetch, br_a2, 'pizza')
94
90
# InstallFailed should be raised if the branch is missing a revision
95
91
# from its own revision history
96
92
br_a2.append_revision('a-b-c')
97
self.assertRaises(bzrlib.errors.InstallFailed, greedy_fetch, br_a3,
93
self.assertRaises(bzrlib.errors.InstallFailed, br_a3.fetch, br_a2)
101
94
#TODO: test that fetch correctly does reweaving when needed. RBC 20051008
95
# Note that this means - updating the weave when ghosts are filled in to
96
# add the right parents.
103
99
class TestFetch(TestCaseWithTransport):
185
183
def test_fetch(self):
186
184
#highest indices a: 5, b: 7
187
print "TestHttpFetch.test_fetch disabled during transition."
189
185
br_a, br_b = make_branches(self)
190
br_rem_a = Branch.open(self.get_remote_url(br_a.base))
186
br_rem_a = Branch.open(self.get_readonly_url('branch1'))
191
187
fetch_steps(self, br_rem_a, br_b, br_a)
193
189
def test_weaves_are_retrieved_once(self):
194
190
self.build_tree(("source/", "source/file", "target/"))
195
wt = WorkingTree.create_standalone('source')
191
wt = self.make_branch_and_tree('source')
196
192
branch = wt.branch
197
193
wt.add(["file"], ["id"])
198
194
wt.commit("added file")
199
195
print >>open("source/file", 'w'), "blah"
200
196
wt.commit("changed file")
201
target = Branch.create("target/")
202
source = Branch.open(self.get_remote_url("source/"))
203
self.assertEqual(greedy_fetch(target, source), (2, []))
197
target = BzrDir.create_branch_and_repo("target/")
198
source = Branch.open(self.get_readonly_url("source/"))
199
self.assertEqual(target.fetch(source), (2, []))
200
log_pattern = '%%s HTTP/1.1" 200 - "-" "bzr/%s"' % bzrlib.__version__
204
201
# this is the path to the literal file. As format changes
205
202
# occur it needs to be updated. FIXME: ask the store for the
207
weave_suffix = 'weaves/ce/id.weave HTTP/1.1" 200 -'
209
len([log for log in self.server.logs if log.endswith(weave_suffix)]))
210
inventory_weave_suffix = 'inventory.weave HTTP/1.1" 200 -'
212
len([log for log in self.server.logs if log.endswith(
204
weave_suffix = log_pattern % 'weaves/ce/id.weave'
206
len([log for log in self.get_readonly_server().logs if log.endswith(weave_suffix)]))
207
inventory_weave_suffix = log_pattern % 'inventory.weave'
209
len([log for log in self.get_readonly_server().logs if log.endswith(
213
210
inventory_weave_suffix)]))
214
211
# this r-h check test will prevent regressions, but it currently already
215
212
# passes, before the patch to cache-rh is applied :[
216
revision_history_suffix = 'revision-history HTTP/1.1" 200 -'
213
revision_history_suffix = log_pattern % 'revision-history'
217
214
self.assertEqual(1,
218
len([log for log in self.server.logs if log.endswith(
215
len([log for log in self.get_readonly_server().logs if log.endswith(
219
216
revision_history_suffix)]))
220
217
# FIXME naughty poking in there.
221
self.server.logs = []
218
self.get_readonly_server().logs = []
222
219
# check there is nothing more to fetch
223
source = Branch.open(self.get_remote_url("source/"))
224
self.assertEqual(greedy_fetch(target, source), (0, []))
225
self.failUnless(self.server.logs[0].endswith('branch-format HTTP/1.1" 200 -'))
226
self.failUnless(self.server.logs[1].endswith('revision-history HTTP/1.1" 200 -'))
227
self.assertEqual(2, len(self.server.logs))
220
source = Branch.open(self.get_readonly_url("source/"))
221
self.assertEqual(target.fetch(source), (0, []))
222
self.failUnless(self.get_readonly_server().logs[0].endswith(log_pattern % 'branch-format'))
223
self.failUnless(self.get_readonly_server().logs[1].endswith(log_pattern % 'revision-history'))
224
self.assertEqual(2, len(self.get_readonly_server().logs))