98
98
ExistingPack and NewPack are used.
101
def __init__(self, revision_index, inventory_index, text_index):
101
def __init__(self, revision_index, inventory_index, text_index,
102
103
"""Create a pack instance.
104
105
:param revision_index: A GraphIndex for determining what revisions are
107
108
present in the Pack and accessing the locations of their
109
110
:param text_index: A GraphIndex for determining what file texts
110
are present in the pack and accessing the locations of their
111
texts/deltas (via (fileid, revisionid) tuples).
111
are present in the pack and accessing the locations of their
112
texts/deltas (via (fileid, revisionid) tuples).
113
:param revision_index: A GraphIndex for determining what signatures are
114
present in the Pack and accessing the locations of their texts.
113
116
self.revision_index = revision_index
114
117
self.inventory_index = inventory_index
115
118
self.text_index = text_index
119
self.signature_index = signature_index
117
121
def get_revision_count(self):
118
122
return self.revision_index.key_count()
140
144
def __init__(self, transport, name, revision_index, inventory_index,
141
145
text_index, signature_index):
142
Pack.__init__(self, revision_index, inventory_index, text_index)
143
self.text_index = text_index
144
self.signature_index = signature_index
146
Pack.__init__(self, revision_index, inventory_index, text_index,
146
149
self.transport = transport
147
150
assert None not in (revision_index, inventory_index, text_index,
189
192
# Texts: compression and per file graph, for all fileids - so two
190
193
# reference lists and two elements in the key tuple.
191
194
InMemoryGraphIndex(reference_lists=2, key_elements=2),
195
# Signatures: Just blobs to store, no compression, no parents
197
InMemoryGraphIndex(reference_lists=0),
193
199
# where should the new pack be opened
194
200
self.upload_transport = upload_transport
225
231
self.inventory_index_name, 'inventory')
226
232
self._write_index(new_name, self.text_index, 2,
227
233
self.text_index_name, 'file texts')
234
self._write_index(new_name, self.signature_index, 3,
235
self.signature_index_name, 'revision signatures')
229
237
def _write_index(self, new_name, index, index_offset, name_getter, label):
230
238
"""Write out an index.
378
386
self._execute_pack_operations(pack_operations)
381
def flush_revision_signature_indices(self, new_name, revision_index_length):
389
def flush_revision_signature_indices(self, new_name, revision_index_length,
390
signature_index_length):
382
391
"""Write out pending indices."""
383
392
# write a revision index (might be empty)
384
393
new_index_name = self._new_pack.revision_index_name(new_name)
403
412
# write a signatures index (might be empty)
404
413
new_index_name = self._new_pack.signature_index_name(new_name)
405
signature_index_length = self._index_transport.put_file(
406
new_index_name, self.repo._signature_write_index.finish())
407
self.repo._signature_write_index = None
408
414
sig_index = GraphIndex(self._index_transport, new_index_name,
409
415
signature_index_length)
410
416
if self.repo._signature_all_indices is not None:
415
421
del self.repo._signature_all_indices._indices[1]
416
422
# reset the knit access writer
417
423
self.repo._signature_knit_access.set_writer(None, None, (None, None))
418
return (rev_index, sig_index,
419
signature_index_length)
424
return rev_index, sig_index,
421
426
def flush_inventory_index(self, new_name, inventory_index_length):
422
427
"""Write the index out to new_name."""
596
599
signature_nodes = self._index_contents(signature_index_map,
597
600
signature_filter)
598
601
# copy signature keys and adjust values
599
self._copy_nodes(signature_nodes, signature_index_map, writer, signature_index)
602
self._copy_nodes(signature_nodes, signature_index_map, writer, new_pack.signature_index)
600
603
if 'fetch' in debug.debug_flags:
601
604
mutter('%s: create_pack: revision signatures copied: %s%s %d items t+%6.3fs',
602
605
time.ctime(), self._upload_transport.base, random_name,
603
signature_index.key_count(),
606
new_pack.signature_index.key_count(),
604
607
time.time() - new_pack.start_time)
605
608
# finish the pack
613
616
if 0 == sum((new_pack.get_revision_count(),
614
617
new_pack.inventory_index.key_count(),
615
618
new_pack.text_index.key_count(),
616
signature_index.key_count(),
619
new_pack.signature_index.key_count(),
618
621
self._upload_transport.delete(random_name)
621
index_transport = self._index_transport
622
624
new_pack.finish()
623
revision_index_length = new_pack.index_sizes[0]
624
inventory_index_length = new_pack.index_sizes[1]
625
text_index_length = new_pack.index_sizes[2]
627
signature_index_name = new_pack.signature_index_name(new_name)
628
signature_index_length = index_transport.put_file(signature_index_name,
629
signature_index.finish())
630
if 'fetch' in debug.debug_flags:
631
# XXX: size might be interesting?
632
mutter('%s: create_pack: wrote revision signatures index: %s%s t+%6.3fs',
633
time.ctime(), self._upload_transport.base, random_name,
634
time.time() - new_pack.start_time)
636
self.allocate(new_name, revision_index_length, inventory_index_length,
637
text_index_length, signature_index_length)
626
self.allocate(new_name, new_pack.index_sizes[0],
627
new_pack.index_sizes[1], new_pack.index_sizes[2],
628
new_pack.index_sizes[3])
638
629
# rename into place. XXX: should rename each index too rather than just
639
630
# uploading blind under the chosen name.
640
631
write_stream.close()
641
632
self._upload_transport.rename(random_name, '../packs/' + new_name + '.pack')
642
633
result = ExistingPack(self._upload_transport.clone('../packs/'), new_name,
643
634
new_pack.revision_index, new_pack.inventory_index, new_pack.text_index,
635
new_pack.signature_index)
645
636
if 'fetch' in debug.debug_flags:
646
637
# XXX: size might be interesting?
647
638
mutter('%s: create_pack: pack renamed into place: %s%s->%s%s t+%6.3fs',
1143
1133
self.flush_text_index(new_name, self._new_pack.index_sizes[2])
1145
1135
self.flush_inventory_index(new_name, self._new_pack.index_sizes[1])
1147
sig_index, signature_index_length = \
1136
rev_index, sig_index = \
1148
1137
self.flush_revision_signature_indices(new_name,
1149
self._new_pack.index_sizes[0])
1138
self._new_pack.index_sizes[0], self._new_pack.index_sizes[3])
1150
1139
new_pack = ExistingPack(self._upload_transport.clone('../packs/'),
1151
1140
new_name, rev_index, inv_index, txt_index, sig_index)
1152
1141
self._write_stream.close()
1160
1149
# occuring during the write of that file.
1161
1150
self.allocate(new_name, self._new_pack.index_sizes[0],
1162
1151
self._new_pack.index_sizes[1], self._new_pack.index_sizes[2],
1163
signature_index_length)
1152
self._new_pack.index_sizes[3])
1164
1153
self.repo._open_pack_tuple = None
1165
1154
self._new_pack = None
1166
1155
if not self.autopack():
1235
1224
pack_map, indices = self.repo._packs._make_index_map('.six')
1236
1225
if self.repo.is_in_write_group():
1237
1226
# allow writing: queue writes to a new index
1238
indices.insert(0, self.repo._signature_write_index)
1239
pack_map[self.repo._signature_write_index] = self.repo._open_pack_tuple
1240
writer = self.repo._packs._open_pack_writer, self.repo._signature_write_index
1241
add_callback = self.repo._signature_write_index.add_nodes
1227
indices.insert(0, self.repo._packs._new_pack.signature_index)
1228
pack_map[self.repo._packs._new_pack.signature_index] = self.repo._open_pack_tuple
1229
writer = self.repo._packs._open_pack_writer, self.repo._packs._new_pack.signature_index
1230
add_callback = self.repo._packs._new_pack.signature_index.add_nodes
1244
1233
add_callback = None # no data-adding permitted.
1256
1245
return self.repo._signature_knit
1258
1247
def data_inserted(self):
1259
if (getattr(self.repo._packs, '_new_pack', None) and
1260
self.repo._packs._new_pack.revision_index.key_count()):
1248
if self.repo._packs._new_pack is None:
1250
if self.repo._packs._new_pack.revision_index.key_count():
1262
if (getattr(self.repo, '_signature_write_index', None) and
1263
self.repo._signature_write_index.key_count()):
1252
if self.repo._packs._new_pack.signature_index.key_count():
1267
1256
def setup(self):
1268
# setup in-memory indices to accumulate data.
1269
self.repo._signature_write_index = InMemoryGraphIndex(0)
1270
1257
# if knit indices have been handed out, add a mutable
1271
1258
# index to them
1272
1259
if self.repo._revision_knit is not None:
1276
1263
self.repo._packs._open_pack_writer,
1277
1264
self.repo._packs._new_pack.revision_index, self.repo._open_pack_tuple)
1278
1265
if self.repo._signature_knit is not None:
1279
self.repo._signature_all_indices.insert_index(0, self.repo._signature_write_index)
1280
self.repo._signature_knit._index._add_callback = self.repo._signature_write_index.add_nodes
1266
self.repo._signature_all_indices.insert_index(0, self.repo._packs._new_pack.signature_index)
1267
self.repo._signature_knit._index._add_callback = self.repo._packs._new_pack.signature_index.add_nodes
1281
1268
self.repo._signature_knit_access.set_writer(
1282
1269
self.repo._packs._open_pack_writer,
1283
self.repo._signature_write_index, self.repo._open_pack_tuple)
1270
self.repo._packs._new_pack.signature_index, self.repo._open_pack_tuple)
1286
1273
class GraphKnitTextStore(VersionedFileStore):