72
74
added text, reducing memory and object pressure.
77
def __init__(self, repository, parents, config, timestamp=None,
78
timezone=None, committer=None, revprops=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)
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,
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)])
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.
103
def __init__(self, repository, parents, config, timestamp=None,
104
timezone=None, committer=None, revprops=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)
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)
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)])
94
122
class Pack(object):
95
123
"""An in memory proxy for a pack and its indices.
189
217
def __init__(self, upload_transport, index_transport, pack_transport,
218
upload_suffix='', file_mode=None):
191
219
"""Create a NewPack instance.
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.
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(
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,
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)
538
571
def _create_pack_from_packs(self):
539
572
self.pb.update("Opening pack", 0, 5)
713
746
pb = ui.ui_factory.nested_progress_bar()
715
return self._do_copy_nodes_graph(nodes, index_map, writer,
716
write_index, output_lines, pb)
748
for result in self._do_copy_nodes_graph(nodes, index_map, writer,
749
write_index, output_lines, pb):
752
# Python 2.4 does not permit try:finally: in a generator.
720
758
def _do_copy_nodes_graph(self, nodes, index_map, writer, write_index,
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
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')
1809
1849
def _ignore_setting_bzrdir(self, format):
1842
1882
def _get_matching_bzrdir(self):
1843
1883
return bzrdir.format_registry.make_bzrdir(
1844
'knitpack-subtree-experimental')
1884
'pack-0.92-subtree')
1846
1886
def _ignore_setting_bzrdir(self, format):
1863
1903
def get_format_description(self):
1864
1904
"""See RepositoryFormat.get_format_description()."""
1865
1905
return "Packs containing knits with subtree support\n"
1908
class RepositoryFormatKnitPack4(RepositoryFormatPack):
1909
"""A rich-root, no subtrees parameterised Pack repository.
1911
This repository format uses the xml6 serializer to get:
1912
- support for recording full info about the tree root
1914
This format was introduced in 1.0.
1917
repository_class = KnitPackRepository
1918
_commit_builder_class = PackRootCommitBuilder
1919
rich_root_data = True
1920
supports_tree_reference = False
1921
_serializer = xml6.serializer_v6
1923
def _get_matching_bzrdir(self):
1924
return bzrdir.format_registry.make_bzrdir(
1927
def _ignore_setting_bzrdir(self, format):
1930
_matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
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)
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")
1942
def get_format_description(self):
1943
"""See RepositoryFormat.get_format_description()."""
1944
return "Packs containing knits with rich root support\n"