~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: John Arbash Meinel
  • Date: 2010-01-13 16:23:07 UTC
  • mto: (4634.119.7 2.0)
  • mto: This revision was merged to the branch mainline in revision 4959.
  • Revision ID: john@arbash-meinel.com-20100113162307-0bs82td16gzih827
Update the MANIFEST.in file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1045
1045
    def get_annotator(self):
1046
1046
        return _KnitAnnotator(self)
1047
1047
 
1048
 
    def check(self, progress_bar=None):
 
1048
    def check(self, progress_bar=None, keys=None):
1049
1049
        """See VersionedFiles.check()."""
 
1050
        if keys is None:
 
1051
            return self._logical_check()
 
1052
        else:
 
1053
            # At the moment, check does not extra work over get_record_stream
 
1054
            return self.get_record_stream(keys, 'unordered', True)
 
1055
 
 
1056
    def _logical_check(self):
1050
1057
        # This doesn't actually test extraction of everything, but that will
1051
1058
        # impact 'bzr check' substantially, and needs to be integrated with
1052
1059
        # care. However, it does check for the obvious problem of a delta with
1183
1190
        generator = _VFContentMapGenerator(self, [key])
1184
1191
        return generator._get_content(key)
1185
1192
 
 
1193
    def get_known_graph_ancestry(self, keys):
 
1194
        """Get a KnownGraph instance with the ancestry of keys."""
 
1195
        parent_map, missing_keys = self._index.find_ancestry(keys)
 
1196
        for fallback in self._fallback_vfs:
 
1197
            if not missing_keys:
 
1198
                break
 
1199
            (f_parent_map, f_missing_keys) = fallback._index.find_ancestry(
 
1200
                                                missing_keys)
 
1201
            parent_map.update(f_parent_map)
 
1202
            missing_keys = f_missing_keys
 
1203
        kg = _mod_graph.KnownGraph(parent_map)
 
1204
        return kg
 
1205
 
1186
1206
    def get_parent_map(self, keys):
1187
1207
        """Get a map of the graph parents of keys.
1188
1208
 
1489
1509
                                                                non_local_keys,
1490
1510
                                                                positions):
1491
1511
                generator = _VFContentMapGenerator(self, keys, non_local_keys,
1492
 
                                                   global_map)
 
1512
                                                   global_map,
 
1513
                                                   ordering=ordering)
1493
1514
                for record in generator.get_record_stream():
1494
1515
                    yield record
1495
1516
        else:
1497
1518
                if source is parent_maps[0]:
1498
1519
                    # this KnitVersionedFiles
1499
1520
                    records = [(key, positions[key][1]) for key in keys]
1500
 
                    for key, raw_data, sha1 in self._read_records_iter_raw(records):
 
1521
                    for key, raw_data in self._read_records_iter_unchecked(records):
1501
1522
                        (record_details, index_memo, _) = positions[key]
1502
1523
                        yield KnitContentFactory(key, global_map[key],
1503
 
                            record_details, sha1, raw_data, self._factory.annotated, None)
 
1524
                            record_details, None, raw_data, self._factory.annotated, None)
1504
1525
                else:
1505
1526
                    vf = self._fallback_vfs[parent_maps.index(source) - 1]
1506
1527
                    for record in vf.get_record_stream(keys, ordering,
1575
1596
        # key = basis_parent, value = index entry to add
1576
1597
        buffered_index_entries = {}
1577
1598
        for record in stream:
 
1599
            kind = record.storage_kind
 
1600
            if kind.startswith('knit-') and kind.endswith('-gz'):
 
1601
                # Check that the ID in the header of the raw knit bytes matches
 
1602
                # the record metadata.
 
1603
                raw_data = record._raw_record
 
1604
                df, rec = self._parse_record_header(record.key, raw_data)
 
1605
                df.close()
1578
1606
            buffered = False
1579
1607
            parents = record.parents
1580
1608
            if record.storage_kind in delta_types:
1682
1710
            # There were index entries buffered at the end of the stream,
1683
1711
            # So these need to be added (if the index supports holding such
1684
1712
            # entries for later insertion)
 
1713
            all_entries = []
1685
1714
            for key in buffered_index_entries:
1686
1715
                index_entries = buffered_index_entries[key]
1687
 
                self._index.add_records(index_entries,
1688
 
                    missing_compression_parents=True)
 
1716
                all_entries.extend(index_entries)
 
1717
            self._index.add_records(
 
1718
                all_entries, missing_compression_parents=True)
1689
1719
 
1690
1720
    def get_missing_compression_parent_keys(self):
1691
1721
        """Return an iterable of keys of missing compression parents.
1993
2023
class _ContentMapGenerator(object):
1994
2024
    """Generate texts or expose raw deltas for a set of texts."""
1995
2025
 
 
2026
    def __init__(self, ordering='unordered'):
 
2027
        self._ordering = ordering
 
2028
 
1996
2029
    def _get_content(self, key):
1997
2030
        """Get the content object for key."""
1998
2031
        # Note that _get_content is only called when the _ContentMapGenerator
2032
2065
            # Loop over fallback repositories asking them for texts - ignore
2033
2066
            # any missing from a particular fallback.
2034
2067
            for record in source.get_record_stream(missing_keys,
2035
 
                'unordered', True):
 
2068
                self._ordering, True):
2036
2069
                if record.storage_kind == 'absent':
2037
2070
                    # Not in thie particular stream, may be in one of the
2038
2071
                    # other fallback vfs objects.
2170
2203
    """Content map generator reading from a VersionedFiles object."""
2171
2204
 
2172
2205
    def __init__(self, versioned_files, keys, nonlocal_keys=None,
2173
 
        global_map=None, raw_record_map=None):
 
2206
        global_map=None, raw_record_map=None, ordering='unordered'):
2174
2207
        """Create a _ContentMapGenerator.
2175
2208
 
2176
2209
        :param versioned_files: The versioned files that the texts are being
2184
2217
        :param raw_record_map: A unparsed raw record map to use for answering
2185
2218
            contents.
2186
2219
        """
 
2220
        _ContentMapGenerator.__init__(self, ordering=ordering)
2187
2221
        # The vf to source data from
2188
2222
        self.vf = versioned_files
2189
2223
        # The keys desired
2548
2582
        except KeyError:
2549
2583
            raise RevisionNotPresent(key, self)
2550
2584
 
 
2585
    def find_ancestry(self, keys):
 
2586
        """See CombinedGraphIndex.find_ancestry()"""
 
2587
        prefixes = set(key[:-1] for key in keys)
 
2588
        self._load_prefixes(prefixes)
 
2589
        result = {}
 
2590
        parent_map = {}
 
2591
        missing_keys = set()
 
2592
        pending_keys = list(keys)
 
2593
        # This assumes that keys will not reference parents in a different
 
2594
        # prefix, which is accurate so far.
 
2595
        while pending_keys:
 
2596
            key = pending_keys.pop()
 
2597
            if key in parent_map:
 
2598
                continue
 
2599
            prefix = key[:-1]
 
2600
            try:
 
2601
                suffix_parents = self._kndx_cache[prefix][0][key[-1]][4]
 
2602
            except KeyError:
 
2603
                missing_keys.add(key)
 
2604
            else:
 
2605
                parent_keys = tuple([prefix + (suffix,)
 
2606
                                     for suffix in suffix_parents])
 
2607
                parent_map[key] = parent_keys
 
2608
                pending_keys.extend([p for p in parent_keys
 
2609
                                        if p not in parent_map])
 
2610
        return parent_map, missing_keys
 
2611
 
2551
2612
    def get_parent_map(self, keys):
2552
2613
        """Get a map of the parents of keys.
2553
2614
 
2725
2786
 
2726
2787
class _KeyRefs(object):
2727
2788
 
2728
 
    def __init__(self):
 
2789
    def __init__(self, track_new_keys=False):
2729
2790
        # dict mapping 'key' to 'set of keys referring to that key'
2730
2791
        self.refs = {}
 
2792
        if track_new_keys:
 
2793
            # set remembering all new keys
 
2794
            self.new_keys = set()
 
2795
        else:
 
2796
            self.new_keys = None
 
2797
 
 
2798
    def clear(self):
 
2799
        if self.refs:
 
2800
            self.refs.clear()
 
2801
        if self.new_keys:
 
2802
            self.new_keys.clear()
2731
2803
 
2732
2804
    def add_references(self, key, refs):
2733
2805
        # Record the new references
2740
2812
        # Discard references satisfied by the new key
2741
2813
        self.add_key(key)
2742
2814
 
 
2815
    def get_new_keys(self):
 
2816
        return self.new_keys
 
2817
    
2743
2818
    def get_unsatisfied_refs(self):
2744
2819
        return self.refs.iterkeys()
2745
2820
 
2746
 
    def add_key(self, key):
 
2821
    def _satisfy_refs_for_key(self, key):
2747
2822
        try:
2748
2823
            del self.refs[key]
2749
2824
        except KeyError:
2750
2825
            # No keys depended on this key.  That's ok.
2751
2826
            pass
2752
2827
 
2753
 
    def add_keys(self, keys):
 
2828
    def add_key(self, key):
 
2829
        # satisfy refs for key, and remember that we've seen this key.
 
2830
        self._satisfy_refs_for_key(key)
 
2831
        if self.new_keys is not None:
 
2832
            self.new_keys.add(key)
 
2833
 
 
2834
    def satisfy_refs_for_keys(self, keys):
2754
2835
        for key in keys:
2755
 
            self.add_key(key)
 
2836
            self._satisfy_refs_for_key(key)
2756
2837
 
2757
2838
    def get_referrers(self):
2758
2839
        result = set()
2920
3001
        # If updating this, you should also update
2921
3002
        # groupcompress._GCGraphIndex.get_missing_parents
2922
3003
        # We may have false positives, so filter those out.
2923
 
        self._key_dependencies.add_keys(
 
3004
        self._key_dependencies.satisfy_refs_for_keys(
2924
3005
            self.get_parent_map(self._key_dependencies.get_unsatisfied_refs()))
2925
3006
        return frozenset(self._key_dependencies.get_unsatisfied_refs())
2926
3007
 
3037
3118
            options.append('no-eol')
3038
3119
        return options
3039
3120
 
 
3121
    def find_ancestry(self, keys):
 
3122
        """See CombinedGraphIndex.find_ancestry()"""
 
3123
        return self._graph_index.find_ancestry(keys, 0)
 
3124
 
3040
3125
    def get_parent_map(self, keys):
3041
3126
        """Get a map of the parents of keys.
3042
3127
 
3616
3701
                    to_process.extend(self._process_pending(key))
3617
3702
 
3618
3703
try:
3619
 
    from bzrlib._knit_load_data_c import _load_data_c as _load_data
 
3704
    from bzrlib._knit_load_data_pyx import _load_data_c as _load_data
3620
3705
except ImportError:
3621
3706
    from bzrlib._knit_load_data_py import _load_data_py as _load_data