/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:
860
860
        # versioned roots do not change unless the tree found a change.
861
861
 
862
862
 
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
863
######################################################################
877
864
# Repositories
878
865
 
1389
1376
        data during reads, and allows a 'write_group' to be obtained. Write
1390
1377
        groups must be used for actual data insertion.
1391
1378
 
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
1379
        :param token: if this is already locked, then lock_write will fail
1399
1380
            unless the token matches the existing lock.
1400
1381
        :returns: a token if this instance supports tokens, otherwise None.
1403
1384
        :raises MismatchedToken: if the specified token doesn't match the token
1404
1385
            of the existing lock.
1405
1386
        :seealso: start_write_group.
1406
 
        :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
1407
1393
        """
1408
1394
        locked = self.is_locked()
1409
 
        token = self.control_files.lock_write(token=token)
 
1395
        result = self.control_files.lock_write(token=token)
1410
1396
        if not locked:
1411
1397
            self._warn_if_deprecated()
1412
1398
            self._note_lock('w')
1414
1400
                # Writes don't affect fallback repos
1415
1401
                repo.lock_read()
1416
1402
            self._refresh_data()
1417
 
        return RepositoryWriteLockResult(self.unlock, token)
 
1403
        return result
1418
1404
 
1419
1405
    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
1406
        locked = self.is_locked()
1426
1407
        self.control_files.lock_read()
1427
1408
        if not locked:
1430
1411
            for repo in self._fallback_repositories:
1431
1412
                repo.lock_read()
1432
1413
            self._refresh_data()
1433
 
        return self
1434
1414
 
1435
1415
    def get_physical_lock_status(self):
1436
1416
        return self.control_files.get_physical_lock_status()