/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:54:05 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506235405-wii4elupfhzl3jvy
Add __str__ to the new helper classes.

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
    def __str__(self):
 
876
        return "RepositoryWriteLockResult(%s, %s)" % (self.repository_token,
 
877
            self.unlock)
 
878
 
 
879
 
863
880
######################################################################
864
881
# Repositories
865
882
 
1376
1393
        data during reads, and allows a 'write_group' to be obtained. Write
1377
1394
        groups must be used for actual data insertion.
1378
1395
 
 
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
 
1379
1402
        :param token: if this is already locked, then lock_write will fail
1380
1403
            unless the token matches the existing lock.
1381
1404
        :returns: a token if this instance supports tokens, otherwise None.
1384
1407
        :raises MismatchedToken: if the specified token doesn't match the token
1385
1408
            of the existing lock.
1386
1409
        :seealso: start_write_group.
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
 
1410
        :return: A RepositoryWriteLockResult.
1393
1411
        """
1394
1412
        locked = self.is_locked()
1395
 
        result = self.control_files.lock_write(token=token)
 
1413
        token = self.control_files.lock_write(token=token)
1396
1414
        if not locked:
1397
1415
            self._warn_if_deprecated()
1398
1416
            self._note_lock('w')
1400
1418
                # Writes don't affect fallback repos
1401
1419
                repo.lock_read()
1402
1420
            self._refresh_data()
1403
 
        return result
 
1421
        return RepositoryWriteLockResult(self.unlock, token)
1404
1422
 
1405
1423
    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
        """
1406
1429
        locked = self.is_locked()
1407
1430
        self.control_files.lock_read()
1408
1431
        if not locked:
1411
1434
            for repo in self._fallback_repositories:
1412
1435
                repo.lock_read()
1413
1436
            self._refresh_data()
 
1437
        return self
1414
1438
 
1415
1439
    def get_physical_lock_status(self):
1416
1440
        return self.control_files.get_physical_lock_status()