~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/pack_repo.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-07-14 08:21:19 UTC
  • mfrom: (3517.4.20 stacking)
  • Revision ID: pqm@pqm.ubuntu.com-20080714082119-ju6qe5weo8pp7f1c
merge integrated branch stacking

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,
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):
1774
1778
        parent_map = self.get_parent_map(revision_ids)
1775
1779
        return [parent_map.get(r, None) for r in revision_ids]
1776
1780
 
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
1781
    def _make_parents_provider(self):
1804
1782
        return graph.CachingParentsProvider(self)
1805
1783
 
1838
1816
        if self._write_lock_count == 1:
1839
1817
            from bzrlib import transactions
1840
1818
            self._transaction = transactions.WriteTransaction()
 
1819
            for repo in self._fallback_repositories:
 
1820
                # Writes don't affect fallback repos
 
1821
                repo.lock_read()
1841
1822
        self._refresh_data()
1842
1823
 
1843
1824
    def lock_read(self):
1845
1826
            self._write_lock_count += 1
1846
1827
        else:
1847
1828
            self.control_files.lock_read()
 
1829
            for repo in self._fallback_repositories:
 
1830
                # Writes don't affect fallback repos
 
1831
                repo.lock_read()
1848
1832
        self._refresh_data()
1849
1833
 
1850
1834
    def leave_lock_in_place(self):
1886
1870
                transaction = self._transaction
1887
1871
                self._transaction = None
1888
1872
                transaction.finish()
 
1873
                for repo in self._fallback_repositories:
 
1874
                    repo.unlock()
1889
1875
        else:
1890
1876
            self.control_files.unlock()
 
1877
            for repo in self._fallback_repositories:
 
1878
                repo.unlock()
 
1879
 
 
1880
 
 
1881
class RepositoryFormatPack(MetaDirRepositoryFormat):
 
1882
    """Format logic for pack structured repositories.
 
1883
 
 
1884
    This repository format has:
 
1885
     - a list of packs in pack-names
 
1886
     - packs in packs/NAME.pack
 
1887
     - indices in indices/NAME.{iix,six,tix,rix}
 
1888
     - knit deltas in the packs, knit indices mapped to the indices.
 
1889
     - thunk objects to support the knits programming API.
 
1890
     - a format marker of its own
 
1891
     - an optional 'shared-storage' flag
 
1892
     - an optional 'no-working-trees' flag
 
1893
     - a LockDir lock
 
1894
    """
 
1895
 
 
1896
    # Set this attribute in derived classes to control the repository class
 
1897
    # created by open and initialize.
 
1898
    repository_class = None
 
1899
    # Set this attribute in derived classes to control the
 
1900
    # _commit_builder_class that the repository objects will have passed to
 
1901
    # their constructor.
 
1902
    _commit_builder_class = None
 
1903
    # Set this attribute in derived clases to control the _serializer that the
 
1904
    # repository objects will have passed to their constructor.
 
1905
    _serializer = None
 
1906
    # External references are not supported in pack repositories yet.
 
1907
    supports_external_lookups = False
 
1908
 
 
1909
    def initialize(self, a_bzrdir, shared=False):
 
1910
        """Create a pack based repository.
 
1911
 
 
1912
        :param a_bzrdir: bzrdir to contain the new repository; must already
 
1913
            be initialized.
 
1914
        :param shared: If true the repository will be initialized as a shared
 
1915
                       repository.
 
1916
        """
 
1917
        mutter('creating repository in %s.', a_bzrdir.transport.base)
 
1918
        dirs = ['indices', 'obsolete_packs', 'packs', 'upload']
 
1919
        builder = GraphIndexBuilder()
 
1920
        files = [('pack-names', builder.finish())]
 
1921
        utf8_files = [('format', self.get_format_string())]
 
1922
        
 
1923
        self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
 
1924
        return self.open(a_bzrdir=a_bzrdir, _found=True)
 
1925
 
 
1926
    def open(self, a_bzrdir, _found=False, _override_transport=None):
 
1927
        """See RepositoryFormat.open().
 
1928
        
 
1929
        :param _override_transport: INTERNAL USE ONLY. Allows opening the
 
1930
                                    repository at a slightly different url
 
1931
                                    than normal. I.e. during 'upgrade'.
 
1932
        """
 
1933
        if not _found:
 
1934
            format = RepositoryFormat.find_format(a_bzrdir)
 
1935
        if _override_transport is not None:
 
1936
            repo_transport = _override_transport
 
1937
        else:
 
1938
            repo_transport = a_bzrdir.get_repository_transport(None)
 
1939
        control_files = lockable_files.LockableFiles(repo_transport,
 
1940
                                'lock', lockdir.LockDir)
 
1941
        return self.repository_class(_format=self,
 
1942
                              a_bzrdir=a_bzrdir,
 
1943
                              control_files=control_files,
 
1944
                              _commit_builder_class=self._commit_builder_class,
 
1945
                              _serializer=self._serializer)
 
1946
 
 
1947
 
 
1948
class RepositoryFormatKnitPack1(RepositoryFormatPack):
 
1949
    """A no-subtrees parameterized Pack repository.
 
1950
 
 
1951
    This format was introduced in 0.92.
 
1952
    """
 
1953
 
 
1954
    repository_class = KnitPackRepository
 
1955
    _commit_builder_class = PackCommitBuilder
 
1956
    _serializer = xml5.serializer_v5
 
1957
 
 
1958
    def _get_matching_bzrdir(self):
 
1959
        return bzrdir.format_registry.make_bzrdir('pack-0.92')
 
1960
 
 
1961
    def _ignore_setting_bzrdir(self, format):
 
1962
        pass
 
1963
 
 
1964
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
 
1965
 
 
1966
    def get_format_string(self):
 
1967
        """See RepositoryFormat.get_format_string()."""
 
1968
        return "Bazaar pack repository format 1 (needs bzr 0.92)\n"
 
1969
 
 
1970
    def get_format_description(self):
 
1971
        """See RepositoryFormat.get_format_description()."""
 
1972
        return "Packs containing knits without subtree support"
 
1973
 
 
1974
    def check_conversion_target(self, target_format):
 
1975
        pass
1891
1976
 
1892
1977
 
1893
1978
class RepositoryFormatPack(MetaDirRepositoryFormat):
2143
2228
            "pack-0.92-subtree\n")
2144
2229
 
2145
2230
 
 
2231
class RepositoryFormatPackDevelopment1(RepositoryFormatPackDevelopment0):
 
2232
    """A no-subtrees development repository.
 
2233
 
 
2234
    This format should be retained until the second release after bzr 1.5.
 
2235
 
 
2236
    Supports external lookups, which results in non-truncated ghosts after
 
2237
    reconcile compared to pack-0.92 formats.
 
2238
    """
 
2239
 
 
2240
    supports_external_lookups = True
 
2241
 
 
2242
    def _get_matching_bzrdir(self):
 
2243
        return bzrdir.format_registry.make_bzrdir('development1')
 
2244
 
 
2245
    def _ignore_setting_bzrdir(self, format):
 
2246
        pass
 
2247
 
 
2248
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
 
2249
 
 
2250
    def get_format_string(self):
 
2251
        """See RepositoryFormat.get_format_string()."""
 
2252
        return "Bazaar development format 1 (needs bzr.dev from before 1.6)\n"
 
2253
 
 
2254
    def get_format_description(self):
 
2255
        """See RepositoryFormat.get_format_description()."""
 
2256
        return ("Development repository format, currently the same as "
 
2257
            "pack-0.92 with external reference support.\n")
 
2258
 
 
2259
    def check_conversion_target(self, target_format):
 
2260
        pass
 
2261
 
 
2262
 
 
2263
class RepositoryFormatPackDevelopment1Subtree(RepositoryFormatPackDevelopment0Subtree):
 
2264
    """A subtrees development repository.
 
2265
 
 
2266
    This format should be retained until the second release after bzr 1.5.
 
2267
 
 
2268
    Supports external lookups, which results in non-truncated ghosts after
 
2269
    reconcile compared to pack-0.92 formats.
 
2270
    """
 
2271
 
 
2272
    supports_external_lookups = True
 
2273
 
 
2274
    def _get_matching_bzrdir(self):
 
2275
        return bzrdir.format_registry.make_bzrdir(
 
2276
            'development1-subtree')
 
2277
 
 
2278
    def _ignore_setting_bzrdir(self, format):
 
2279
        pass
 
2280
 
 
2281
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
 
2282
 
 
2283
    def check_conversion_target(self, target_format):
 
2284
        if not target_format.rich_root_data:
 
2285
            raise errors.BadConversionTarget(
 
2286
                'Does not support rich root data.', target_format)
 
2287
        if not getattr(target_format, 'supports_tree_reference', False):
 
2288
            raise errors.BadConversionTarget(
 
2289
                'Does not support nested trees', target_format)
 
2290
            
 
2291
    def get_format_string(self):
 
2292
        """See RepositoryFormat.get_format_string()."""
 
2293
        return ("Bazaar development format 1 with subtree support "
 
2294
            "(needs bzr.dev from before 1.6)\n")
 
2295
 
 
2296
    def get_format_description(self):
 
2297
        """See RepositoryFormat.get_format_description()."""
 
2298
        return ("Development repository format, currently the same as "
 
2299
            "pack-0.92-subtree with external reference support.\n")