~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Robert Collins
  • Date: 2010-05-06 23:54:05 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506235405-wii4elupfhzl3jvy
Add __str__ to the new helper classes.

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):
 
863
class RepositoryWriteLockResult(object):
874
864
    """The result of write locking a repository.
875
865
 
876
866
    :ivar repository_token: The token obtained from the underlying lock, or
879
869
    """
880
870
 
881
871
    def __init__(self, unlock, repository_token):
882
 
        LogicalLockResult.__init__(self, unlock)
883
872
        self.repository_token = repository_token
 
873
        self.unlock = unlock
884
874
 
885
 
    def __repr__(self):
 
875
    def __str__(self):
886
876
        return "RepositoryWriteLockResult(%s, %s)" % (self.repository_token,
887
877
            self.unlock)
888
878
 
1045
1035
                " id and insertion revid (%r, %r)"
1046
1036
                % (inv.revision_id, revision_id))
1047
1037
        if inv.root is None:
1048
 
            raise errors.RootMissing()
 
1038
            raise AssertionError()
1049
1039
        return self._add_inventory_checked(revision_id, inv, parents)
1050
1040
 
1051
1041
    def _add_inventory_checked(self, revision_id, inv, parents):
1444
1434
            for repo in self._fallback_repositories:
1445
1435
                repo.lock_read()
1446
1436
            self._refresh_data()
1447
 
        return LogicalLockResult(self.unlock)
 
1437
        return self
1448
1438
 
1449
1439
    def get_physical_lock_status(self):
1450
1440
        return self.control_files.get_physical_lock_status()
1668
1658
        return missing_keys
1669
1659
 
1670
1660
    def refresh_data(self):
1671
 
        """Re-read any data needed to synchronise with disk.
 
1661
        """Re-read any data needed to to synchronise with disk.
1672
1662
 
1673
1663
        This method is intended to be called after another repository instance
1674
1664
        (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.
 
1665
        repository. It may not be called during a write group, but may be
 
1666
        called at any other time.
1680
1667
        """
 
1668
        if self.is_in_write_group():
 
1669
            raise errors.InternalBzrError(
 
1670
                "May not refresh_data while in a write group.")
1681
1671
        self._refresh_data()
1682
1672
 
1683
1673
    def resume_write_group(self, tokens):
1722
1712
                "May not fetch while in a write group.")
1723
1713
        # fast path same-url fetch operations
1724
1714
        # TODO: lift out to somewhere common with RemoteRepository
1725
 
        # <https://bugs.launchpad.net/bzr/+bug/401646>
 
1715
        # <https://bugs.edge.launchpad.net/bzr/+bug/401646>
1726
1716
        if (self.has_same_location(source)
1727
1717
            and fetch_spec is None
1728
1718
            and self._has_same_fallbacks(source)):
4283
4273
                is_resume = False
4284
4274
            try:
4285
4275
                # locked_insert_stream performs a commit|suspend.
4286
 
                return self._locked_insert_stream(stream, src_format,
4287
 
                    is_resume)
 
4276
                return self._locked_insert_stream(stream, src_format, is_resume)
4288
4277
            except:
4289
4278
                self.target_repo.abort_write_group(suppress_errors=True)
4290
4279
                raise
4337
4326
                # required if the serializers are different only in terms of
4338
4327
                # the inventory.
4339
4328
                if src_serializer == to_serializer:
4340
 
                    self.target_repo.revisions.insert_record_stream(substream)
 
4329
                    self.target_repo.revisions.insert_record_stream(
 
4330
                        substream)
4341
4331
                else:
4342
4332
                    self._extract_and_insert_revisions(substream,
4343
4333
                        src_serializer)
4451
4441
        """Create a StreamSource streaming from from_repository."""
4452
4442
        self.from_repository = from_repository
4453
4443
        self.to_format = to_format
4454
 
        self._record_counter = RecordCounter()
4455
4444
 
4456
4445
    def delta_on_metadata(self):
4457
4446
        """Return True if delta's are permitted on metadata streams.