/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-04-14 10:12:22 UTC
  • mto: This revision was merged to the branch mainline in revision 5156.
  • Revision ID: parth.malwankar@gmail.com-20100414101222-uiu2ucurptoz1dg1
improved bug description.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    chk_map,
27
27
    config,
28
28
    debug,
 
29
    errors,
29
30
    fetch as _mod_fetch,
30
31
    fifo_cache,
31
32
    generate_ids,
52
53
from bzrlib.testament import Testament
53
54
""")
54
55
 
55
 
from bzrlib import (
56
 
    errors,
57
 
    registry,
58
 
    )
59
56
from bzrlib.decorators import needs_read_lock, needs_write_lock, only_raises
60
57
from bzrlib.inter import InterObject
61
58
from bzrlib.inventory import (
64
61
    ROOT_ID,
65
62
    entry_factory,
66
63
    )
67
 
from bzrlib.lock import _RelockDebugMixin, LogicalLockResult
 
64
from bzrlib.lock import _RelockDebugMixin
 
65
from bzrlib import registry
68
66
from bzrlib.trace import (
69
67
    log_exception_quietly, note, mutter, mutter_callsite, warning)
70
68
 
73
71
_deprecation_warning_done = False
74
72
 
75
73
 
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
 
 
84
74
class CommitBuilder(object):
85
75
    """Provides an interface to build up a commit.
86
76
 
870
860
        # versioned roots do not change unless the tree found a change.
871
861
 
872
862
 
873
 
class RepositoryWriteLockResult(LogicalLockResult):
874
 
    """The result of write locking a repository.
875
 
 
876
 
    :ivar repository_token: The token obtained from the underlying lock, or
877
 
        None.
878
 
    :ivar unlock: A callable which will unlock the lock.
879
 
    """
880
 
 
881
 
    def __init__(self, unlock, repository_token):
882
 
        LogicalLockResult.__init__(self, unlock)
883
 
        self.repository_token = repository_token
884
 
 
885
 
    def __repr__(self):
886
 
        return "RepositoryWriteLockResult(%s, %s)" % (self.repository_token,
887
 
            self.unlock)
888
 
 
889
 
 
890
863
######################################################################
891
864
# Repositories
892
865
 
893
866
 
894
 
class Repository(_RelockDebugMixin, bzrdir.ControlComponent):
 
867
class Repository(_RelockDebugMixin):
895
868
    """Repository holding history for one or more branches.
896
869
 
897
870
    The repository holds and retrieves historical information including
1318
1291
 
1319
1292
        :param _format: The format of the repository on disk.
1320
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.
1321
1298
        """
1322
 
        # In the future we will have a single api for all stores for
1323
 
        # getting file texts, inventories and revisions, then
1324
 
        # this construct will accept instances of those things.
1325
1299
        super(Repository, self).__init__()
1326
1300
        self._format = _format
1327
1301
        # the following are part of the public API for Repository:
1342
1316
        # rather copying them?
1343
1317
        self._safe_to_return_from_cache = False
1344
1318
 
1345
 
    @property
1346
 
    def user_transport(self):
1347
 
        return self.bzrdir.user_transport
1348
 
 
1349
 
    @property
1350
 
    def control_transport(self):
1351
 
        return self._transport
1352
 
 
1353
1319
    def __repr__(self):
1354
1320
        if self._fallback_repositories:
1355
1321
            return '%s(%r, fallback_repositories=%r)' % (
1403
1369
        data during reads, and allows a 'write_group' to be obtained. Write
1404
1370
        groups must be used for actual data insertion.
1405
1371
 
1406
 
        A token should be passed in if you know that you have locked the object
1407
 
        some other way, and need to synchronise this object's state with that
1408
 
        fact.
1409
 
 
1410
 
        XXX: this docstring is duplicated in many places, e.g. lockable_files.py
1411
 
 
1412
1372
        :param token: if this is already locked, then lock_write will fail
1413
1373
            unless the token matches the existing lock.
1414
1374
        :returns: a token if this instance supports tokens, otherwise None.
1417
1377
        :raises MismatchedToken: if the specified token doesn't match the token
1418
1378
            of the existing lock.
1419
1379
        :seealso: start_write_group.
1420
 
        :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
1421
1386
        """
1422
1387
        locked = self.is_locked()
1423
 
        token = self.control_files.lock_write(token=token)
 
1388
        result = self.control_files.lock_write(token=token)
1424
1389
        if not locked:
1425
1390
            self._warn_if_deprecated()
1426
1391
            self._note_lock('w')
1428
1393
                # Writes don't affect fallback repos
1429
1394
                repo.lock_read()
1430
1395
            self._refresh_data()
1431
 
        return RepositoryWriteLockResult(self.unlock, token)
 
1396
        return result
1432
1397
 
1433
1398
    def lock_read(self):
1434
 
        """Lock the repository for read operations.
1435
 
 
1436
 
        :return: An object with an unlock method which will release the lock
1437
 
            obtained.
1438
 
        """
1439
1399
        locked = self.is_locked()
1440
1400
        self.control_files.lock_read()
1441
1401
        if not locked:
1444
1404
            for repo in self._fallback_repositories:
1445
1405
                repo.lock_read()
1446
1406
            self._refresh_data()
1447
 
        return LogicalLockResult(self.unlock)
1448
1407
 
1449
1408
    def get_physical_lock_status(self):
1450
1409
        return self.control_files.get_physical_lock_status()
1510
1469
 
1511
1470
        # now gather global repository information
1512
1471
        # XXX: This is available for many repos regardless of listability.
1513
 
        if self.user_transport.listable():
 
1472
        if self.bzrdir.root_transport.listable():
1514
1473
            # XXX: do we want to __define len__() ?
1515
1474
            # Maybe the versionedfiles object should provide a different
1516
1475
            # method to get the number of keys.
1548
1507
 
1549
1508
        ret = []
1550
1509
        for branches, repository in bzrdir.BzrDir.find_bzrdirs(
1551
 
                self.user_transport, evaluate=Evaluator()):
 
1510
                self.bzrdir.root_transport, evaluate=Evaluator()):
1552
1511
            if branches is not None:
1553
1512
                ret.extend(branches)
1554
1513
            if not using and repository is not None:
1668
1627
        return missing_keys
1669
1628
 
1670
1629
    def refresh_data(self):
1671
 
        """Re-read any data needed to synchronise with disk.
 
1630
        """Re-read any data needed to to synchronise with disk.
1672
1631
 
1673
1632
        This method is intended to be called after another repository instance
1674
1633
        (such as one used by a smart server) has inserted data into the
1675
 
        repository. On all repositories this will work outside of write groups.
1676
 
        Some repository formats (pack and newer for bzrlib native formats)
1677
 
        support refresh_data inside write groups. If called inside a write
1678
 
        group on a repository that does not support refreshing in a write group
1679
 
        IsInWriteGroupError will be raised.
 
1634
        repository. It may not be called during a write group, but may be
 
1635
        called at any other time.
1680
1636
        """
 
1637
        if self.is_in_write_group():
 
1638
            raise errors.InternalBzrError(
 
1639
                "May not refresh_data while in a write group.")
1681
1640
        self._refresh_data()
1682
1641
 
1683
1642
    def resume_write_group(self, tokens):
2622
2581
            keys = tsort.topo_sort(parent_map)
2623
2582
        return [None] + list(keys)
2624
2583
 
2625
 
    def pack(self, hint=None, clean_obsolete_packs=False):
 
2584
    def pack(self, hint=None):
2626
2585
        """Compress the data within the repository.
2627
2586
 
2628
2587
        This operation only makes sense for some repository types. For other
2638
2597
            obtained from the result of commit_write_group(). Out of
2639
2598
            date hints are simply ignored, because concurrent operations
2640
2599
            can obsolete them rapidly.
2641
 
 
2642
 
        :param clean_obsolete_packs: Clean obsolete packs immediately after
2643
 
            the pack operation.
2644
2600
        """
2645
2601
 
2646
2602
    def get_transaction(self):
3212
3168
        """
3213
3169
        raise NotImplementedError(self.open)
3214
3170
 
3215
 
    def _run_post_repo_init_hooks(self, repository, a_bzrdir, shared):
3216
 
        from bzrlib.bzrdir import BzrDir, RepoInitHookParams
3217
 
        hooks = BzrDir.hooks['post_repo_init']
3218
 
        if not hooks:
3219
 
            return
3220
 
        params = RepoInitHookParams(repository, self, a_bzrdir, shared)
3221
 
        for hook in hooks:
3222
 
            hook(params)
3223
 
 
3224
3171
 
3225
3172
class MetaDirRepositoryFormat(RepositoryFormat):
3226
3173
    """Common base class for the new repositories using the metadir layout."""