~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Parth Malwankar
  • Date: 2010-05-05 14:11:13 UTC
  • mfrom: (5211 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5213.
  • Revision ID: parth.malwankar@gmail.com-20100505141113-c21oicoxzb3u6if6
merged in changes from trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    chk_map,
27
27
    config,
28
28
    debug,
29
 
    errors,
30
29
    fetch as _mod_fetch,
31
30
    fifo_cache,
32
31
    generate_ids,
62
61
    entry_factory,
63
62
    )
64
63
from bzrlib.lock import _RelockDebugMixin
65
 
from bzrlib import registry
 
64
from bzrlib import (
 
65
    errors,
 
66
    registry,
 
67
    )
66
68
from bzrlib.trace import (
67
69
    log_exception_quietly, note, mutter, mutter_callsite, warning)
68
70
 
71
73
_deprecation_warning_done = False
72
74
 
73
75
 
 
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
 
74
84
class CommitBuilder(object):
75
85
    """Provides an interface to build up a commit.
76
86
 
860
870
        # versioned roots do not change unless the tree found a change.
861
871
 
862
872
 
863
 
class RepositoryWriteLockResult(object):
864
 
    """The result of write locking a repository.
865
 
 
866
 
    :ivar repository_token: The token obtained from the underlying lock, or
867
 
        None.
868
 
    :ivar unlock: A callable which will unlock the lock.
869
 
    """
870
 
 
871
 
    def __init__(self, unlock, repository_token):
872
 
        self.repository_token = repository_token
873
 
        self.unlock = unlock
874
 
 
875
 
    def __str__(self):
876
 
        return "RepositoryWriteLockResult(%s, %s)" % (self.repository_token,
877
 
            self.unlock)
878
 
 
879
 
 
880
873
######################################################################
881
874
# Repositories
882
875
 
1393
1386
        data during reads, and allows a 'write_group' to be obtained. Write
1394
1387
        groups must be used for actual data insertion.
1395
1388
 
1396
 
        A token should be passed in if you know that you have locked the object
1397
 
        some other way, and need to synchronise this object's state with that
1398
 
        fact.
1399
 
 
1400
 
        XXX: this docstring is duplicated in many places, e.g. lockable_files.py
1401
 
 
1402
1389
        :param token: if this is already locked, then lock_write will fail
1403
1390
            unless the token matches the existing lock.
1404
1391
        :returns: a token if this instance supports tokens, otherwise None.
1407
1394
        :raises MismatchedToken: if the specified token doesn't match the token
1408
1395
            of the existing lock.
1409
1396
        :seealso: start_write_group.
1410
 
        :return: A RepositoryWriteLockResult.
 
1397
 
 
1398
        A token should be passed in if you know that you have locked the object
 
1399
        some other way, and need to synchronise this object's state with that
 
1400
        fact.
 
1401
 
 
1402
        XXX: this docstring is duplicated in many places, e.g. lockable_files.py
1411
1403
        """
1412
1404
        locked = self.is_locked()
1413
 
        token = self.control_files.lock_write(token=token)
 
1405
        result = self.control_files.lock_write(token=token)
1414
1406
        if not locked:
1415
1407
            self._warn_if_deprecated()
1416
1408
            self._note_lock('w')
1418
1410
                # Writes don't affect fallback repos
1419
1411
                repo.lock_read()
1420
1412
            self._refresh_data()
1421
 
        return RepositoryWriteLockResult(self.unlock, token)
 
1413
        return result
1422
1414
 
1423
1415
    def lock_read(self):
1424
 
        """Lock the repository for read operations.
1425
 
 
1426
 
        :return: An object with an unlock method which will release the lock
1427
 
            obtained.
1428
 
        """
1429
1416
        locked = self.is_locked()
1430
1417
        self.control_files.lock_read()
1431
1418
        if not locked:
1434
1421
            for repo in self._fallback_repositories:
1435
1422
                repo.lock_read()
1436
1423
            self._refresh_data()
1437
 
        return self
1438
1424
 
1439
1425
    def get_physical_lock_status(self):
1440
1426
        return self.control_files.get_physical_lock_status()
1658
1644
        return missing_keys
1659
1645
 
1660
1646
    def refresh_data(self):
1661
 
        """Re-read any data needed to to synchronise with disk.
 
1647
        """Re-read any data needed to synchronise with disk.
1662
1648
 
1663
1649
        This method is intended to be called after another repository instance
1664
1650
        (such as one used by a smart server) has inserted data into the
1665
 
        repository. It may not be called during a write group, but may be
1666
 
        called at any other time.
 
1651
        repository. On all repositories this will work outside of write groups.
 
1652
        Some repository formats (pack and newer for bzrlib native formats)
 
1653
        support refresh_data inside write groups. If called inside a write
 
1654
        group on a repository that does not support refreshing in a write group
 
1655
        IsInWriteGroupError will be raised.
1667
1656
        """
1668
 
        if self.is_in_write_group():
1669
 
            raise errors.InternalBzrError(
1670
 
                "May not refresh_data while in a write group.")
1671
1657
        self._refresh_data()
1672
1658
 
1673
1659
    def resume_write_group(self, tokens):