~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/knitrepo.py

  • Committer: Robert Collins
  • Date: 2010-05-06 23:41:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506234135-yivbzczw1sejxnxc
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
expected to return an object which can be used to unlock them. This reduces
duplicate code when using cleanups. The previous 'tokens's returned by
``Branch.lock_write`` and ``Repository.lock_write`` are now attributes
on the result of the lock_write. ``repository.RepositoryWriteLockResult``
and ``branch.BranchWriteLockResult`` document this. (Robert Collins)

``log._get_info_for_log_files`` now takes an add_cleanup callable.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2007-2010 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
24
24
    lockdir,
25
25
    osutils,
26
26
    revision as _mod_revision,
 
27
    trace,
27
28
    transactions,
28
29
    versionedfile,
29
30
    xml5,
42
43
    RepositoryFormat,
43
44
    RootCommitBuilder,
44
45
    )
45
 
from bzrlib.trace import mutter, mutter_callsite
46
46
 
47
47
 
48
48
class _KnitParentsProvider(object):
229
229
    def _make_parents_provider(self):
230
230
        return _KnitsParentsProvider(self.revisions)
231
231
 
232
 
    def _find_inconsistent_revision_parents(self):
 
232
    def _find_inconsistent_revision_parents(self, revisions_iterator=None):
233
233
        """Find revisions with different parent lists in the revision object
234
234
        and in the index graph.
235
235
 
 
236
        :param revisions_iterator: None, or an iterator of (revid,
 
237
            Revision-or-None). This iterator controls the revisions checked.
236
238
        :returns: an iterator yielding tuples of (revison-id, parents-in-index,
237
239
            parents-in-revision).
238
240
        """
239
241
        if not self.is_locked():
240
242
            raise AssertionError()
241
243
        vf = self.revisions
242
 
        for index_version in vf.keys():
243
 
            parent_map = vf.get_parent_map([index_version])
 
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,)])
244
250
            parents_according_to_index = tuple(parent[-1] for parent in
245
 
                parent_map[index_version])
246
 
            revision = self.get_revision(index_version[-1])
 
251
                parent_map[(revid,)])
247
252
            parents_according_to_revision = tuple(revision.parent_ids)
248
253
            if parents_according_to_index != parents_according_to_revision:
249
 
                yield (index_version[-1], parents_according_to_index,
 
254
                yield (revid, parents_according_to_index,
250
255
                    parents_according_to_revision)
251
256
 
252
257
    def _check_for_inconsistent_revision_parents(self):
337
342
        :param shared: If true the repository will be initialized as a shared
338
343
                       repository.
339
344
        """
340
 
        mutter('creating repository in %s.', a_bzrdir.transport.base)
 
345
        trace.mutter('creating repository in %s.', a_bzrdir.transport.base)
341
346
        dirs = ['knits']
342
347
        files = []
343
348
        utf8_files = [('format', self.get_format_string())]
355
360
        result.revisions.get_parent_map([('A',)])
356
361
        result.signatures.get_parent_map([('A',)])
357
362
        result.unlock()
 
363
        self._run_post_repo_init_hooks(result, a_bzrdir, shared)
358
364
        return result
359
365
 
360
366
    def open(self, a_bzrdir, _found=False, _override_transport=None):
419
425
        """See RepositoryFormat.get_format_description()."""
420
426
        return "Knit repository format 1"
421
427
 
422
 
    def check_conversion_target(self, target_format):
423
 
        pass
424
 
 
425
428
 
426
429
class RepositoryFormatKnit3(RepositoryFormatKnit):
427
430
    """Bzr repository knit format 3.
442
445
    repository_class = KnitRepository
443
446
    _commit_builder_class = RootCommitBuilder
444
447
    rich_root_data = True
 
448
    experimental = True
445
449
    supports_tree_reference = True
446
450
    @property
447
451
    def _serializer(self):
455
459
 
456
460
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
457
461
 
458
 
    def check_conversion_target(self, target_format):
459
 
        if not target_format.rich_root_data:
460
 
            raise errors.BadConversionTarget(
461
 
                'Does not support rich root data.', target_format)
462
 
        if not getattr(target_format, 'supports_tree_reference', False):
463
 
            raise errors.BadConversionTarget(
464
 
                'Does not support nested trees', target_format)
465
 
 
466
462
    def get_format_string(self):
467
463
        """See RepositoryFormat.get_format_string()."""
468
464
        return "Bazaar Knit Repository Format 3 (bzr 0.15)\n"
504
500
 
505
501
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
506
502
 
507
 
    def check_conversion_target(self, target_format):
508
 
        if not target_format.rich_root_data:
509
 
            raise errors.BadConversionTarget(
510
 
                'Does not support rich root data.', target_format)
511
 
 
512
503
    def get_format_string(self):
513
504
        """See RepositoryFormat.get_format_string()."""
514
505
        return 'Bazaar Knit Repository Format 4 (bzr 1.0)\n'