1
# Copyright (C) 2005 by Canonical Ltd
1
# Copyright (C) 2005 Canonical Ltd
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.
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.
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
21
from bzrlib import bzrdir, repository
20
22
from bzrlib.branch import Branch
21
23
from bzrlib.bzrdir import BzrDir
22
24
from bzrlib.builtins import merge
25
27
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
26
28
from bzrlib.tests.test_revision import make_branches
27
29
from bzrlib.trace import mutter
30
from bzrlib.upgrade import Convert
28
31
from bzrlib.workingtree import WorkingTree
113
116
wt = self.make_branch_and_tree('br')
114
117
self.assertEqual(wt.branch.fetch(wt.branch), (0, []))
119
def test_fetch_root_knit(self):
120
"""Ensure that knit2.fetch() updates the root knit
122
This tests the case where the root has a new revision, but there are no
123
corresponding filename, parent, contents or other changes.
125
knit1_format = bzrdir.BzrDirMetaFormat1()
126
knit1_format.repository_format = repository.RepositoryFormatKnit1()
127
knit2_format = bzrdir.BzrDirMetaFormat1()
128
knit2_format.repository_format = repository.RepositoryFormatKnit2()
129
# we start with a knit1 repository because that causes the
130
# root revision to change for each commit, even though the content,
131
# parent, name, and other attributes are unchanged.
132
tree = self.make_branch_and_tree('tree', knit1_format)
133
tree.set_root_id('tree-root')
134
tree.commit('rev1', rev_id='rev1')
135
tree.commit('rev2', rev_id='rev2')
137
# Now we convert it to a knit2 repository so that it has a root knit
138
Convert(tree.basedir, knit2_format)
139
tree = WorkingTree.open(tree.basedir)
140
branch = self.make_branch('branch', format=knit2_format)
141
branch.pull(tree.branch, stop_revision='rev1')
142
repo = branch.repository
143
root_knit = repo.weave_store.get_weave('tree-root',
144
repo.get_transaction())
145
# Make sure fetch retrieved only what we requested
146
self.assertTrue('rev1' in root_knit)
147
self.assertTrue('rev2' not in root_knit)
148
branch.pull(tree.branch)
149
root_knit = repo.weave_store.get_weave('tree-root',
150
repo.get_transaction())
151
# Make sure that the next revision in the root knit was retrieved,
152
# even though the text, name, parent_id, etc., were unchanged.
153
self.assertTrue('rev2' in root_knit)
117
156
class TestMergeFetch(TestCaseWithTransport):
199
238
def _count_log_matches(self, target, logs):
200
239
"""Count the number of times the target file pattern was fetched in an http log"""
201
log_pattern = '%s HTTP/1.1" 200 - "-" "bzr/%s' % \
202
(target, bzrlib.__version__)
240
get_succeeds_re = re.compile(
241
'.*"GET .*%s HTTP/1.1" 20[06] - "-" "bzr/%s' %
242
( target, bzrlib.__version__))
204
244
for line in logs:
205
# TODO: perhaps use a regexp instead so we can match more
207
if line.find(log_pattern) > -1:
245
if get_succeeds_re.match(line):
219
257
target = BzrDir.create_branch_and_repo("target/")
220
258
source = Branch.open(self.get_readonly_url("source/"))
221
259
self.assertEqual(target.fetch(source), (2, []))
222
log_pattern = '%%s HTTP/1.1" 200 - "-" "bzr/%s' % bzrlib.__version__
223
260
# this is the path to the literal file. As format changes
224
261
# occur it needs to be updated. FIXME: ask the store for the
226
263
self.log("web server logs are:")
227
264
http_logs = self.get_readonly_server().logs
228
265
self.log('\n'.join(http_logs))
229
self.assertEqual(1, self._count_log_matches('weaves/ce/id.weave', http_logs))
230
self.assertEqual(1, self._count_log_matches('inventory.weave', http_logs))
266
# unfortunately this log entry is branch format specific. We could
267
# factor out the 'what files does this format use' to a method on the
268
# repository, which would let us to this generically. RBC 20060419
269
self.assertEqual(1, self._count_log_matches('/ce/id.kndx', http_logs))
270
self.assertEqual(1, self._count_log_matches('/ce/id.knit', http_logs))
271
self.assertEqual(1, self._count_log_matches('inventory.kndx', http_logs))
231
272
# this r-h check test will prevent regressions, but it currently already
232
273
# passes, before the patch to cache-rh is applied :[
233
274
self.assertEqual(1, self._count_log_matches('revision-history', http_logs))
240
281
http_logs = self.get_readonly_server().logs
241
282
self.log("web server logs are:")
242
283
self.log('\n'.join(http_logs))
243
self.assertEqual(1, self._count_log_matches('branch-format', http_logs[0:1]))
244
self.assertEqual(1, self._count_log_matches('revision-history', http_logs[1:2]))
245
self.assertEqual(2, len(http_logs))
284
self.assertEqual(1, self._count_log_matches('branch-format', http_logs))
285
self.assertEqual(1, self._count_log_matches('branch/format', http_logs))
286
self.assertEqual(1, self._count_log_matches('repository/format', http_logs))
287
self.assertEqual(1, self._count_log_matches('revision-history', http_logs))
288
self.assertEqual(4, len(http_logs))