/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 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

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,
52
53
from bzrlib.testament import Testament
53
54
""")
54
55
 
55
 
from bzrlib import (
56
 
    errors,
57
 
    registry,
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.lock import _RelockDebugMixin, LogicalLockResult
 
64
from bzrlib.lock import _RelockDebugMixin
 
65
from bzrlib import registry
68
66
from bzrlib.trace import (
69
67
    log_exception_quietly, note, mutter, mutter_callsite, warning)
70
68
 
73
71
_deprecation_warning_done = False
74
72
 
75
73
 
76
 
class IsInWriteGroupError(errors.InternalBzrError):
77
 
 
78
 
    _fmt = "May not refresh_data of repo %(repo)s while in a write group."
79
 
 
80
 
    def __init__(self, repo):
81
 
        errors.InternalBzrError.__init__(self, repo=repo)
82
 
 
83
 
 
84
74
class CommitBuilder(object):
85
75
    """Provides an interface to build up a commit.
86
76
 
870
860
        # versioned roots do not change unless the tree found a change.
871
861
 
872
862
 
873
 
class RepositoryWriteLockResult(LogicalLockResult):
874
 
    """The result of write locking a repository.
875
 
 
876
 
    :ivar repository_token: The token obtained from the underlying lock, or
877
 
        None.
878
 
    :ivar unlock: A callable which will unlock the lock.
879
 
    """
880
 
 
881
 
    def __init__(self, unlock, repository_token):
882
 
        LogicalLockResult.__init__(self, unlock)
883
 
        self.repository_token = repository_token
884
 
 
885
 
    def __repr__(self):
886
 
        return "RepositoryWriteLockResult(%s, %s)" % (self.repository_token,
887
 
            self.unlock)
888
 
 
889
 
 
890
863
######################################################################
891
864
# Repositories
892
865
 
1403
1376
        data during reads, and allows a 'write_group' to be obtained. Write
1404
1377
        groups must be used for actual data insertion.
1405
1378
 
1406
 
        A token should be passed in if you know that you have locked the object
1407
 
        some other way, and need to synchronise this object's state with that
1408
 
        fact.
1409
 
 
1410
 
        XXX: this docstring is duplicated in many places, e.g. lockable_files.py
1411
 
 
1412
1379
        :param token: if this is already locked, then lock_write will fail
1413
1380
            unless the token matches the existing lock.
1414
1381
        :returns: a token if this instance supports tokens, otherwise None.
1417
1384
        :raises MismatchedToken: if the specified token doesn't match the token
1418
1385
            of the existing lock.
1419
1386
        :seealso: start_write_group.
1420
 
        :return: A RepositoryWriteLockResult.
 
1387
 
 
1388
        A token should be passed in if you know that you have locked the object
 
1389
        some other way, and need to synchronise this object's state with that
 
1390
        fact.
 
1391
 
 
1392
        XXX: this docstring is duplicated in many places, e.g. lockable_files.py
1421
1393
        """
1422
1394
        locked = self.is_locked()
1423
 
        token = self.control_files.lock_write(token=token)
 
1395
        result = self.control_files.lock_write(token=token)
1424
1396
        if not locked:
1425
1397
            self._warn_if_deprecated()
1426
1398
            self._note_lock('w')
1428
1400
                # Writes don't affect fallback repos
1429
1401
                repo.lock_read()
1430
1402
            self._refresh_data()
1431
 
        return RepositoryWriteLockResult(self.unlock, token)
 
1403
        return result
1432
1404
 
1433
1405
    def lock_read(self):
1434
 
        """Lock the repository for read operations.
1435
 
 
1436
 
        :return: An object with an unlock method which will release the lock
1437
 
            obtained.
1438
 
        """
1439
1406
        locked = self.is_locked()
1440
1407
        self.control_files.lock_read()
1441
1408
        if not locked:
1444
1411
            for repo in self._fallback_repositories:
1445
1412
                repo.lock_read()
1446
1413
            self._refresh_data()
1447
 
        return LogicalLockResult(self.unlock)
1448
1414
 
1449
1415
    def get_physical_lock_status(self):
1450
1416
        return self.control_files.get_physical_lock_status()
1668
1634
        return missing_keys
1669
1635
 
1670
1636
    def refresh_data(self):
1671
 
        """Re-read any data needed to synchronise with disk.
 
1637
        """Re-read any data needed to to synchronise with disk.
1672
1638
 
1673
1639
        This method is intended to be called after another repository instance
1674
1640
        (such as one used by a smart server) has inserted data into the
1675
 
        repository. On all repositories this will work outside of write groups.
1676
 
        Some repository formats (pack and newer for bzrlib native formats)
1677
 
        support refresh_data inside write groups. If called inside a write
1678
 
        group on a repository that does not support refreshing in a write group
1679
 
        IsInWriteGroupError will be raised.
 
1641
        repository. It may not be called during a write group, but may be
 
1642
        called at any other time.
1680
1643
        """
 
1644
        if self.is_in_write_group():
 
1645
            raise errors.InternalBzrError(
 
1646
                "May not refresh_data while in a write group.")
1681
1647
        self._refresh_data()
1682
1648
 
1683
1649
    def resume_write_group(self, tokens):