~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/knitrepo.py

  • Committer: Vincent Ladeuil
  • Date: 2009-01-30 00:49:41 UTC
  • mto: (3982.1.1 bzr.integration)
  • mto: This revision was merged to the branch mainline in revision 3983.
  • Revision ID: v.ladeuil+lp@free.fr-20090130004941-820fpd2ryyo127vv
Add more tests, fix pycurl double handling, revert previous tracking.

* bzrlib/tests/test_http.py:
(PredefinedRequestHandler): Renamed from
PreRecordedRequestHandler.
(PredefinedRequestHandler.handle_one_request): Get the canned
response from the test server directly.
(ActivityServerMixin): Make it a true object and intialize the
attributes in the constructor. Tests can now set the
canned_response attribute before querying the server.
(TestActivity.setUp, TestActivity.tearDown,
TestActivity.get_transport, TestActivity.assertActivitiesMatch):
Extracted from test_get to be able to write other tests.
(TestActivity.test_has, TestActivity.test_readv,
TestActivity.test_post): New tests, all cases should be covered
now.

* bzrlib/transport/http/response.py:
(RangeFile.__init__, RangeFile.read, handle_response): Revert
previous tracking, both http implementations can now report
activity from the socket.

* bzrlib/transport/http/_pycurl.py:
(PyCurlTransport._get_ranged, PyCurlTransport._post): Revert
previous tracking.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
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
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
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
from bzrlib.lazy_import import lazy_import
18
18
lazy_import(globals(), """
24
24
    lockdir,
25
25
    osutils,
26
26
    revision as _mod_revision,
27
 
    trace,
28
27
    transactions,
29
28
    versionedfile,
30
29
    xml5,
43
42
    RepositoryFormat,
44
43
    RootCommitBuilder,
45
44
    )
 
45
from bzrlib.trace import mutter, mutter_callsite
46
46
 
47
47
 
48
48
class _KnitParentsProvider(object):
53
53
    def __repr__(self):
54
54
        return 'KnitParentsProvider(%r)' % self._knit
55
55
 
 
56
    @symbol_versioning.deprecated_method(symbol_versioning.one_one)
 
57
    def get_parents(self, revision_ids):
 
58
        """See graph._StackedParentsProvider.get_parents"""
 
59
        parent_map = self.get_parent_map(revision_ids)
 
60
        return [parent_map.get(r, None) for r in revision_ids]
 
61
 
56
62
    def get_parent_map(self, keys):
57
 
        """See graph.StackedParentsProvider.get_parent_map"""
 
63
        """See graph._StackedParentsProvider.get_parent_map"""
58
64
        parent_map = {}
59
65
        for revision_id in keys:
60
66
            if revision_id is None:
85
91
        return 'KnitsParentsProvider(%r)' % self._knit
86
92
 
87
93
    def get_parent_map(self, keys):
88
 
        """See graph.StackedParentsProvider.get_parent_map"""
 
94
        """See graph._StackedParentsProvider.get_parent_map"""
89
95
        parent_map = self._knit.get_parent_map(
90
96
            [self._prefix + (key,) for key in keys])
91
97
        result = {}
118
124
        self._commit_builder_class = _commit_builder_class
119
125
        self._serializer = _serializer
120
126
        self._reconcile_fixes_text_parents = True
 
127
        self._fetch_uses_deltas = True
 
128
        self._fetch_order = 'topological'
121
129
 
122
130
    @needs_read_lock
123
131
    def _all_revision_ids(self):
207
215
        revision_id = osutils.safe_revision_id(revision_id)
208
216
        return self.get_revision_reconcile(revision_id)
209
217
 
210
 
    def _refresh_data(self):
211
 
        if not self.is_locked():
212
 
            return
213
 
        # Create a new transaction to force all knits to see the scope change.
214
 
        # This is safe because we're outside a write group.
215
 
        self.control_files._finish_transaction()
216
 
        if self.is_write_locked():
217
 
            self.control_files._set_write_transaction()
218
 
        else:
219
 
            self.control_files._set_read_transaction()
220
 
 
221
218
    @needs_write_lock
222
219
    def reconcile(self, other=None, thorough=False):
223
220
        """Reconcile this repository."""
225
222
        reconciler = KnitReconciler(self, thorough=thorough)
226
223
        reconciler.reconcile()
227
224
        return reconciler
228
 
 
 
225
    
229
226
    def _make_parents_provider(self):
230
227
        return _KnitsParentsProvider(self.revisions)
231
228
 
232
 
    def _find_inconsistent_revision_parents(self, revisions_iterator=None):
 
229
    def _find_inconsistent_revision_parents(self):
233
230
        """Find revisions with different parent lists in the revision object
234
231
        and in the index graph.
235
232
 
236
 
        :param revisions_iterator: None, or an iterator of (revid,
237
 
            Revision-or-None). This iterator controls the revisions checked.
238
233
        :returns: an iterator yielding tuples of (revison-id, parents-in-index,
239
234
            parents-in-revision).
240
235
        """
241
236
        if not self.is_locked():
242
237
            raise AssertionError()
243
238
        vf = self.revisions
244
 
        if revisions_iterator is None:
245
 
            revisions_iterator = self._iter_revisions(None)
246
 
        for revid, revision in revisions_iterator:
247
 
            if revision is None:
248
 
                pass
249
 
            parent_map = vf.get_parent_map([(revid,)])
 
239
        for index_version in vf.keys():
 
240
            parent_map = vf.get_parent_map([index_version])
250
241
            parents_according_to_index = tuple(parent[-1] for parent in
251
 
                parent_map[(revid,)])
 
242
                parent_map[index_version])
 
243
            revision = self.get_revision(index_version[-1])
252
244
            parents_according_to_revision = tuple(revision.parent_ids)
253
245
            if parents_according_to_index != parents_according_to_revision:
254
 
                yield (revid, parents_according_to_index,
 
246
                yield (index_version[-1], parents_according_to_index,
255
247
                    parents_according_to_revision)
256
248
 
257
249
    def _check_for_inconsistent_revision_parents(self):
267
259
 
268
260
 
269
261
class RepositoryFormatKnit(MetaDirRepositoryFormat):
270
 
    """Bzr repository knit format (generalized).
 
262
    """Bzr repository knit format (generalized). 
271
263
 
272
264
    This repository format has:
273
265
     - knits for file texts and inventory
296
288
    supports_ghosts = True
297
289
    # External lookups are not supported in this format.
298
290
    supports_external_lookups = False
299
 
    # No CHK support.
300
 
    supports_chks = False
301
 
    _fetch_order = 'topological'
302
 
    _fetch_uses_deltas = True
303
 
    fast_deltas = False
304
291
 
305
292
    def _get_inventories(self, repo_transport, repo, name='inventory'):
306
293
        mapper = versionedfile.ConstantMapper(name)
342
329
        :param shared: If true the repository will be initialized as a shared
343
330
                       repository.
344
331
        """
345
 
        trace.mutter('creating repository in %s.', a_bzrdir.transport.base)
 
332
        mutter('creating repository in %s.', a_bzrdir.transport.base)
346
333
        dirs = ['knits']
347
334
        files = []
348
335
        utf8_files = [('format', self.get_format_string())]
349
 
 
 
336
        
350
337
        self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
351
338
        repo_transport = a_bzrdir.get_repository_transport(None)
352
339
        control_files = lockable_files.LockableFiles(repo_transport,
360
347
        result.revisions.get_parent_map([('A',)])
361
348
        result.signatures.get_parent_map([('A',)])
362
349
        result.unlock()
363
 
        self._run_post_repo_init_hooks(result, a_bzrdir, shared)
364
350
        return result
365
351
 
366
352
    def open(self, a_bzrdir, _found=False, _override_transport=None):
367
353
        """See RepositoryFormat.open().
368
 
 
 
354
        
369
355
        :param _override_transport: INTERNAL USE ONLY. Allows opening the
370
356
                                    repository at a slightly different url
371
357
                                    than normal. I.e. during 'upgrade'.
387
373
        repo.signatures = self._get_signatures(repo_transport, repo)
388
374
        repo.inventories = self._get_inventories(repo_transport, repo)
389
375
        repo.texts = self._get_texts(repo_transport, repo)
390
 
        repo.chk_bytes = None
391
376
        repo._transport = repo_transport
392
377
        return repo
393
378
 
425
410
        """See RepositoryFormat.get_format_description()."""
426
411
        return "Knit repository format 1"
427
412
 
 
413
    def check_conversion_target(self, target_format):
 
414
        pass
 
415
 
428
416
 
429
417
class RepositoryFormatKnit3(RepositoryFormatKnit):
430
418
    """Bzr repository knit format 3.
445
433
    repository_class = KnitRepository
446
434
    _commit_builder_class = RootCommitBuilder
447
435
    rich_root_data = True
448
 
    experimental = True
449
436
    supports_tree_reference = True
450
437
    @property
451
438
    def _serializer(self):
459
446
 
460
447
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
461
448
 
 
449
    def check_conversion_target(self, target_format):
 
450
        if not target_format.rich_root_data:
 
451
            raise errors.BadConversionTarget(
 
452
                'Does not support rich root data.', target_format)
 
453
        if not getattr(target_format, 'supports_tree_reference', False):
 
454
            raise errors.BadConversionTarget(
 
455
                'Does not support nested trees', target_format)
 
456
            
462
457
    def get_format_string(self):
463
458
        """See RepositoryFormat.get_format_string()."""
464
459
        return "Bazaar Knit Repository Format 3 (bzr 0.15)\n"
500
495
 
501
496
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
502
497
 
 
498
    def check_conversion_target(self, target_format):
 
499
        if not target_format.rich_root_data:
 
500
            raise errors.BadConversionTarget(
 
501
                'Does not support rich root data.', target_format)
 
502
 
503
503
    def get_format_string(self):
504
504
        """See RepositoryFormat.get_format_string()."""
505
505
        return 'Bazaar Knit Repository Format 4 (bzr 1.0)\n'