1535
1535
added_keys.extend(
1536
1536
[index_entry[0] for index_entry in index_entries])
1537
1537
del buffered_index_entries[key]
1538
# If there were any deltas which had a missing basis parent, error.
1539
1538
if buffered_index_entries:
1540
from pprint import pformat
1541
raise errors.BzrCheckError(
1542
"record_stream refers to compression parents not in %r:\n%s"
1543
% (self, pformat(sorted(buffered_index_entries.keys()))))
1539
# There were index entries buffered at the end of the stream,
1540
# So these need to be added (if the index supports holding such
1541
# entries for later insertion)
1542
for key in buffered_index_entries:
1543
index_entries = buffered_index_entries[key]
1544
self._index.add_records(index_entries,
1545
missing_compression_parents=True)
1547
def get_missing_compression_parent_keys(self):
1548
"""Return an iterable of keys of missing compression parents.
1550
Check this after calling insert_record_stream to find out if there are
1551
any missing compression parents. If there are, the records that
1552
depend on them are not able to be inserted safely. For atomic
1553
KnitVersionedFiles built on packs, the transaction should be aborted or
1554
suspended - commit will fail at this point. Nonatomic knits will error
1555
earlier because they have no staging area to put pending entries into.
1557
return self._index.get_missing_compression_parents()
1545
1559
def iter_lines_added_or_present_in_keys(self, keys, pb=None):
1546
1560
"""Iterate over the lines in the versioned files from keys.
2218
2232
self._reset_cache()
2219
2233
self.has_graph = True
2221
def add_records(self, records, random_id=False):
2235
def add_records(self, records, random_id=False, missing_compression_parents=False):
2222
2236
"""Add multiple records to the index.
2224
2238
:param records: a list of tuples:
2225
2239
(key, options, access_memo, parents).
2226
2240
:param random_id: If True the ids being added were randomly generated
2227
2241
and no check for existence will be performed.
2242
:param missing_compression_parents: If True the records being added are
2243
only compressed against texts already in the index (or inside
2244
records). If False the records all refer to unavailable texts (or
2245
texts inside records) as compression parents.
2247
if missing_compression_parents:
2248
# It might be nice to get the edge of the records. But keys isn't
2250
keys = sorted(record[0] for record in records)
2251
raise errors.RevisionNotPresent(keys, self)
2230
2253
for record in records:
2231
2254
key = record[0]
2594
2617
def __repr__(self):
2595
2618
return "%s(%r)" % (self.__class__.__name__, self._graph_index)
2597
def add_records(self, records, random_id=False):
2620
def add_records(self, records, random_id=False,
2621
missing_compression_parents=False):
2598
2622
"""Add multiple records to the index.
2600
2624
This function does not insert data into the Immutable GraphIndex
2606
2630
(key, options, access_memo, parents).
2607
2631
:param random_id: If True the ids being added were randomly generated
2608
2632
and no check for existence will be performed.
2633
:param missing_compression_parents: If True the records being added are
2634
only compressed against texts already in the index (or inside
2635
records). If False the records all refer to unavailable texts (or
2636
texts inside records) as compression parents.
2610
2638
if not self._add_callback:
2611
2639
raise errors.ReadOnlyError(self)
2629
2658
if self._deltas:
2630
2659
if 'line-delta' in options:
2631
2660
node_refs = (parents, (parents[0],))
2661
if missing_compression_parents:
2662
compression_parents.add(parents[0])
2633
2664
node_refs = (parents, ())
2656
2687
for key, (value, node_refs) in keys.iteritems():
2657
2688
result.append((key, value))
2658
2689
self._add_callback(result)
2690
if missing_compression_parents:
2691
# This may appear to be incorrect (it does not check for
2692
# compression parents that are in the existing graph index),
2693
# but such records won't have been buffered, so this is
2694
# actually correct: every entry when
2695
# missing_compression_parents==True either has a missing parent, or
2696
# a parent that is one of the keys in records.
2697
compression_parents.difference_update(keys)
2698
self._missing_compression_parents.update(compression_parents)
2699
# Adding records may have satisfied missing compression parents.
2700
self._missing_compression_parents.difference_update(keys)
2660
2702
def scan_unvalidated_index(self, graph_index):
2661
2703
"""Inform this _KnitGraphIndex that there is an unvalidated index.
2672
2714
self._missing_compression_parents.update(new_missing)
2674
2716
def get_missing_compression_parents(self):
2675
"""Return the keys of compression parents missing from unvalidated
2717
"""Return the keys of missing compression parents.
2719
Missing compression parents occur when a record stream was missing
2720
basis texts, or a index was scanned that had missing basis texts.
2678
2722
return frozenset(self._missing_compression_parents)