~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/pack_repo.py

  • Committer: INADA Naoki
  • Date: 2011-05-17 00:45:09 UTC
  • mfrom: (5875 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5891.
  • Revision ID: songofacandy@gmail.com-20110517004509-q58negjbdjh7t6u1
mergeĀ fromĀ lp:bzr

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
    )
53
53
from bzrlib.lock import LogicalLockResult
54
54
from bzrlib.repository import (
55
 
    CommitBuilder,
 
55
    _LazyListJoin,
56
56
    MetaDirRepository,
57
 
    MetaDirRepositoryFormat,
58
57
    RepositoryFormat,
59
58
    RepositoryWriteLockResult,
60
 
    RootCommitBuilder,
 
59
    )
 
60
from bzrlib.vf_repository import (
 
61
    MetaDirVersionedFileRepository,
 
62
    MetaDirVersionedFileRepositoryFormat,
 
63
    VersionedFileCommitBuilder,
 
64
    VersionedFileRootCommitBuilder,
61
65
    )
62
66
from bzrlib.trace import (
63
67
    mutter,
66
70
    )
67
71
 
68
72
 
69
 
class PackCommitBuilder(CommitBuilder):
70
 
    """A subclass of CommitBuilder to add texts with pack semantics.
 
73
class PackCommitBuilder(VersionedFileCommitBuilder):
 
74
    """Subclass of VersionedFileCommitBuilder to add texts with pack semantics.
71
75
 
72
76
    Specifically this uses one knit object rather than one knit object per
73
77
    added text, reducing memory and object pressure.
76
80
    def __init__(self, repository, parents, config, timestamp=None,
77
81
                 timezone=None, committer=None, revprops=None,
78
82
                 revision_id=None, lossy=False):
79
 
        CommitBuilder.__init__(self, repository, parents, config,
 
83
        VersionedFileCommitBuilder.__init__(self, repository, parents, config,
80
84
            timestamp=timestamp, timezone=timezone, committer=committer,
81
85
            revprops=revprops, revision_id=revision_id, lossy=lossy)
82
86
        self._file_graph = graph.Graph(
87
91
        return set([key[1] for key in self._file_graph.heads(keys)])
88
92
 
89
93
 
90
 
class PackRootCommitBuilder(RootCommitBuilder):
 
94
class PackRootCommitBuilder(VersionedFileRootCommitBuilder):
91
95
    """A subclass of RootCommitBuilder to add texts with pack semantics.
92
96
 
93
97
    Specifically this uses one knit object rather than one knit object per
97
101
    def __init__(self, repository, parents, config, timestamp=None,
98
102
                 timezone=None, committer=None, revprops=None,
99
103
                 revision_id=None, lossy=False):
100
 
        CommitBuilder.__init__(self, repository, parents, config,
101
 
            timestamp=timestamp, timezone=timezone, committer=committer,
102
 
            revprops=revprops, revision_id=revision_id, lossy=lossy)
 
104
        super(PackRootCommitBuilder, self).__init__(repository, parents,
 
105
            config, timestamp=timestamp, timezone=timezone,
 
106
            committer=committer, revprops=revprops, revision_id=revision_id,
 
107
            lossy=lossy)
103
108
        self._file_graph = graph.Graph(
104
109
            repository._pack_collection.text_index.combined_index)
105
110
 
1622
1627
            self._resume_pack(token)
1623
1628
 
1624
1629
 
1625
 
class PackRepository(MetaDirRepository):
 
1630
class PackRepository(MetaDirVersionedFileRepository):
1626
1631
    """Repository with knit objects stored inside pack containers.
1627
1632
 
1628
1633
    The layering for a KnitPackRepository is:
1660
1665
        self._commit_builder_class = _commit_builder_class
1661
1666
        self._serializer = _serializer
1662
1667
        self._reconcile_fixes_text_parents = True
 
1668
        if self._format.supports_external_lookups:
 
1669
            self._unstacked_provider = graph.CachingParentsProvider(
 
1670
                self._make_parents_provider_unstacked())
 
1671
        else:
 
1672
            self._unstacked_provider = graph.CachingParentsProvider(self)
 
1673
        self._unstacked_provider.disable_cache()
1663
1674
 
1664
1675
    @needs_read_lock
1665
1676
    def _all_revision_ids(self):
1671
1682
        self._pack_collection._abort_write_group()
1672
1683
 
1673
1684
    def _make_parents_provider(self):
1674
 
        return graph.CachingParentsProvider(self)
 
1685
        if not self._format.supports_external_lookups:
 
1686
            return self._unstacked_provider
 
1687
        return graph.StackedParentsProvider(_LazyListJoin(
 
1688
            [self._unstacked_provider], self._fallback_repositories))
1675
1689
 
1676
1690
    def _refresh_data(self):
1677
1691
        if not self.is_locked():
1678
1692
            return
1679
1693
        self._pack_collection.reload_pack_names()
 
1694
        self._unstacked_provider.disable_cache()
 
1695
        self._unstacked_provider.enable_cache()
1680
1696
 
1681
1697
    def _start_write_group(self):
1682
1698
        self._pack_collection._start_write_group()
1684
1700
    def _commit_write_group(self):
1685
1701
        hint = self._pack_collection._commit_write_group()
1686
1702
        self.revisions._index._key_dependencies.clear()
 
1703
        # The commit may have added keys that were previously cached as
 
1704
        # missing, so reset the cache.
 
1705
        self._unstacked_provider.disable_cache()
 
1706
        self._unstacked_provider.enable_cache()
1687
1707
        return hint
1688
1708
 
1689
1709
    def suspend_write_group(self):
1730
1750
            if 'relock' in debug.debug_flags and self._prev_lock == 'w':
1731
1751
                note('%r was write locked again', self)
1732
1752
            self._prev_lock = 'w'
 
1753
            self._unstacked_provider.enable_cache()
1733
1754
            for repo in self._fallback_repositories:
1734
1755
                # Writes don't affect fallback repos
1735
1756
                repo.lock_read()
1750
1771
            if 'relock' in debug.debug_flags and self._prev_lock == 'r':
1751
1772
                note('%r was read locked again', self)
1752
1773
            self._prev_lock = 'r'
 
1774
            self._unstacked_provider.enable_cache()
1753
1775
            for repo in self._fallback_repositories:
1754
1776
                repo.lock_read()
1755
1777
            self._refresh_data()
1787
1809
    def unlock(self):
1788
1810
        if self._write_lock_count == 1 and self._write_group is not None:
1789
1811
            self.abort_write_group()
 
1812
            self._unstacked_provider.disable_cache()
1790
1813
            self._transaction = None
1791
1814
            self._write_lock_count = 0
1792
1815
            raise errors.BzrError(
1802
1825
            self.control_files.unlock()
1803
1826
 
1804
1827
        if not self.is_locked():
 
1828
            self._unstacked_provider.disable_cache()
1805
1829
            for repo in self._fallback_repositories:
1806
1830
                repo.unlock()
1807
1831
 
1808
1832
 
1809
 
class RepositoryFormatPack(MetaDirRepositoryFormat):
 
1833
class RepositoryFormatPack(MetaDirVersionedFileRepositoryFormat):
1810
1834
    """Format logic for pack structured repositories.
1811
1835
 
1812
1836
    This repository format has:
1842
1866
    index_class = None
1843
1867
    _fetch_uses_deltas = True
1844
1868
    fast_deltas = False
1845
 
    supports_full_versioned_files = True
1846
1869
    supports_funky_characters = True
1847
1870
    revision_graph_can_have_wrong_parents = True
1848
1871