/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
 
242
231
 
243
232
    def _gen_revision_id(self):
244
233
        """Return new revision-id."""
245
 
        return generate_ids.gen_revision_id(self._committer, self._timestamp)
 
234
        return generate_ids.gen_revision_id(self._config.username(),
 
235
                                            self._timestamp)
246
236
 
247
237
    def _generate_revision_if_needed(self):
248
238
        """Create a revision id if None was supplied.
288
278
 
289
279
        :param tree: The tree which is being committed.
290
280
        """
291
 
        if len(self.parents) == 0:
292
 
            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.
293
283
        entry = entry_factory['directory'](tree.path2id(''), '',
294
284
            None)
295
285
        entry.revision = self._new_revision_id
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
 
1045
1018
                " id and insertion revid (%r, %r)"
1046
1019
                % (inv.revision_id, revision_id))
1047
1020
        if inv.root is None:
1048
 
            raise errors.RootMissing()
 
1021
            raise AssertionError()
1049
1022
        return self._add_inventory_checked(revision_id, inv, parents)
1050
1023
 
1051
1024
    def _add_inventory_checked(self, revision_id, inv, parents):
1403
1376
        data during reads, and allows a 'write_group' to be obtained. Write
1404
1377
        groups must be used for actual data insertion.
1405
1378
 
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
1379
        :param token: if this is already locked, then lock_write will fail
1413
1380
            unless the token matches the existing lock.
1414
1381
        :returns: a token if this instance supports tokens, otherwise None.
1417
1384
        :raises MismatchedToken: if the specified token doesn't match the token
1418
1385
            of the existing lock.
1419
1386
        :seealso: start_write_group.
1420
 
        :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
1421
1393
        """
1422
1394
        locked = self.is_locked()
1423
 
        token = self.control_files.lock_write(token=token)
 
1395
        result = self.control_files.lock_write(token=token)
1424
1396
        if not locked:
1425
1397
            self._warn_if_deprecated()
1426
1398
            self._note_lock('w')
1428
1400
                # Writes don't affect fallback repos
1429
1401
                repo.lock_read()
1430
1402
            self._refresh_data()
1431
 
        return RepositoryWriteLockResult(self.unlock, token)
 
1403
        return result
1432
1404
 
1433
1405
    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
1406
        locked = self.is_locked()
1440
1407
        self.control_files.lock_read()
1441
1408
        if not locked:
1444
1411
            for repo in self._fallback_repositories:
1445
1412
                repo.lock_read()
1446
1413
            self._refresh_data()
1447
 
        return LogicalLockResult(self.unlock)
1448
1414
 
1449
1415
    def get_physical_lock_status(self):
1450
1416
        return self.control_files.get_physical_lock_status()
1668
1634
        return missing_keys
1669
1635
 
1670
1636
    def refresh_data(self):
1671
 
        """Re-read any data needed to synchronise with disk.
 
1637
        """Re-read any data needed to to synchronise with disk.
1672
1638
 
1673
1639
        This method is intended to be called after another repository instance
1674
1640
        (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.
 
1641
        repository. It may not be called during a write group, but may be
 
1642
        called at any other time.
1680
1643
        """
 
1644
        if self.is_in_write_group():
 
1645
            raise errors.InternalBzrError(
 
1646
                "May not refresh_data while in a write group.")
1681
1647
        self._refresh_data()
1682
1648
 
1683
1649
    def resume_write_group(self, tokens):
1722
1688
                "May not fetch while in a write group.")
1723
1689
        # fast path same-url fetch operations
1724
1690
        # TODO: lift out to somewhere common with RemoteRepository
1725
 
        # <https://bugs.launchpad.net/bzr/+bug/401646>
 
1691
        # <https://bugs.edge.launchpad.net/bzr/+bug/401646>
1726
1692
        if (self.has_same_location(source)
1727
1693
            and fetch_spec is None
1728
1694
            and self._has_same_fallbacks(source)):
4283
4249
                is_resume = False
4284
4250
            try:
4285
4251
                # locked_insert_stream performs a commit|suspend.
4286
 
                return self._locked_insert_stream(stream, src_format,
4287
 
                    is_resume)
 
4252
                return self._locked_insert_stream(stream, src_format, is_resume)
4288
4253
            except:
4289
4254
                self.target_repo.abort_write_group(suppress_errors=True)
4290
4255
                raise
4337
4302
                # required if the serializers are different only in terms of
4338
4303
                # the inventory.
4339
4304
                if src_serializer == to_serializer:
4340
 
                    self.target_repo.revisions.insert_record_stream(substream)
 
4305
                    self.target_repo.revisions.insert_record_stream(
 
4306
                        substream)
4341
4307
                else:
4342
4308
                    self._extract_and_insert_revisions(substream,
4343
4309
                        src_serializer)
4451
4417
        """Create a StreamSource streaming from from_repository."""
4452
4418
        self.from_repository = from_repository
4453
4419
        self.to_format = to_format
4454
 
        self._record_counter = RecordCounter()
4455
4420
 
4456
4421
    def delta_on_metadata(self):
4457
4422
        """Return True if delta's are permitted on metadata streams.