~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_fetch.py

Merge integration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import sys
19
19
 
20
20
from bzrlib.branch import Branch
 
21
from bzrlib.bzrdir import BzrDir
21
22
from bzrlib.builtins import merge
22
23
import bzrlib.errors
23
24
from bzrlib.fetch import greedy_fetch
29
30
 
30
31
 
31
32
def has_revision(branch, revision_id):
32
 
    try:
33
 
        branch.repository.get_revision_xml_file(revision_id)
34
 
        return True
35
 
    except bzrlib.errors.NoSuchRevision:
36
 
        return False
37
 
 
 
33
    return branch.repository.has_revision(revision_id)
38
34
 
39
35
def fetch_steps(self, br_a, br_b, writable_a):
40
36
    """A foreign test method for testing fetch locally and remotely."""
41
 
    def new_branch(name):
42
 
        os.mkdir(name)
43
 
        return WorkingTree.create_standalone(name).branch
44
 
            
45
 
    self.assertFalse(has_revision(br_b, br_a.revision_history()[3]))
46
 
    self.assert_(has_revision(br_b, br_a.revision_history()[2]))
 
37
     
 
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)
49
 
 
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]))
53
47
 
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]))
59
53
 
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, [])
66
60
 
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]))
70
64
        
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]))
76
70
 
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]))
82
76
 
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]))
 
82
        self.assertFalse(
 
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,
96
94
    br_a2.append_revision('a-b-c')
97
95
    self.assertRaises(bzrlib.errors.InstallFailed, greedy_fetch, br_a3,
98
96
                      br_a2)
99
 
 
100
 
 
101
97
    #TODO: test that fetch correctly does reweaving when needed. RBC 20051008
 
98
    # Note that this means - updating the weave when ghosts are filled in to 
 
99
    # add the right parents.
 
100
 
102
101
 
103
102
class TestFetch(TestCaseWithTransport):
104
103
 
128
127
        wt1 = self.make_branch_and_tree('br1')
129
128
        br1 = wt1.branch
130
129
        wt1.commit(message='rev 1-1', rev_id='1-1')
131
 
        br2 = br1.clone('br2')
 
130
        dir_2 = br1.bzrdir.sprout('br2')
 
131
        br2 = dir_2.open_branch()
132
132
        wt1.commit(message='rev 1-2', rev_id='1-2')
133
 
        WorkingTree('br2', br2).commit(message='rev 2-1', rev_id='2-1')
 
133
        dir_2.open_workingtree().commit(message='rev 2-1', rev_id='2-1')
134
134
        merge(other_revision=['br1', -1], base_revision=[None, None], 
135
135
              this_dir='br2')
136
136
        self._check_revs_present(br2)
152
152
        self.build_tree_contents([('br1/file', 'original contents\n')])
153
153
        wt1.add('file', 'this-file-id')
154
154
        wt1.commit(message='rev 1-1', rev_id='1-1')
155
 
        br2 = br1.clone('br2')
156
 
        wt2 = WorkingTree('br2', br2)
 
155
        dir_2 = br1.bzrdir.sprout('br2')
 
156
        br2 = dir_2.open_branch()
 
157
        wt2 = dir_2.open_workingtree()
157
158
        self.build_tree_contents([('br1/file', 'original from 1\n')])
158
159
        wt1.commit(message='rev 1-2', rev_id='1-2')
159
160
        self.build_tree_contents([('br1/file', 'agreement\n')])
184
185
 
185
186
    def test_fetch(self):
186
187
        #highest indices a: 5, b: 7
187
 
        print "TestHttpFetch.test_fetch disabled during transition."
188
 
        return
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)
192
191
 
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
206
205
        # path.
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))