/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:
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,
43
44
    symbol_versioning,
44
45
    trace,
45
46
    tsort,
 
47
    ui,
46
48
    versionedfile,
47
49
    )
48
50
from bzrlib.bundle import serializer
51
53
from bzrlib.testament import Testament
52
54
""")
53
55
 
54
 
from bzrlib import (
55
 
    errors,
56
 
    registry,
57
 
    ui,
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.recordcounter import RecordCounter
68
 
from bzrlib.lock import _RelockDebugMixin, LogicalLockResult
 
64
from bzrlib.lock import _RelockDebugMixin
 
65
from bzrlib import registry
69
66
from bzrlib.trace import (
70
67
    log_exception_quietly, note, mutter, mutter_callsite, warning)
71
68
 
74
71
_deprecation_warning_done = False
75
72
 
76
73
 
77
 
class IsInWriteGroupError(errors.InternalBzrError):
78
 
 
79
 
    _fmt = "May not refresh_data of repo %(repo)s while in a write group."
80
 
 
81
 
    def __init__(self, repo):
82
 
        errors.InternalBzrError.__init__(self, repo=repo)
83
 
 
84
 
 
85
74
class CommitBuilder(object):
86
75
    """Provides an interface to build up a commit.
87
76
 
289
278
 
290
279
        :param tree: The tree which is being committed.
291
280
        """
292
 
        if len(self.parents) == 0:
293
 
            raise errors.RootMissing()
 
281
        # NB: if there are no parents then this method is not called, so no
 
282
        # need to guard on parents having length.
294
283
        entry = entry_factory['directory'](tree.path2id(''), '',
295
284
            None)
296
285
        entry.revision = self._new_revision_id
871
860
        # versioned roots do not change unless the tree found a change.
872
861
 
873
862
 
874
 
class RepositoryWriteLockResult(LogicalLockResult):
875
 
    """The result of write locking a repository.
876
 
 
877
 
    :ivar repository_token: The token obtained from the underlying lock, or
878
 
        None.
879
 
    :ivar unlock: A callable which will unlock the lock.
880
 
    """
881
 
 
882
 
    def __init__(self, unlock, repository_token):
883
 
        LogicalLockResult.__init__(self, unlock)
884
 
        self.repository_token = repository_token
885
 
 
886
 
    def __repr__(self):
887
 
        return "RepositoryWriteLockResult(%s, %s)" % (self.repository_token,
888
 
            self.unlock)
889
 
 
890
 
 
891
863
######################################################################
892
864
# Repositories
893
865
 
1046
1018
                " id and insertion revid (%r, %r)"
1047
1019
                % (inv.revision_id, revision_id))
1048
1020
        if inv.root is None:
1049
 
            raise errors.RootMissing()
 
1021
            raise AssertionError()
1050
1022
        return self._add_inventory_checked(revision_id, inv, parents)
1051
1023
 
1052
1024
    def _add_inventory_checked(self, revision_id, inv, parents):
1404
1376
        data during reads, and allows a 'write_group' to be obtained. Write
1405
1377
        groups must be used for actual data insertion.
1406
1378
 
1407
 
        A token should be passed in if you know that you have locked the object
1408
 
        some other way, and need to synchronise this object's state with that
1409
 
        fact.
1410
 
 
1411
 
        XXX: this docstring is duplicated in many places, e.g. lockable_files.py
1412
 
 
1413
1379
        :param token: if this is already locked, then lock_write will fail
1414
1380
            unless the token matches the existing lock.
1415
1381
        :returns: a token if this instance supports tokens, otherwise None.
1418
1384
        :raises MismatchedToken: if the specified token doesn't match the token
1419
1385
            of the existing lock.
1420
1386
        :seealso: start_write_group.
1421
 
        :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
1422
1393
        """
1423
1394
        locked = self.is_locked()
1424
 
        token = self.control_files.lock_write(token=token)
 
1395
        result = self.control_files.lock_write(token=token)
1425
1396
        if not locked:
1426
1397
            self._warn_if_deprecated()
1427
1398
            self._note_lock('w')
1429
1400
                # Writes don't affect fallback repos
1430
1401
                repo.lock_read()
1431
1402
            self._refresh_data()
1432
 
        return RepositoryWriteLockResult(self.unlock, token)
 
1403
        return result
1433
1404
 
1434
1405
    def lock_read(self):
1435
 
        """Lock the repository for read operations.
1436
 
 
1437
 
        :return: An object with an unlock method which will release the lock
1438
 
            obtained.
1439
 
        """
1440
1406
        locked = self.is_locked()
1441
1407
        self.control_files.lock_read()
1442
1408
        if not locked:
1445
1411
            for repo in self._fallback_repositories:
1446
1412
                repo.lock_read()
1447
1413
            self._refresh_data()
1448
 
        return LogicalLockResult(self.unlock)
1449
1414
 
1450
1415
    def get_physical_lock_status(self):
1451
1416
        return self.control_files.get_physical_lock_status()
1669
1634
        return missing_keys
1670
1635
 
1671
1636
    def refresh_data(self):
1672
 
        """Re-read any data needed to synchronise with disk.
 
1637
        """Re-read any data needed to to synchronise with disk.
1673
1638
 
1674
1639
        This method is intended to be called after another repository instance
1675
1640
        (such as one used by a smart server) has inserted data into the
1676
 
        repository. On all repositories this will work outside of write groups.
1677
 
        Some repository formats (pack and newer for bzrlib native formats)
1678
 
        support refresh_data inside write groups. If called inside a write
1679
 
        group on a repository that does not support refreshing in a write group
1680
 
        IsInWriteGroupError will be raised.
 
1641
        repository. It may not be called during a write group, but may be
 
1642
        called at any other time.
1681
1643
        """
 
1644
        if self.is_in_write_group():
 
1645
            raise errors.InternalBzrError(
 
1646
                "May not refresh_data while in a write group.")
1682
1647
        self._refresh_data()
1683
1648
 
1684
1649
    def resume_write_group(self, tokens):
1723
1688
                "May not fetch while in a write group.")
1724
1689
        # fast path same-url fetch operations
1725
1690
        # TODO: lift out to somewhere common with RemoteRepository
1726
 
        # <https://bugs.launchpad.net/bzr/+bug/401646>
 
1691
        # <https://bugs.edge.launchpad.net/bzr/+bug/401646>
1727
1692
        if (self.has_same_location(source)
1728
1693
            and fetch_spec is None
1729
1694
            and self._has_same_fallbacks(source)):
4284
4249
                is_resume = False
4285
4250
            try:
4286
4251
                # locked_insert_stream performs a commit|suspend.
4287
 
                return self._locked_insert_stream(stream, src_format,
4288
 
                    is_resume)
 
4252
                return self._locked_insert_stream(stream, src_format, is_resume)
4289
4253
            except:
4290
4254
                self.target_repo.abort_write_group(suppress_errors=True)
4291
4255
                raise
4338
4302
                # required if the serializers are different only in terms of
4339
4303
                # the inventory.
4340
4304
                if src_serializer == to_serializer:
4341
 
                    self.target_repo.revisions.insert_record_stream(substream)
 
4305
                    self.target_repo.revisions.insert_record_stream(
 
4306
                        substream)
4342
4307
                else:
4343
4308
                    self._extract_and_insert_revisions(substream,
4344
4309
                        src_serializer)
4452
4417
        """Create a StreamSource streaming from from_repository."""
4453
4418
        self.from_repository = from_repository
4454
4419
        self.to_format = to_format
4455
 
        self._record_counter = RecordCounter()
4456
4420
 
4457
4421
    def delta_on_metadata(self):
4458
4422
        """Return True if delta's are permitted on metadata streams.