/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/repository.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:
26
26
    chk_map,
27
27
    config,
28
28
    debug,
 
29
    errors,
29
30
    fetch as _mod_fetch,
30
31
    fifo_cache,
31
32
    generate_ids,
43
44
    symbol_versioning,
44
45
    trace,
45
46
    tsort,
 
47
    ui,
46
48
    versionedfile,
47
49
    )
48
50
from bzrlib.bundle import serializer
51
53
from bzrlib.testament import Testament
52
54
""")
53
55
 
54
 
from bzrlib import (
55
 
    errors,
56
 
    registry,
57
 
    ui,
58
 
    )
59
56
from bzrlib.decorators import needs_read_lock, needs_write_lock, only_raises
60
57
from bzrlib.inter import InterObject
61
58
from bzrlib.inventory import (
64
61
    ROOT_ID,
65
62
    entry_factory,
66
63
    )
67
 
from bzrlib.recordcounter import RecordCounter
68
 
from bzrlib.lock import _RelockDebugMixin, LogicalLockResult
 
64
from bzrlib.lock import _RelockDebugMixin
 
65
from bzrlib import registry
69
66
from bzrlib.trace import (
70
67
    log_exception_quietly, note, mutter, mutter_callsite, warning)
71
68
 
74
71
_deprecation_warning_done = False
75
72
 
76
73
 
77
 
class IsInWriteGroupError(errors.InternalBzrError):
78
 
 
79
 
    _fmt = "May not refresh_data of repo %(repo)s while in a write group."
80
 
 
81
 
    def __init__(self, repo):
82
 
        errors.InternalBzrError.__init__(self, repo=repo)
83
 
 
84
 
 
85
74
class CommitBuilder(object):
86
75
    """Provides an interface to build up a commit.
87
76
 
289
278
 
290
279
        :param tree: The tree which is being committed.
291
280
        """
292
 
        if len(self.parents) == 0:
293
 
            raise errors.RootMissing()
 
281
        # NB: if there are no parents then this method is not called, so no
 
282
        # need to guard on parents having length.
294
283
        entry = entry_factory['directory'](tree.path2id(''), '',
295
284
            None)
296
285
        entry.revision = self._new_revision_id
871
860
        # versioned roots do not change unless the tree found a change.
872
861
 
873
862
 
874
 
class RepositoryWriteLockResult(LogicalLockResult):
 
863
class RepositoryWriteLockResult(object):
875
864
    """The result of write locking a repository.
876
865
 
877
866
    :ivar repository_token: The token obtained from the underlying lock, or
880
869
    """
881
870
 
882
871
    def __init__(self, unlock, repository_token):
883
 
        LogicalLockResult.__init__(self, unlock)
884
872
        self.repository_token = repository_token
885
 
 
886
 
    def __repr__(self):
887
 
        return "RepositoryWriteLockResult(%s, %s)" % (self.repository_token,
888
 
            self.unlock)
 
873
        self.unlock = unlock
889
874
 
890
875
 
891
876
######################################################################
1046
1031
                " id and insertion revid (%r, %r)"
1047
1032
                % (inv.revision_id, revision_id))
1048
1033
        if inv.root is None:
1049
 
            raise errors.RootMissing()
 
1034
            raise AssertionError()
1050
1035
        return self._add_inventory_checked(revision_id, inv, parents)
1051
1036
 
1052
1037
    def _add_inventory_checked(self, revision_id, inv, parents):
1445
1430
            for repo in self._fallback_repositories:
1446
1431
                repo.lock_read()
1447
1432
            self._refresh_data()
1448
 
        return LogicalLockResult(self.unlock)
 
1433
        return self
1449
1434
 
1450
1435
    def get_physical_lock_status(self):
1451
1436
        return self.control_files.get_physical_lock_status()
1669
1654
        return missing_keys
1670
1655
 
1671
1656
    def refresh_data(self):
1672
 
        """Re-read any data needed to synchronise with disk.
 
1657
        """Re-read any data needed to to synchronise with disk.
1673
1658
 
1674
1659
        This method is intended to be called after another repository instance
1675
1660
        (such as one used by a smart server) has inserted data into the
1676
 
        repository. On all repositories this will work outside of write groups.
1677
 
        Some repository formats (pack and newer for bzrlib native formats)
1678
 
        support refresh_data inside write groups. If called inside a write
1679
 
        group on a repository that does not support refreshing in a write group
1680
 
        IsInWriteGroupError will be raised.
 
1661
        repository. It may not be called during a write group, but may be
 
1662
        called at any other time.
1681
1663
        """
 
1664
        if self.is_in_write_group():
 
1665
            raise errors.InternalBzrError(
 
1666
                "May not refresh_data while in a write group.")
1682
1667
        self._refresh_data()
1683
1668
 
1684
1669
    def resume_write_group(self, tokens):
1723
1708
                "May not fetch while in a write group.")
1724
1709
        # fast path same-url fetch operations
1725
1710
        # TODO: lift out to somewhere common with RemoteRepository
1726
 
        # <https://bugs.launchpad.net/bzr/+bug/401646>
 
1711
        # <https://bugs.edge.launchpad.net/bzr/+bug/401646>
1727
1712
        if (self.has_same_location(source)
1728
1713
            and fetch_spec is None
1729
1714
            and self._has_same_fallbacks(source)):
4284
4269
                is_resume = False
4285
4270
            try:
4286
4271
                # locked_insert_stream performs a commit|suspend.
4287
 
                return self._locked_insert_stream(stream, src_format,
4288
 
                    is_resume)
 
4272
                return self._locked_insert_stream(stream, src_format, is_resume)
4289
4273
            except:
4290
4274
                self.target_repo.abort_write_group(suppress_errors=True)
4291
4275
                raise
4338
4322
                # required if the serializers are different only in terms of
4339
4323
                # the inventory.
4340
4324
                if src_serializer == to_serializer:
4341
 
                    self.target_repo.revisions.insert_record_stream(substream)
 
4325
                    self.target_repo.revisions.insert_record_stream(
 
4326
                        substream)
4342
4327
                else:
4343
4328
                    self._extract_and_insert_revisions(substream,
4344
4329
                        src_serializer)
4452
4437
        """Create a StreamSource streaming from from_repository."""
4453
4438
        self.from_repository = from_repository
4454
4439
        self.to_format = to_format
4455
 
        self._record_counter = RecordCounter()
4456
4440
 
4457
4441
    def delta_on_metadata(self):
4458
4442
        """Return True if delta's are permitted on metadata streams.