/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: Parth Malwankar
  • Date: 2010-05-05 04:08:11 UTC
  • mfrom: (5205 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5216.
  • Revision ID: parth.malwankar@gmail.com-20100505040811-2th2a48s7wak2p9d
merged in changes from trunk and resolved conflict in builtins.py

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
 
 
876
873
######################################################################
877
874
# Repositories
878
875
 
1389
1386
        data during reads, and allows a 'write_group' to be obtained. Write
1390
1387
        groups must be used for actual data insertion.
1391
1388
 
1392
 
        A token should be passed in if you know that you have locked the object
1393
 
        some other way, and need to synchronise this object's state with that
1394
 
        fact.
1395
 
 
1396
 
        XXX: this docstring is duplicated in many places, e.g. lockable_files.py
1397
 
 
1398
1389
        :param token: if this is already locked, then lock_write will fail
1399
1390
            unless the token matches the existing lock.
1400
1391
        :returns: a token if this instance supports tokens, otherwise None.
1403
1394
        :raises MismatchedToken: if the specified token doesn't match the token
1404
1395
            of the existing lock.
1405
1396
        :seealso: start_write_group.
1406
 
        :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
1407
1403
        """
1408
1404
        locked = self.is_locked()
1409
 
        token = self.control_files.lock_write(token=token)
 
1405
        result = self.control_files.lock_write(token=token)
1410
1406
        if not locked:
1411
1407
            self._warn_if_deprecated()
1412
1408
            self._note_lock('w')
1414
1410
                # Writes don't affect fallback repos
1415
1411
                repo.lock_read()
1416
1412
            self._refresh_data()
1417
 
        return RepositoryWriteLockResult(self.unlock, token)
 
1413
        return result
1418
1414
 
1419
1415
    def lock_read(self):
1420
 
        """Lock the repository for read operations.
1421
 
 
1422
 
        :return: An object with an unlock method which will release the lock
1423
 
            obtained.
1424
 
        """
1425
1416
        locked = self.is_locked()
1426
1417
        self.control_files.lock_read()
1427
1418
        if not locked:
1430
1421
            for repo in self._fallback_repositories:
1431
1422
                repo.lock_read()
1432
1423
            self._refresh_data()
1433
 
        return self
1434
1424
 
1435
1425
    def get_physical_lock_status(self):
1436
1426
        return self.control_files.get_physical_lock_status()
1654
1644
        return missing_keys
1655
1645
 
1656
1646
    def refresh_data(self):
1657
 
        """Re-read any data needed to to synchronise with disk.
 
1647
        """Re-read any data needed to synchronise with disk.
1658
1648
 
1659
1649
        This method is intended to be called after another repository instance
1660
1650
        (such as one used by a smart server) has inserted data into the
1661
 
        repository. It may not be called during a write group, but may be
1662
 
        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.
1663
1656
        """
1664
 
        if self.is_in_write_group():
1665
 
            raise errors.InternalBzrError(
1666
 
                "May not refresh_data while in a write group.")
1667
1657
        self._refresh_data()
1668
1658
 
1669
1659
    def resume_write_group(self, tokens):