/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/pack_repo.py

  • Committer: Michael Hudson
  • Date: 2007-11-29 18:58:23 UTC
  • mfrom: (3048 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3189.
  • Revision ID: michael.hudson@canonical.com-20071129185823-vpokl0unnsjib0xw
merge bzr.dev
a bit involved, hope i got it all right!

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
        pack,
27
27
        ui,
28
28
        )
 
29
from bzrlib.graph import Graph
29
30
from bzrlib.index import (
30
31
    GraphIndex,
31
32
    GraphIndexBuilder,
48
49
    osutils,
49
50
    transactions,
50
51
    xml5,
 
52
    xml6,
51
53
    xml7,
52
54
    )
53
55
 
72
74
    added text, reducing memory and object pressure.
73
75
    """
74
76
 
 
77
    def __init__(self, repository, parents, config, timestamp=None,
 
78
                 timezone=None, committer=None, revprops=None,
 
79
                 revision_id=None):
 
80
        CommitBuilder.__init__(self, repository, parents, config,
 
81
            timestamp=timestamp, timezone=timezone, committer=committer,
 
82
            revprops=revprops, revision_id=revision_id)
 
83
        self._file_graph = Graph(
 
84
            repository._pack_collection.text_index.combined_index)
 
85
 
75
86
    def _add_text_to_weave(self, file_id, new_lines, parents, nostore_sha):
76
87
        return self.repository._pack_collection._add_text_to_weave(file_id,
77
88
            self._new_revision_id, new_lines, parents, nostore_sha,
78
89
            self.random_revid)
79
90
 
 
91
    def _heads(self, file_id, revision_ids):
 
92
        keys = [(file_id, revision_id) for revision_id in revision_ids]
 
93
        return set([key[1] for key in self._file_graph.heads(keys)])
 
94
 
80
95
 
81
96
class PackRootCommitBuilder(RootCommitBuilder):
82
97
    """A subclass of RootCommitBuilder to add texts with pack semantics.
85
100
    added text, reducing memory and object pressure.
86
101
    """
87
102
 
 
103
    def __init__(self, repository, parents, config, timestamp=None,
 
104
                 timezone=None, committer=None, revprops=None,
 
105
                 revision_id=None):
 
106
        CommitBuilder.__init__(self, repository, parents, config,
 
107
            timestamp=timestamp, timezone=timezone, committer=committer,
 
108
            revprops=revprops, revision_id=revision_id)
 
109
        self._file_graph = Graph(
 
110
            repository._pack_collection.text_index.combined_index)
 
111
 
88
112
    def _add_text_to_weave(self, file_id, new_lines, parents, nostore_sha):
89
113
        return self.repository._pack_collection._add_text_to_weave(file_id,
90
114
            self._new_revision_id, new_lines, parents, nostore_sha,
91
115
            self.random_revid)
92
116
 
 
117
    def _heads(self, file_id, revision_ids):
 
118
        keys = [(file_id, revision_id) for revision_id in revision_ids]
 
119
        return set([key[1] for key in self._file_graph.heads(keys)])
 
120
 
93
121
 
94
122
class Pack(object):
95
123
    """An in memory proxy for a pack and its indices.
187
215
        }
188
216
 
189
217
    def __init__(self, upload_transport, index_transport, pack_transport,
190
 
        upload_suffix=''):
 
218
        upload_suffix='', file_mode=None):
191
219
        """Create a NewPack instance.
192
220
 
193
221
        :param upload_transport: A writable transport for the pack to be
199
227
            upload_transport.clone('../packs').
200
228
        :param upload_suffix: An optional suffix to be given to any temporary
201
229
            files created during the pack creation. e.g '.autopack'
 
230
        :param file_mode: An optional file mode to create the new files with.
202
231
        """
203
232
        # The relative locations of the packs are constrained, but all are
204
233
        # passed in because the caller has them, so as to avoid object churn.
223
252
        self.index_transport = index_transport
224
253
        # where is the pack renamed to when it is finished?
225
254
        self.pack_transport = pack_transport
 
255
        # What file mode to upload the pack and indices with.
 
256
        self._file_mode = file_mode
226
257
        # tracks the content written to the .pack file.
227
258
        self._hash = md5.new()
228
259
        # a four-tuple with the length in bytes of the indices, once the pack
239
270
        self.start_time = time.time()
240
271
        # open an output stream for the data added to the pack.
241
272
        self.write_stream = self.upload_transport.open_write_stream(
242
 
            self.random_name)
 
273
            self.random_name, mode=self._file_mode)
243
274
        if 'pack' in debug.debug_flags:
244
275
            mutter('%s: create_pack: pack stream open: %s%s t+%6.3fs',
245
276
                time.ctime(), self.upload_transport.base, self.random_name,
368
399
        """
369
400
        index_name = self.index_name(index_type, self.name)
370
401
        self.index_sizes[self.index_offset(index_type)] = \
371
 
            self.index_transport.put_file(index_name, index.finish())
 
402
            self.index_transport.put_file(index_name, index.finish(),
 
403
            mode=self._file_mode)
372
404
        if 'pack' in debug.debug_flags:
373
405
            # XXX: size might be interesting?
374
406
            mutter('%s: create_pack: wrote %s index: %s%s t+%6.3fs',
533
565
        """Open a pack for the pack we are creating."""
534
566
        return NewPack(self._pack_collection._upload_transport,
535
567
            self._pack_collection._index_transport,
536
 
            self._pack_collection._pack_transport, upload_suffix=self.suffix)
 
568
            self._pack_collection._pack_transport, upload_suffix=self.suffix,
 
569
            file_mode=self._pack_collection.repo.control_files._file_mode)
537
570
 
538
571
    def _create_pack_from_packs(self):
539
572
        self.pb.update("Opening pack", 0, 5)
712
745
        """
713
746
        pb = ui.ui_factory.nested_progress_bar()
714
747
        try:
715
 
            return self._do_copy_nodes_graph(nodes, index_map, writer,
716
 
                write_index, output_lines, pb)
717
 
        finally:
 
748
            for result in self._do_copy_nodes_graph(nodes, index_map, writer,
 
749
                write_index, output_lines, pb):
 
750
                yield result
 
751
        except Exception:
 
752
            # Python 2.4 does not permit try:finally: in a generator.
 
753
            pb.finished()
 
754
            raise
 
755
        else:
718
756
            pb.finished()
719
757
 
720
758
    def _do_copy_nodes_graph(self, nodes, index_map, writer, write_index,
1245
1283
            # changing it.
1246
1284
            for key, value in disk_nodes:
1247
1285
                builder.add_node(key, value)
1248
 
            self.transport.put_file('pack-names', builder.finish())
 
1286
            self.transport.put_file('pack-names', builder.finish(),
 
1287
                mode=self.repo.control_files._file_mode)
1249
1288
            # move the baseline forward
1250
1289
            self._packs_at_load = disk_nodes
1251
1290
            # now clear out the obsolete packs directory
1288
1327
        if not self.repo.is_write_locked():
1289
1328
            raise errors.NotWriteLocked(self)
1290
1329
        self._new_pack = NewPack(self._upload_transport, self._index_transport,
1291
 
            self._pack_transport, upload_suffix='.pack')
 
1330
            self._pack_transport, upload_suffix='.pack',
 
1331
            file_mode=self.repo.control_files._file_mode)
1292
1332
        # allow writing: queue writes to a new index
1293
1333
        self.revision_index.add_writable_index(self._new_pack.revision_index,
1294
1334
            self._new_pack)
1804
1844
    _serializer = xml5.serializer_v5
1805
1845
 
1806
1846
    def _get_matching_bzrdir(self):
1807
 
        return bzrdir.format_registry.make_bzrdir('knitpack-experimental')
 
1847
        return bzrdir.format_registry.make_bzrdir('pack-0.92')
1808
1848
 
1809
1849
    def _ignore_setting_bzrdir(self, format):
1810
1850
        pass
1841
1881
 
1842
1882
    def _get_matching_bzrdir(self):
1843
1883
        return bzrdir.format_registry.make_bzrdir(
1844
 
            'knitpack-subtree-experimental')
 
1884
            'pack-0.92-subtree')
1845
1885
 
1846
1886
    def _ignore_setting_bzrdir(self, format):
1847
1887
        pass
1863
1903
    def get_format_description(self):
1864
1904
        """See RepositoryFormat.get_format_description()."""
1865
1905
        return "Packs containing knits with subtree support\n"
 
1906
 
 
1907
 
 
1908
class RepositoryFormatKnitPack4(RepositoryFormatPack):
 
1909
    """A rich-root, no subtrees parameterised Pack repository.
 
1910
 
 
1911
    This repository format uses the xml6 serializer to get:
 
1912
     - support for recording full info about the tree root
 
1913
 
 
1914
    This format was introduced in 1.0.
 
1915
    """
 
1916
 
 
1917
    repository_class = KnitPackRepository
 
1918
    _commit_builder_class = PackRootCommitBuilder
 
1919
    rich_root_data = True
 
1920
    supports_tree_reference = False
 
1921
    _serializer = xml6.serializer_v6
 
1922
 
 
1923
    def _get_matching_bzrdir(self):
 
1924
        return bzrdir.format_registry.make_bzrdir(
 
1925
            'rich-root-pack')
 
1926
 
 
1927
    def _ignore_setting_bzrdir(self, format):
 
1928
        pass
 
1929
 
 
1930
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
 
1931
 
 
1932
    def check_conversion_target(self, target_format):
 
1933
        if not target_format.rich_root_data:
 
1934
            raise errors.BadConversionTarget(
 
1935
                'Does not support rich root data.', target_format)
 
1936
 
 
1937
    def get_format_string(self):
 
1938
        """See RepositoryFormat.get_format_string()."""
 
1939
        return ("Bazaar pack repository format 1 with rich root"
 
1940
                " (needs bzr 1.0)\n")
 
1941
 
 
1942
    def get_format_description(self):
 
1943
        """See RepositoryFormat.get_format_description()."""
 
1944
        return "Packs containing knits with rich root support\n"