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