~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_fetch.py

  • Committer: Martin Pool
  • Date: 2006-03-21 12:26:54 UTC
  • mto: This revision was merged to the branch mainline in revision 1621.
  • Revision ID: mbp@sourcefrog.net-20060321122654-514047ed65795a17
New developer commands 'weave-list' and 'weave-join'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
2
 
#
 
1
# Copyright (C) 2005 by Canonical Ltd
 
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
#
 
7
 
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
#
 
12
 
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import os
18
 
import re
19
18
import sys
20
19
 
21
 
from bzrlib import (
22
 
    bzrdir,
23
 
    errors,
24
 
    repository,
25
 
    )
26
20
from bzrlib.branch import Branch
27
21
from bzrlib.bzrdir import BzrDir
28
22
from bzrlib.builtins import merge
29
23
import bzrlib.errors
30
 
from bzrlib.repofmt import knitrepo
31
24
from bzrlib.tests import TestCaseWithTransport
32
25
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
33
26
from bzrlib.tests.test_revision import make_branches
34
27
from bzrlib.trace import mutter
35
 
from bzrlib.upgrade import Convert
36
28
from bzrlib.workingtree import WorkingTree
37
29
 
38
30
 
99
91
    # from its own revision history
100
92
    br_a2.append_revision('a-b-c')
101
93
    self.assertRaises(bzrlib.errors.InstallFailed, br_a3.fetch, br_a2)
102
 
 
103
 
    # TODO: ADHB 20070116 Perhaps set_last_revision shouldn't accept
104
 
    #       revisions which are not present?  In that case, this test
105
 
    #       must be rewritten.
106
 
    #
107
 
    #       RBC 20060403 the way to do this is to uncommit the revision from
108
 
    #       the repository after the commit
109
 
 
110
94
    #TODO: test that fetch correctly does reweaving when needed. RBC 20051008
111
95
    # Note that this means - updating the weave when ghosts are filled in to 
112
96
    # add the right parents.
123
107
        wt = self.make_branch_and_tree('br')
124
108
        self.assertEqual(wt.branch.fetch(wt.branch), (0, []))
125
109
 
126
 
    def test_fetch_root_knit(self):
127
 
        """Ensure that knit2.fetch() updates the root knit
128
 
        
129
 
        This tests the case where the root has a new revision, but there are no
130
 
        corresponding filename, parent, contents or other changes.
131
 
        """
132
 
        knit1_format = bzrdir.BzrDirMetaFormat1()
133
 
        knit1_format.repository_format = knitrepo.RepositoryFormatKnit1()
134
 
        knit2_format = bzrdir.BzrDirMetaFormat1()
135
 
        knit2_format.repository_format = knitrepo.RepositoryFormatKnit3()
136
 
        # we start with a knit1 repository because that causes the
137
 
        # root revision to change for each commit, even though the content,
138
 
        # parent, name, and other attributes are unchanged.
139
 
        tree = self.make_branch_and_tree('tree', knit1_format)
140
 
        tree.set_root_id('tree-root')
141
 
        tree.commit('rev1', rev_id='rev1')
142
 
        tree.commit('rev2', rev_id='rev2')
143
 
 
144
 
        # Now we convert it to a knit2 repository so that it has a root knit
145
 
        Convert(tree.basedir, knit2_format)
146
 
        tree = WorkingTree.open(tree.basedir)
147
 
        branch = self.make_branch('branch', format=knit2_format)
148
 
        branch.pull(tree.branch, stop_revision='rev1')
149
 
        repo = branch.repository
150
 
        root_knit = repo.weave_store.get_weave('tree-root',
151
 
                                                repo.get_transaction())
152
 
        # Make sure fetch retrieved only what we requested
153
 
        self.assertTrue('rev1' in root_knit)
154
 
        self.assertTrue('rev2' not in root_knit)
155
 
        branch.pull(tree.branch)
156
 
        root_knit = repo.weave_store.get_weave('tree-root',
157
 
                                                repo.get_transaction())
158
 
        # Make sure that the next revision in the root knit was retrieved,
159
 
        # even though the text, name, parent_id, etc., were unchanged.
160
 
        self.assertTrue('rev2' in root_knit)
161
 
 
162
 
    def test_fetch_incompatible(self):
163
 
        knit_tree = self.make_branch_and_tree('knit', format='knit')
164
 
        knit3_tree = self.make_branch_and_tree('knit3',
165
 
            format='dirstate-with-subtree')
166
 
        knit3_tree.commit('blah')
167
 
        self.assertRaises(errors.IncompatibleRepositories,
168
 
                          knit_tree.branch.fetch, knit3_tree.branch)
169
 
 
170
110
 
171
111
class TestMergeFetch(TestCaseWithTransport):
172
112
 
252
192
 
253
193
    def _count_log_matches(self, target, logs):
254
194
        """Count the number of times the target file pattern was fetched in an http log"""
255
 
        get_succeeds_re = re.compile(
256
 
            '.*"GET .*%s HTTP/1.1" 20[06] - "-" "bzr/%s' %
257
 
            (     target,                    bzrlib.__version__))
 
195
        log_pattern = '%s HTTP/1.1" 200 - "-" "bzr/%s' % \
 
196
            (target, bzrlib.__version__)
258
197
        c = 0
259
198
        for line in logs:
260
 
            if get_succeeds_re.match(line):
 
199
            # TODO: perhaps use a regexp instead so we can match more
 
200
            # precisely?
 
201
            if line.find(log_pattern) > -1:
261
202
                c += 1
262
203
        return c
263
204
 
272
213
        target = BzrDir.create_branch_and_repo("target/")
273
214
        source = Branch.open(self.get_readonly_url("source/"))
274
215
        self.assertEqual(target.fetch(source), (2, []))
 
216
        log_pattern = '%%s HTTP/1.1" 200 - "-" "bzr/%s' % bzrlib.__version__
275
217
        # this is the path to the literal file. As format changes 
276
218
        # occur it needs to be updated. FIXME: ask the store for the
277
219
        # path.
278
220
        self.log("web server logs are:")
279
221
        http_logs = self.get_readonly_server().logs
280
222
        self.log('\n'.join(http_logs))
281
 
        # unfortunately this log entry is branch format specific. We could 
282
 
        # factor out the 'what files does this format use' to a method on the 
283
 
        # repository, which would let us to this generically. RBC 20060419
284
 
        self.assertEqual(1, self._count_log_matches('/ce/id.kndx', http_logs))
285
 
        self.assertEqual(1, self._count_log_matches('/ce/id.knit', http_logs))
286
 
        self.assertEqual(1, self._count_log_matches('inventory.kndx', http_logs))
 
223
        self.assertEqual(1, self._count_log_matches('weaves/ce/id.weave', http_logs))
 
224
        self.assertEqual(1, self._count_log_matches('inventory.weave', http_logs))
287
225
        # this r-h check test will prevent regressions, but it currently already 
288
226
        # passes, before the patch to cache-rh is applied :[
289
 
        self.assertTrue(1 >= self._count_log_matches('revision-history',
290
 
                                                     http_logs))
291
 
        self.assertTrue(1 >= self._count_log_matches('last-revision',
292
 
                                                     http_logs))
 
227
        self.assertEqual(1, self._count_log_matches('revision-history', http_logs))
293
228
        # FIXME naughty poking in there.
294
229
        self.get_readonly_server().logs = []
295
230
        # check there is nothing more to fetch
299
234
        http_logs = self.get_readonly_server().logs
300
235
        self.log("web server logs are:")
301
236
        self.log('\n'.join(http_logs))
302
 
        self.assertEqual(1, self._count_log_matches('branch-format', http_logs))
303
 
        self.assertEqual(1, self._count_log_matches('branch/format', http_logs))
304
 
        self.assertEqual(1, self._count_log_matches('repository/format', http_logs))
305
 
        self.assertTrue(1 >= self._count_log_matches('revision-history',
306
 
                                                     http_logs))
307
 
        self.assertTrue(1 >= self._count_log_matches('last-revision',
308
 
                                                     http_logs))
309
 
        self.assertEqual(4, len(http_logs))
 
237
        self.assertEqual(1, self._count_log_matches('branch-format', http_logs[0:1]))
 
238
        self.assertEqual(1, self._count_log_matches('revision-history', http_logs[1:2]))
 
239
        self.assertEqual(2, len(http_logs))