~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Robert Collins
  • Date: 2010-05-11 08:36:16 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100511083616-b8fjb19zomwupid0
Make all lock methods return Result objects, rather than lock_read returning self, as per John's review.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
    check,
26
26
    chk_map,
27
27
    config,
28
 
    controldir,
29
28
    debug,
 
29
    errors,
30
30
    fetch as _mod_fetch,
31
31
    fifo_cache,
32
32
    generate_ids,
44
44
    symbol_versioning,
45
45
    trace,
46
46
    tsort,
 
47
    ui,
47
48
    versionedfile,
48
49
    )
49
50
from bzrlib.bundle import serializer
52
53
from bzrlib.testament import Testament
53
54
""")
54
55
 
55
 
from bzrlib import (
56
 
    errors,
57
 
    registry,
58
 
    ui,
59
 
    )
60
56
from bzrlib.decorators import needs_read_lock, needs_write_lock, only_raises
61
57
from bzrlib.inter import InterObject
62
58
from bzrlib.inventory import (
65
61
    ROOT_ID,
66
62
    entry_factory,
67
63
    )
68
 
from bzrlib.recordcounter import RecordCounter
69
64
from bzrlib.lock import _RelockDebugMixin, LogicalLockResult
 
65
from bzrlib import registry
70
66
from bzrlib.trace import (
71
67
    log_exception_quietly, note, mutter, mutter_callsite, warning)
72
68
 
75
71
_deprecation_warning_done = False
76
72
 
77
73
 
78
 
class IsInWriteGroupError(errors.InternalBzrError):
79
 
 
80
 
    _fmt = "May not refresh_data of repo %(repo)s while in a write group."
81
 
 
82
 
    def __init__(self, repo):
83
 
        errors.InternalBzrError.__init__(self, repo=repo)
84
 
 
85
 
 
86
74
class CommitBuilder(object):
87
75
    """Provides an interface to build up a commit.
88
76
 
243
231
 
244
232
    def _gen_revision_id(self):
245
233
        """Return new revision-id."""
246
 
        return generate_ids.gen_revision_id(self._committer, self._timestamp)
 
234
        return generate_ids.gen_revision_id(self._config.username(),
 
235
                                            self._timestamp)
247
236
 
248
237
    def _generate_revision_if_needed(self):
249
238
        """Create a revision id if None was supplied.
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
892
881
# Repositories
893
882
 
894
883
 
895
 
class Repository(_RelockDebugMixin, controldir.ControlComponent):
 
884
class Repository(_RelockDebugMixin, bzrdir.ControlComponent):
896
885
    """Repository holding history for one or more branches.
897
886
 
898
887
    The repository holds and retrieves historical information including
1046
1035
                " id and insertion revid (%r, %r)"
1047
1036
                % (inv.revision_id, revision_id))
1048
1037
        if inv.root is None:
1049
 
            raise errors.RootMissing()
 
1038
            raise AssertionError()
1050
1039
        return self._add_inventory_checked(revision_id, inv, parents)
1051
1040
 
1052
1041
    def _add_inventory_checked(self, revision_id, inv, parents):
1669
1658
        return missing_keys
1670
1659
 
1671
1660
    def refresh_data(self):
1672
 
        """Re-read any data needed to synchronise with disk.
 
1661
        """Re-read any data needed to to synchronise with disk.
1673
1662
 
1674
1663
        This method is intended to be called after another repository instance
1675
1664
        (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.
 
1665
        repository. It may not be called during a write group, but may be
 
1666
        called at any other time.
1681
1667
        """
 
1668
        if self.is_in_write_group():
 
1669
            raise errors.InternalBzrError(
 
1670
                "May not refresh_data while in a write group.")
1682
1671
        self._refresh_data()
1683
1672
 
1684
1673
    def resume_write_group(self, tokens):
1723
1712
                "May not fetch while in a write group.")
1724
1713
        # fast path same-url fetch operations
1725
1714
        # TODO: lift out to somewhere common with RemoteRepository
1726
 
        # <https://bugs.launchpad.net/bzr/+bug/401646>
 
1715
        # <https://bugs.edge.launchpad.net/bzr/+bug/401646>
1727
1716
        if (self.has_same_location(source)
1728
1717
            and fetch_spec is None
1729
1718
            and self._has_same_fallbacks(source)):
4284
4273
                is_resume = False
4285
4274
            try:
4286
4275
                # locked_insert_stream performs a commit|suspend.
4287
 
                return self._locked_insert_stream(stream, src_format,
4288
 
                    is_resume)
 
4276
                return self._locked_insert_stream(stream, src_format, is_resume)
4289
4277
            except:
4290
4278
                self.target_repo.abort_write_group(suppress_errors=True)
4291
4279
                raise
4338
4326
                # required if the serializers are different only in terms of
4339
4327
                # the inventory.
4340
4328
                if src_serializer == to_serializer:
4341
 
                    self.target_repo.revisions.insert_record_stream(substream)
 
4329
                    self.target_repo.revisions.insert_record_stream(
 
4330
                        substream)
4342
4331
                else:
4343
4332
                    self._extract_and_insert_revisions(substream,
4344
4333
                        src_serializer)
4452
4441
        """Create a StreamSource streaming from from_repository."""
4453
4442
        self.from_repository = from_repository
4454
4443
        self.to_format = to_format
4455
 
        self._record_counter = RecordCounter()
4456
4444
 
4457
4445
    def delta_on_metadata(self):
4458
4446
        """Return True if delta's are permitted on metadata streams.