~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/pack_repo.py

  • Committer: Andrew Bennetts
  • Date: 2008-07-28 06:53:44 UTC
  • mfrom: (3581 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3583.
  • Revision ID: andrew.bennetts@canonical.com-20080728065344-ocndjoycs903q6fz
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
from bzrlib.repofmt.knitrepo import KnitRepository
63
63
from bzrlib.repository import (
64
64
    CommitBuilder,
 
65
    InterRepository,
65
66
    MetaDirRepository,
66
67
    MetaDirRepositoryFormat,
67
68
    RepositoryFormat,
138
139
        :param text_index: A GraphIndex for determining what file texts
139
140
            are present in the pack and accessing the locations of their
140
141
            texts/deltas (via (fileid, revisionid) tuples).
141
 
        :param revision_index: A GraphIndex for determining what signatures are
 
142
        :param signature_index: A GraphIndex for determining what signatures are
142
143
            present in the Pack and accessing the locations of their texts.
143
144
        """
144
145
        self.revision_index = revision_index
208
209
 
209
210
    def __repr__(self):
210
211
        return "<bzrlib.repofmt.pack_repo.Pack object at 0x%x, %s, %s" % (
211
 
            id(self), self.transport, self.name)
 
212
            id(self), self.pack_transport, self.name)
212
213
 
213
214
 
214
215
class NewPack(Pack):
1107
1108
 
1108
1109
 
1109
1110
class RepositoryPackCollection(object):
1110
 
    """Management of packs within a repository."""
 
1111
    """Management of packs within a repository.
 
1112
    
 
1113
    :ivar _names: map of {pack_name: (index_size,)}
 
1114
    """
1111
1115
 
1112
1116
    def __init__(self, repo, transport, index_transport, upload_transport,
1113
1117
                 pack_transport):
1725
1729
        self._reconcile_fixes_text_parents = True
1726
1730
        self._reconcile_backsup_inventory = False
1727
1731
 
 
1732
    def _warn_if_deprecated(self):
 
1733
        # This class isn't deprecated
 
1734
        pass
 
1735
 
1728
1736
    def _abort_write_group(self):
1729
1737
        self._pack_collection._abort_write_group()
1730
1738
 
1774
1782
        parent_map = self.get_parent_map(revision_ids)
1775
1783
        return [parent_map.get(r, None) for r in revision_ids]
1776
1784
 
1777
 
    def get_parent_map(self, keys):
1778
 
        """See graph._StackedParentsProvider.get_parent_map
1779
 
 
1780
 
        This implementation accesses the combined revision index to provide
1781
 
        answers.
1782
 
        """
1783
 
        self._pack_collection.ensure_loaded()
1784
 
        index = self._pack_collection.revision_index.combined_index
1785
 
        keys = set(keys)
1786
 
        if None in keys:
1787
 
            raise ValueError('get_parent_map(None) is not valid')
1788
 
        if _mod_revision.NULL_REVISION in keys:
1789
 
            keys.discard(_mod_revision.NULL_REVISION)
1790
 
            found_parents = {_mod_revision.NULL_REVISION:()}
1791
 
        else:
1792
 
            found_parents = {}
1793
 
        search_keys = set((revision_id,) for revision_id in keys)
1794
 
        for index, key, value, refs in index.iter_entries(search_keys):
1795
 
            parents = refs[0]
1796
 
            if not parents:
1797
 
                parents = (_mod_revision.NULL_REVISION,)
1798
 
            else:
1799
 
                parents = tuple(parent[0] for parent in parents)
1800
 
            found_parents[key[0]] = parents
1801
 
        return found_parents
1802
 
 
1803
 
    def has_revisions(self, revision_ids):
1804
 
        """See Repository.has_revisions()."""
1805
 
        revision_ids = set(revision_ids)
1806
 
        result = revision_ids.intersection(
1807
 
            set([None, _mod_revision.NULL_REVISION]))
1808
 
        revision_ids.difference_update(result)
1809
 
        index = self._pack_collection.revision_index.combined_index
1810
 
        keys = [(revision_id,) for revision_id in revision_ids]
1811
 
        result.update(node[1][0] for node in index.iter_entries(keys))
1812
 
        return result
1813
 
 
1814
1785
    def _make_parents_provider(self):
1815
1786
        return graph.CachingParentsProvider(self)
1816
1787
 
1849
1820
        if self._write_lock_count == 1:
1850
1821
            from bzrlib import transactions
1851
1822
            self._transaction = transactions.WriteTransaction()
 
1823
            for repo in self._fallback_repositories:
 
1824
                # Writes don't affect fallback repos
 
1825
                repo.lock_read()
1852
1826
        self._refresh_data()
1853
1827
 
1854
1828
    def lock_read(self):
1856
1830
            self._write_lock_count += 1
1857
1831
        else:
1858
1832
            self.control_files.lock_read()
 
1833
            for repo in self._fallback_repositories:
 
1834
                # Writes don't affect fallback repos
 
1835
                repo.lock_read()
1859
1836
        self._refresh_data()
1860
1837
 
1861
1838
    def leave_lock_in_place(self):
1897
1874
                transaction = self._transaction
1898
1875
                self._transaction = None
1899
1876
                transaction.finish()
 
1877
                for repo in self._fallback_repositories:
 
1878
                    repo.unlock()
1900
1879
        else:
1901
1880
            self.control_files.unlock()
 
1881
            for repo in self._fallback_repositories:
 
1882
                repo.unlock()
 
1883
 
 
1884
 
 
1885
class RepositoryFormatPack(MetaDirRepositoryFormat):
 
1886
    """Format logic for pack structured repositories.
 
1887
 
 
1888
    This repository format has:
 
1889
     - a list of packs in pack-names
 
1890
     - packs in packs/NAME.pack
 
1891
     - indices in indices/NAME.{iix,six,tix,rix}
 
1892
     - knit deltas in the packs, knit indices mapped to the indices.
 
1893
     - thunk objects to support the knits programming API.
 
1894
     - a format marker of its own
 
1895
     - an optional 'shared-storage' flag
 
1896
     - an optional 'no-working-trees' flag
 
1897
     - a LockDir lock
 
1898
    """
 
1899
 
 
1900
    # Set this attribute in derived classes to control the repository class
 
1901
    # created by open and initialize.
 
1902
    repository_class = None
 
1903
    # Set this attribute in derived classes to control the
 
1904
    # _commit_builder_class that the repository objects will have passed to
 
1905
    # their constructor.
 
1906
    _commit_builder_class = None
 
1907
    # Set this attribute in derived clases to control the _serializer that the
 
1908
    # repository objects will have passed to their constructor.
 
1909
    _serializer = None
 
1910
    # External references are not supported in pack repositories yet.
 
1911
    supports_external_lookups = False
 
1912
 
 
1913
    def initialize(self, a_bzrdir, shared=False):
 
1914
        """Create a pack based repository.
 
1915
 
 
1916
        :param a_bzrdir: bzrdir to contain the new repository; must already
 
1917
            be initialized.
 
1918
        :param shared: If true the repository will be initialized as a shared
 
1919
                       repository.
 
1920
        """
 
1921
        mutter('creating repository in %s.', a_bzrdir.transport.base)
 
1922
        dirs = ['indices', 'obsolete_packs', 'packs', 'upload']
 
1923
        builder = GraphIndexBuilder()
 
1924
        files = [('pack-names', builder.finish())]
 
1925
        utf8_files = [('format', self.get_format_string())]
 
1926
        
 
1927
        self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
 
1928
        return self.open(a_bzrdir=a_bzrdir, _found=True)
 
1929
 
 
1930
    def open(self, a_bzrdir, _found=False, _override_transport=None):
 
1931
        """See RepositoryFormat.open().
 
1932
        
 
1933
        :param _override_transport: INTERNAL USE ONLY. Allows opening the
 
1934
                                    repository at a slightly different url
 
1935
                                    than normal. I.e. during 'upgrade'.
 
1936
        """
 
1937
        if not _found:
 
1938
            format = RepositoryFormat.find_format(a_bzrdir)
 
1939
        if _override_transport is not None:
 
1940
            repo_transport = _override_transport
 
1941
        else:
 
1942
            repo_transport = a_bzrdir.get_repository_transport(None)
 
1943
        control_files = lockable_files.LockableFiles(repo_transport,
 
1944
                                'lock', lockdir.LockDir)
 
1945
        return self.repository_class(_format=self,
 
1946
                              a_bzrdir=a_bzrdir,
 
1947
                              control_files=control_files,
 
1948
                              _commit_builder_class=self._commit_builder_class,
 
1949
                              _serializer=self._serializer)
 
1950
 
 
1951
 
 
1952
class RepositoryFormatKnitPack1(RepositoryFormatPack):
 
1953
    """A no-subtrees parameterized Pack repository.
 
1954
 
 
1955
    This format was introduced in 0.92.
 
1956
    """
 
1957
 
 
1958
    repository_class = KnitPackRepository
 
1959
    _commit_builder_class = PackCommitBuilder
 
1960
    _serializer = xml5.serializer_v5
 
1961
 
 
1962
    def _get_matching_bzrdir(self):
 
1963
        return bzrdir.format_registry.make_bzrdir('pack-0.92')
 
1964
 
 
1965
    def _ignore_setting_bzrdir(self, format):
 
1966
        pass
 
1967
 
 
1968
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
 
1969
 
 
1970
    def get_format_string(self):
 
1971
        """See RepositoryFormat.get_format_string()."""
 
1972
        return "Bazaar pack repository format 1 (needs bzr 0.92)\n"
 
1973
 
 
1974
    def get_format_description(self):
 
1975
        """See RepositoryFormat.get_format_description()."""
 
1976
        return "Packs containing knits without subtree support"
 
1977
 
 
1978
    def check_conversion_target(self, target_format):
 
1979
        pass
1902
1980
 
1903
1981
 
1904
1982
class RepositoryFormatPack(MetaDirRepositoryFormat):
2079
2157
        return "Packs containing knits with rich root support\n"
2080
2158
 
2081
2159
 
 
2160
class RepositoryFormatKnitPack5(RepositoryFormatPack):
 
2161
    """Repository that supports external references to allow stacking.
 
2162
 
 
2163
    New in release 1.6.
 
2164
 
 
2165
    Supports external lookups, which results in non-truncated ghosts after
 
2166
    reconcile compared to pack-0.92 formats.
 
2167
    """
 
2168
 
 
2169
    repository_class = KnitPackRepository
 
2170
    _commit_builder_class = PackCommitBuilder
 
2171
    _serializer = xml5.serializer_v5
 
2172
    supports_external_lookups = True
 
2173
 
 
2174
    def _get_matching_bzrdir(self):
 
2175
        return bzrdir.format_registry.make_bzrdir('development1')
 
2176
 
 
2177
    def _ignore_setting_bzrdir(self, format):
 
2178
        pass
 
2179
 
 
2180
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
 
2181
 
 
2182
    def get_format_string(self):
 
2183
        """See RepositoryFormat.get_format_string()."""
 
2184
        return "Bazaar RepositoryFormatKnitPack5 (bzr 1.6)\n"
 
2185
 
 
2186
    def get_format_description(self):
 
2187
        """See RepositoryFormat.get_format_description()."""
 
2188
        return self.__doc__
 
2189
 
 
2190
    def check_conversion_target(self, target_format):
 
2191
        pass
 
2192
 
 
2193
 
 
2194
class RepositoryFormatKnitPack5RichRoot(RepositoryFormatPack):
 
2195
    """A repository with subtrees and external references.
 
2196
 
 
2197
    New in release 1.6.
 
2198
 
 
2199
    Supports external lookups, which results in non-truncated ghosts after
 
2200
    reconcile compared to pack-0.92 formats.
 
2201
    """
 
2202
 
 
2203
    repository_class = KnitPackRepository
 
2204
    _commit_builder_class = PackRootCommitBuilder
 
2205
    rich_root_data = True
 
2206
    supports_tree_reference = False # no subtrees
 
2207
    _serializer = xml7.serializer_v7
 
2208
 
 
2209
    supports_external_lookups = True
 
2210
 
 
2211
    def _get_matching_bzrdir(self):
 
2212
        return bzrdir.format_registry.make_bzrdir(
 
2213
            'development1-subtree')
 
2214
 
 
2215
    def _ignore_setting_bzrdir(self, format):
 
2216
        pass
 
2217
 
 
2218
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
 
2219
 
 
2220
    def check_conversion_target(self, target_format):
 
2221
        if not target_format.rich_root_data:
 
2222
            raise errors.BadConversionTarget(
 
2223
                'Does not support rich root data.', target_format)
 
2224
            
 
2225
    def get_format_string(self):
 
2226
        """See RepositoryFormat.get_format_string()."""
 
2227
        return "Bazaar RepositoryFormatKnitPack5RichRoot (bzr 1.6)\n"
 
2228
 
 
2229
    def get_format_description(self):
 
2230
        """See RepositoryFormat.get_format_description()."""
 
2231
        return self.__doc__
 
2232
 
 
2233
 
2082
2234
class RepositoryFormatPackDevelopment0(RepositoryFormatPack):
2083
2235
    """A no-subtrees development repository.
2084
2236
 
2154
2306
            "pack-0.92-subtree\n")
2155
2307
 
2156
2308
 
 
2309
class RepositoryFormatPackDevelopment1(RepositoryFormatPackDevelopment0):
 
2310
    """A no-subtrees development repository.
 
2311
 
 
2312
    This format should be retained until the second release after bzr 1.5.
 
2313
 
 
2314
    Supports external lookups, which results in non-truncated ghosts after
 
2315
    reconcile compared to pack-0.92 formats.
 
2316
    """
 
2317
 
 
2318
    supports_external_lookups = True
 
2319
 
 
2320
    def _get_matching_bzrdir(self):
 
2321
        return bzrdir.format_registry.make_bzrdir('development1')
 
2322
 
 
2323
    def _ignore_setting_bzrdir(self, format):
 
2324
        pass
 
2325
 
 
2326
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
 
2327
 
 
2328
    def get_format_string(self):
 
2329
        """See RepositoryFormat.get_format_string()."""
 
2330
        return "Bazaar development format 1 (needs bzr.dev from before 1.6)\n"
 
2331
 
 
2332
    def get_format_description(self):
 
2333
        """See RepositoryFormat.get_format_description()."""
 
2334
        return ("Development repository format, currently the same as "
 
2335
            "pack-0.92 with external reference support.\n")
 
2336
 
 
2337
    def check_conversion_target(self, target_format):
 
2338
        pass
 
2339
 
 
2340
 
 
2341
class RepositoryFormatPackDevelopment1Subtree(RepositoryFormatPackDevelopment0Subtree):
 
2342
    """A subtrees development repository.
 
2343
 
 
2344
    This format should be retained until the second release after bzr 1.5.
 
2345
 
 
2346
    Supports external lookups, which results in non-truncated ghosts after
 
2347
    reconcile compared to pack-0.92 formats.
 
2348
    """
 
2349
 
 
2350
    supports_external_lookups = True
 
2351
 
 
2352
    def _get_matching_bzrdir(self):
 
2353
        return bzrdir.format_registry.make_bzrdir(
 
2354
            'development1-subtree')
 
2355
 
 
2356
    def _ignore_setting_bzrdir(self, format):
 
2357
        pass
 
2358
 
 
2359
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
 
2360
 
 
2361
    def check_conversion_target(self, target_format):
 
2362
        if not target_format.rich_root_data:
 
2363
            raise errors.BadConversionTarget(
 
2364
                'Does not support rich root data.', target_format)
 
2365
        if not getattr(target_format, 'supports_tree_reference', False):
 
2366
            raise errors.BadConversionTarget(
 
2367
                'Does not support nested trees', target_format)
 
2368
            
 
2369
    def get_format_string(self):
 
2370
        """See RepositoryFormat.get_format_string()."""
 
2371
        return ("Bazaar development format 1 with subtree support "
 
2372
            "(needs bzr.dev from before 1.6)\n")
 
2373
 
 
2374
    def get_format_description(self):
 
2375
        """See RepositoryFormat.get_format_description()."""
 
2376
        return ("Development repository format, currently the same as "
 
2377
            "pack-0.92-subtree with external reference support.\n")