~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: Gordon Tyler
  • Date: 2010-01-14 15:24:04 UTC
  • mto: (5037.3.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5046.
  • Revision ID: gordon@doxxx.net-20100114152404-d64ik2afl96lcml0
Reverted changes to test_rules since the original should work now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
    lru_cache,
70
70
    pack,
71
71
    progress,
 
72
    static_tuple,
72
73
    trace,
73
74
    tsort,
74
75
    tuned_gzip,
1518
1519
                if source is parent_maps[0]:
1519
1520
                    # this KnitVersionedFiles
1520
1521
                    records = [(key, positions[key][1]) for key in keys]
1521
 
                    for key, raw_data, sha1 in self._read_records_iter_raw(records):
 
1522
                    for key, raw_data in self._read_records_iter_unchecked(records):
1522
1523
                        (record_details, index_memo, _) = positions[key]
1523
1524
                        yield KnitContentFactory(key, global_map[key],
1524
 
                            record_details, sha1, raw_data, self._factory.annotated, None)
 
1525
                            record_details, None, raw_data, self._factory.annotated, None)
1525
1526
                else:
1526
1527
                    vf = self._fallback_vfs[parent_maps.index(source) - 1]
1527
1528
                    for record in vf.get_record_stream(keys, ordering,
1596
1597
        # key = basis_parent, value = index entry to add
1597
1598
        buffered_index_entries = {}
1598
1599
        for record in stream:
 
1600
            kind = record.storage_kind
 
1601
            if kind.startswith('knit-') and kind.endswith('-gz'):
 
1602
                # Check that the ID in the header of the raw knit bytes matches
 
1603
                # the record metadata.
 
1604
                raw_data = record._raw_record
 
1605
                df, rec = self._parse_record_header(record.key, raw_data)
 
1606
                df.close()
1599
1607
            buffered = False
1600
1608
            parents = record.parents
1601
1609
            if record.storage_kind in delta_types:
1703
1711
            # There were index entries buffered at the end of the stream,
1704
1712
            # So these need to be added (if the index supports holding such
1705
1713
            # entries for later insertion)
 
1714
            all_entries = []
1706
1715
            for key in buffered_index_entries:
1707
1716
                index_entries = buffered_index_entries[key]
1708
 
                self._index.add_records(index_entries,
1709
 
                    missing_compression_parents=True)
 
1717
                all_entries.extend(index_entries)
 
1718
            self._index.add_records(
 
1719
                all_entries, missing_compression_parents=True)
1710
1720
 
1711
1721
    def get_missing_compression_parent_keys(self):
1712
1722
        """Return an iterable of keys of missing compression parents.
2358
2368
    FLAGS is a comma separated list of flags about the record. Values include
2359
2369
        no-eol, line-delta, fulltext.
2360
2370
    BYTE_OFFSET is the ascii representation of the byte offset in the data file
2361
 
        that the the compressed data starts at.
 
2371
        that the compressed data starts at.
2362
2372
    LENGTH is the ascii representation of the length of the data file.
2363
2373
    PARENT_ID a utf-8 revision id prefixed by a '.' that is a parent of
2364
2374
        REVISION_ID.
2777
2787
 
2778
2788
class _KeyRefs(object):
2779
2789
 
2780
 
    def __init__(self):
 
2790
    def __init__(self, track_new_keys=False):
2781
2791
        # dict mapping 'key' to 'set of keys referring to that key'
2782
2792
        self.refs = {}
 
2793
        if track_new_keys:
 
2794
            # set remembering all new keys
 
2795
            self.new_keys = set()
 
2796
        else:
 
2797
            self.new_keys = None
 
2798
 
 
2799
    def clear(self):
 
2800
        if self.refs:
 
2801
            self.refs.clear()
 
2802
        if self.new_keys:
 
2803
            self.new_keys.clear()
2783
2804
 
2784
2805
    def add_references(self, key, refs):
2785
2806
        # Record the new references
2792
2813
        # Discard references satisfied by the new key
2793
2814
        self.add_key(key)
2794
2815
 
 
2816
    def get_new_keys(self):
 
2817
        return self.new_keys
 
2818
    
2795
2819
    def get_unsatisfied_refs(self):
2796
2820
        return self.refs.iterkeys()
2797
2821
 
2798
 
    def add_key(self, key):
 
2822
    def _satisfy_refs_for_key(self, key):
2799
2823
        try:
2800
2824
            del self.refs[key]
2801
2825
        except KeyError:
2802
2826
            # No keys depended on this key.  That's ok.
2803
2827
            pass
2804
2828
 
2805
 
    def add_keys(self, keys):
 
2829
    def add_key(self, key):
 
2830
        # satisfy refs for key, and remember that we've seen this key.
 
2831
        self._satisfy_refs_for_key(key)
 
2832
        if self.new_keys is not None:
 
2833
            self.new_keys.add(key)
 
2834
 
 
2835
    def satisfy_refs_for_keys(self, keys):
2806
2836
        for key in keys:
2807
 
            self.add_key(key)
 
2837
            self._satisfy_refs_for_key(key)
2808
2838
 
2809
2839
    def get_referrers(self):
2810
2840
        result = set()
2915
2945
        if not random_id:
2916
2946
            present_nodes = self._get_entries(keys)
2917
2947
            for (index, key, value, node_refs) in present_nodes:
 
2948
                parents = node_refs[:1]
 
2949
                # Sometimes these are passed as a list rather than a tuple
 
2950
                passed = static_tuple.as_tuples(keys[key])
 
2951
                passed_parents = passed[1][:1]
2918
2952
                if (value[0] != keys[key][0][0] or
2919
 
                    node_refs[:1] != keys[key][1][:1]):
 
2953
                    parents != passed_parents):
 
2954
                    node_refs = static_tuple.as_tuples(node_refs)
2920
2955
                    raise KnitCorrupt(self, "inconsistent details in add_records"
2921
 
                        ": %s %s" % ((value, node_refs), keys[key]))
 
2956
                        ": %s %s" % ((value, node_refs), passed))
2922
2957
                del keys[key]
2923
2958
        result = []
2924
2959
        if self._parents:
2972
3007
        # If updating this, you should also update
2973
3008
        # groupcompress._GCGraphIndex.get_missing_parents
2974
3009
        # We may have false positives, so filter those out.
2975
 
        self._key_dependencies.add_keys(
 
3010
        self._key_dependencies.satisfy_refs_for_keys(
2976
3011
            self.get_parent_map(self._key_dependencies.get_unsatisfied_refs()))
2977
3012
        return frozenset(self._key_dependencies.get_unsatisfied_refs())
2978
3013
 
3673
3708
 
3674
3709
try:
3675
3710
    from bzrlib._knit_load_data_pyx import _load_data_c as _load_data
3676
 
except ImportError:
 
3711
except ImportError, e:
 
3712
    osutils.failed_to_load_extension(e)
3677
3713
    from bzrlib._knit_load_data_py import _load_data_py as _load_data