~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Gordon Tyler
  • Date: 2010-05-03 04:51:58 UTC
  • mto: This revision was merged to the branch mainline in revision 5207.
  • Revision ID: gordon@doxxx.net-20100503045158-q9smvxm7oelm8nm5
Fixed preservation of existing line endings and added tests for that and Unicode handling.

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