~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Martin
  • Date: 2010-04-22 18:36:13 UTC
  • mto: (5177.1.1 integration2)
  • mto: This revision was merged to the branch mainline in revision 5179.
  • Revision ID: gzlist@googlemail.com-20100422183613-gruiwv2xsrjf0nhp
Fix more tests which were failing under -OO that had been missed earlier

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
 
883
866
 
884
 
class Repository(_RelockDebugMixin, bzrdir.ControlComponent):
 
867
class Repository(_RelockDebugMixin):
885
868
    """Repository holding history for one or more branches.
886
869
 
887
870
    The repository holds and retrieves historical information including
1308
1291
 
1309
1292
        :param _format: The format of the repository on disk.
1310
1293
        :param a_bzrdir: The BzrDir of the repository.
 
1294
 
 
1295
        In the future we will have a single api for all stores for
 
1296
        getting file texts, inventories and revisions, then
 
1297
        this construct will accept instances of those things.
1311
1298
        """
1312
 
        # In the future we will have a single api for all stores for
1313
 
        # getting file texts, inventories and revisions, then
1314
 
        # this construct will accept instances of those things.
1315
1299
        super(Repository, self).__init__()
1316
1300
        self._format = _format
1317
1301
        # the following are part of the public API for Repository:
1332
1316
        # rather copying them?
1333
1317
        self._safe_to_return_from_cache = False
1334
1318
 
1335
 
    @property
1336
 
    def user_transport(self):
1337
 
        return self.bzrdir.user_transport
1338
 
 
1339
 
    @property
1340
 
    def control_transport(self):
1341
 
        return self._transport
1342
 
 
1343
1319
    def __repr__(self):
1344
1320
        if self._fallback_repositories:
1345
1321
            return '%s(%r, fallback_repositories=%r)' % (
1393
1369
        data during reads, and allows a 'write_group' to be obtained. Write
1394
1370
        groups must be used for actual data insertion.
1395
1371
 
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
1372
        :param token: if this is already locked, then lock_write will fail
1403
1373
            unless the token matches the existing lock.
1404
1374
        :returns: a token if this instance supports tokens, otherwise None.
1407
1377
        :raises MismatchedToken: if the specified token doesn't match the token
1408
1378
            of the existing lock.
1409
1379
        :seealso: start_write_group.
1410
 
        :return: A RepositoryWriteLockResult.
 
1380
 
 
1381
        A token should be passed in if you know that you have locked the object
 
1382
        some other way, and need to synchronise this object's state with that
 
1383
        fact.
 
1384
 
 
1385
        XXX: this docstring is duplicated in many places, e.g. lockable_files.py
1411
1386
        """
1412
1387
        locked = self.is_locked()
1413
 
        token = self.control_files.lock_write(token=token)
 
1388
        result = self.control_files.lock_write(token=token)
1414
1389
        if not locked:
1415
1390
            self._warn_if_deprecated()
1416
1391
            self._note_lock('w')
1418
1393
                # Writes don't affect fallback repos
1419
1394
                repo.lock_read()
1420
1395
            self._refresh_data()
1421
 
        return RepositoryWriteLockResult(self.unlock, token)
 
1396
        return result
1422
1397
 
1423
1398
    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
1399
        locked = self.is_locked()
1430
1400
        self.control_files.lock_read()
1431
1401
        if not locked:
1434
1404
            for repo in self._fallback_repositories:
1435
1405
                repo.lock_read()
1436
1406
            self._refresh_data()
1437
 
        return self
1438
1407
 
1439
1408
    def get_physical_lock_status(self):
1440
1409
        return self.control_files.get_physical_lock_status()
1500
1469
 
1501
1470
        # now gather global repository information
1502
1471
        # XXX: This is available for many repos regardless of listability.
1503
 
        if self.user_transport.listable():
 
1472
        if self.bzrdir.root_transport.listable():
1504
1473
            # XXX: do we want to __define len__() ?
1505
1474
            # Maybe the versionedfiles object should provide a different
1506
1475
            # method to get the number of keys.
1538
1507
 
1539
1508
        ret = []
1540
1509
        for branches, repository in bzrdir.BzrDir.find_bzrdirs(
1541
 
                self.user_transport, evaluate=Evaluator()):
 
1510
                self.bzrdir.root_transport, evaluate=Evaluator()):
1542
1511
            if branches is not None:
1543
1512
                ret.extend(branches)
1544
1513
            if not using and repository is not None:
3202
3171
        """
3203
3172
        raise NotImplementedError(self.open)
3204
3173
 
3205
 
    def _run_post_repo_init_hooks(self, repository, a_bzrdir, shared):
3206
 
        from bzrlib.bzrdir import BzrDir, RepoInitHookParams
3207
 
        hooks = BzrDir.hooks['post_repo_init']
3208
 
        if not hooks:
3209
 
            return
3210
 
        params = RepoInitHookParams(repository, self, a_bzrdir, shared)
3211
 
        for hook in hooks:
3212
 
            hook(params)
3213
 
 
3214
3174
 
3215
3175
class MetaDirRepositoryFormat(RepositoryFormat):
3216
3176
    """Common base class for the new repositories using the metadir layout."""