~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: John Arbash Meinel
  • Date: 2009-07-31 19:56:19 UTC
  • mto: This revision was merged to the branch mainline in revision 4592.
  • Revision ID: john@arbash-meinel.com-20090731195619-xabumey07q2w1fge
Change the Makefile to stage things into a build directory
rather than building inside the tree.

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,
73
72
    trace,
74
73
    tsort,
75
74
    tuned_gzip,
1046
1045
    def get_annotator(self):
1047
1046
        return _KnitAnnotator(self)
1048
1047
 
1049
 
    def check(self, progress_bar=None, keys=None):
 
1048
    def check(self, progress_bar=None):
1050
1049
        """See VersionedFiles.check()."""
1051
 
        if keys is None:
1052
 
            return self._logical_check()
1053
 
        else:
1054
 
            # At the moment, check does not extra work over get_record_stream
1055
 
            return self.get_record_stream(keys, 'unordered', True)
1056
 
 
1057
 
    def _logical_check(self):
1058
1050
        # This doesn't actually test extraction of everything, but that will
1059
1051
        # impact 'bzr check' substantially, and needs to be integrated with
1060
1052
        # care. However, it does check for the obvious problem of a delta with
1191
1183
        generator = _VFContentMapGenerator(self, [key])
1192
1184
        return generator._get_content(key)
1193
1185
 
1194
 
    def get_known_graph_ancestry(self, keys):
1195
 
        """Get a KnownGraph instance with the ancestry of keys."""
1196
 
        parent_map, missing_keys = self._index.find_ancestry(keys)
1197
 
        for fallback in self._fallback_vfs:
1198
 
            if not missing_keys:
1199
 
                break
1200
 
            (f_parent_map, f_missing_keys) = fallback._index.find_ancestry(
1201
 
                                                missing_keys)
1202
 
            parent_map.update(f_parent_map)
1203
 
            missing_keys = f_missing_keys
1204
 
        kg = _mod_graph.KnownGraph(parent_map)
1205
 
        return kg
1206
 
 
1207
1186
    def get_parent_map(self, keys):
1208
1187
        """Get a map of the graph parents of keys.
1209
1188
 
1519
1498
                if source is parent_maps[0]:
1520
1499
                    # this KnitVersionedFiles
1521
1500
                    records = [(key, positions[key][1]) for key in keys]
1522
 
                    for key, raw_data in self._read_records_iter_unchecked(records):
 
1501
                    for key, raw_data, sha1 in self._read_records_iter_raw(records):
1523
1502
                        (record_details, index_memo, _) = positions[key]
1524
1503
                        yield KnitContentFactory(key, global_map[key],
1525
 
                            record_details, None, raw_data, self._factory.annotated, None)
 
1504
                            record_details, sha1, raw_data, self._factory.annotated, None)
1526
1505
                else:
1527
1506
                    vf = self._fallback_vfs[parent_maps.index(source) - 1]
1528
1507
                    for record in vf.get_record_stream(keys, ordering,
1597
1576
        # key = basis_parent, value = index entry to add
1598
1577
        buffered_index_entries = {}
1599
1578
        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()
1607
1579
            buffered = False
1608
1580
            parents = record.parents
1609
1581
            if record.storage_kind in delta_types:
1711
1683
            # There were index entries buffered at the end of the stream,
1712
1684
            # So these need to be added (if the index supports holding such
1713
1685
            # entries for later insertion)
1714
 
            all_entries = []
1715
1686
            for key in buffered_index_entries:
1716
1687
                index_entries = buffered_index_entries[key]
1717
 
                all_entries.extend(index_entries)
1718
 
            self._index.add_records(
1719
 
                all_entries, missing_compression_parents=True)
 
1688
                self._index.add_records(index_entries,
 
1689
                    missing_compression_parents=True)
1720
1690
 
1721
1691
    def get_missing_compression_parent_keys(self):
1722
1692
        """Return an iterable of keys of missing compression parents.
2368
2338
    FLAGS is a comma separated list of flags about the record. Values include
2369
2339
        no-eol, line-delta, fulltext.
2370
2340
    BYTE_OFFSET is the ascii representation of the byte offset in the data file
2371
 
        that the compressed data starts at.
 
2341
        that the the compressed data starts at.
2372
2342
    LENGTH is the ascii representation of the length of the data file.
2373
2343
    PARENT_ID a utf-8 revision id prefixed by a '.' that is a parent of
2374
2344
        REVISION_ID.
2583
2553
        except KeyError:
2584
2554
            raise RevisionNotPresent(key, self)
2585
2555
 
2586
 
    def find_ancestry(self, keys):
2587
 
        """See CombinedGraphIndex.find_ancestry()"""
2588
 
        prefixes = set(key[:-1] for key in keys)
2589
 
        self._load_prefixes(prefixes)
2590
 
        result = {}
2591
 
        parent_map = {}
2592
 
        missing_keys = set()
2593
 
        pending_keys = list(keys)
2594
 
        # This assumes that keys will not reference parents in a different
2595
 
        # prefix, which is accurate so far.
2596
 
        while pending_keys:
2597
 
            key = pending_keys.pop()
2598
 
            if key in parent_map:
2599
 
                continue
2600
 
            prefix = key[:-1]
2601
 
            try:
2602
 
                suffix_parents = self._kndx_cache[prefix][0][key[-1]][4]
2603
 
            except KeyError:
2604
 
                missing_keys.add(key)
2605
 
            else:
2606
 
                parent_keys = tuple([prefix + (suffix,)
2607
 
                                     for suffix in suffix_parents])
2608
 
                parent_map[key] = parent_keys
2609
 
                pending_keys.extend([p for p in parent_keys
2610
 
                                        if p not in parent_map])
2611
 
        return parent_map, missing_keys
2612
 
 
2613
2556
    def get_parent_map(self, keys):
2614
2557
        """Get a map of the parents of keys.
2615
2558
 
2787
2730
 
2788
2731
class _KeyRefs(object):
2789
2732
 
2790
 
    def __init__(self, track_new_keys=False):
 
2733
    def __init__(self):
2791
2734
        # dict mapping 'key' to 'set of keys referring to that key'
2792
2735
        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()
2804
2736
 
2805
2737
    def add_references(self, key, refs):
2806
2738
        # Record the new references
2813
2745
        # Discard references satisfied by the new key
2814
2746
        self.add_key(key)
2815
2747
 
2816
 
    def get_new_keys(self):
2817
 
        return self.new_keys
2818
 
    
2819
2748
    def get_unsatisfied_refs(self):
2820
2749
        return self.refs.iterkeys()
2821
2750
 
2822
 
    def _satisfy_refs_for_key(self, key):
 
2751
    def add_key(self, key):
2823
2752
        try:
2824
2753
            del self.refs[key]
2825
2754
        except KeyError:
2826
2755
            # No keys depended on this key.  That's ok.
2827
2756
            pass
2828
2757
 
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):
 
2758
    def add_keys(self, keys):
2836
2759
        for key in keys:
2837
 
            self._satisfy_refs_for_key(key)
 
2760
            self.add_key(key)
2838
2761
 
2839
2762
    def get_referrers(self):
2840
2763
        result = set()
2945
2868
        if not random_id:
2946
2869
            present_nodes = self._get_entries(keys)
2947
2870
            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]
2952
2871
                if (value[0] != keys[key][0][0] or
2953
 
                    parents != passed_parents):
2954
 
                    node_refs = static_tuple.as_tuples(node_refs)
 
2872
                    node_refs[:1] != keys[key][1][:1]):
2955
2873
                    raise KnitCorrupt(self, "inconsistent details in add_records"
2956
 
                        ": %s %s" % ((value, node_refs), passed))
 
2874
                        ": %s %s" % ((value, node_refs), keys[key]))
2957
2875
                del keys[key]
2958
2876
        result = []
2959
2877
        if self._parents:
3007
2925
        # If updating this, you should also update
3008
2926
        # groupcompress._GCGraphIndex.get_missing_parents
3009
2927
        # We may have false positives, so filter those out.
3010
 
        self._key_dependencies.satisfy_refs_for_keys(
 
2928
        self._key_dependencies.add_keys(
3011
2929
            self.get_parent_map(self._key_dependencies.get_unsatisfied_refs()))
3012
2930
        return frozenset(self._key_dependencies.get_unsatisfied_refs())
3013
2931
 
3124
3042
            options.append('no-eol')
3125
3043
        return options
3126
3044
 
3127
 
    def find_ancestry(self, keys):
3128
 
        """See CombinedGraphIndex.find_ancestry()"""
3129
 
        return self._graph_index.find_ancestry(keys, 0)
3130
 
 
3131
3045
    def get_parent_map(self, keys):
3132
3046
        """Get a map of the parents of keys.
3133
3047
 
3708
3622
 
3709
3623
try:
3710
3624
    from bzrlib._knit_load_data_pyx import _load_data_c as _load_data
3711
 
except ImportError, e:
3712
 
    osutils.failed_to_load_extension(e)
 
3625
except ImportError:
3713
3626
    from bzrlib._knit_load_data_py import _load_data_py as _load_data