/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: Martin
  • Date: 2009-11-07 08:02:13 UTC
  • mfrom: (4789 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4809.
  • Revision ID: gzlist@googlemail.com-20091107080213-jad185091b3l69ih
Merge bzr.dev 4789 to resolve conflict from the disabling of plink auto-detection, and relocate NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1190
1190
        generator = _VFContentMapGenerator(self, [key])
1191
1191
        return generator._get_content(key)
1192
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
 
1193
1206
    def get_parent_map(self, keys):
1194
1207
        """Get a map of the graph parents of keys.
1195
1208
 
1505
1518
                if source is parent_maps[0]:
1506
1519
                    # this KnitVersionedFiles
1507
1520
                    records = [(key, positions[key][1]) for key in keys]
1508
 
                    for key, raw_data, sha1 in self._read_records_iter_raw(records):
 
1521
                    for key, raw_data in self._read_records_iter_unchecked(records):
1509
1522
                        (record_details, index_memo, _) = positions[key]
1510
1523
                        yield KnitContentFactory(key, global_map[key],
1511
 
                            record_details, sha1, raw_data, self._factory.annotated, None)
 
1524
                            record_details, None, raw_data, self._factory.annotated, None)
1512
1525
                else:
1513
1526
                    vf = self._fallback_vfs[parent_maps.index(source) - 1]
1514
1527
                    for record in vf.get_record_stream(keys, ordering,
1583
1596
        # key = basis_parent, value = index entry to add
1584
1597
        buffered_index_entries = {}
1585
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()
1586
1606
            buffered = False
1587
1607
            parents = record.parents
1588
1608
            if record.storage_kind in delta_types:
1690
1710
            # There were index entries buffered at the end of the stream,
1691
1711
            # So these need to be added (if the index supports holding such
1692
1712
            # entries for later insertion)
 
1713
            all_entries = []
1693
1714
            for key in buffered_index_entries:
1694
1715
                index_entries = buffered_index_entries[key]
1695
 
                self._index.add_records(index_entries,
1696
 
                    missing_compression_parents=True)
 
1716
                all_entries.extend(index_entries)
 
1717
            self._index.add_records(
 
1718
                all_entries, missing_compression_parents=True)
1697
1719
 
1698
1720
    def get_missing_compression_parent_keys(self):
1699
1721
        """Return an iterable of keys of missing compression parents.
2345
2367
    FLAGS is a comma separated list of flags about the record. Values include
2346
2368
        no-eol, line-delta, fulltext.
2347
2369
    BYTE_OFFSET is the ascii representation of the byte offset in the data file
2348
 
        that the the compressed data starts at.
 
2370
        that the compressed data starts at.
2349
2371
    LENGTH is the ascii representation of the length of the data file.
2350
2372
    PARENT_ID a utf-8 revision id prefixed by a '.' that is a parent of
2351
2373
        REVISION_ID.
2560
2582
        except KeyError:
2561
2583
            raise RevisionNotPresent(key, self)
2562
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
 
2563
2612
    def get_parent_map(self, keys):
2564
2613
        """Get a map of the parents of keys.
2565
2614
 
2737
2786
 
2738
2787
class _KeyRefs(object):
2739
2788
 
2740
 
    def __init__(self):
 
2789
    def __init__(self, track_new_keys=False):
2741
2790
        # dict mapping 'key' to 'set of keys referring to that key'
2742
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()
2743
2803
 
2744
2804
    def add_references(self, key, refs):
2745
2805
        # Record the new references
2752
2812
        # Discard references satisfied by the new key
2753
2813
        self.add_key(key)
2754
2814
 
 
2815
    def get_new_keys(self):
 
2816
        return self.new_keys
 
2817
    
2755
2818
    def get_unsatisfied_refs(self):
2756
2819
        return self.refs.iterkeys()
2757
2820
 
2758
 
    def add_key(self, key):
 
2821
    def _satisfy_refs_for_key(self, key):
2759
2822
        try:
2760
2823
            del self.refs[key]
2761
2824
        except KeyError:
2762
2825
            # No keys depended on this key.  That's ok.
2763
2826
            pass
2764
2827
 
2765
 
    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):
2766
2835
        for key in keys:
2767
 
            self.add_key(key)
 
2836
            self._satisfy_refs_for_key(key)
2768
2837
 
2769
2838
    def get_referrers(self):
2770
2839
        result = set()
2932
3001
        # If updating this, you should also update
2933
3002
        # groupcompress._GCGraphIndex.get_missing_parents
2934
3003
        # We may have false positives, so filter those out.
2935
 
        self._key_dependencies.add_keys(
 
3004
        self._key_dependencies.satisfy_refs_for_keys(
2936
3005
            self.get_parent_map(self._key_dependencies.get_unsatisfied_refs()))
2937
3006
        return frozenset(self._key_dependencies.get_unsatisfied_refs())
2938
3007
 
3049
3118
            options.append('no-eol')
3050
3119
        return options
3051
3120
 
 
3121
    def find_ancestry(self, keys):
 
3122
        """See CombinedGraphIndex.find_ancestry()"""
 
3123
        return self._graph_index.find_ancestry(keys, 0)
 
3124
 
3052
3125
    def get_parent_map(self, keys):
3053
3126
        """Get a map of the parents of keys.
3054
3127
 
3629
3702
 
3630
3703
try:
3631
3704
    from bzrlib._knit_load_data_pyx import _load_data_c as _load_data
3632
 
except ImportError:
 
3705
except ImportError, e:
 
3706
    osutils.failed_to_load_extension(e)
3633
3707
    from bzrlib._knit_load_data_py import _load_data_py as _load_data