~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-04-18 04:55:00 UTC
  • mfrom: (5784.2.1 754188-apport-test)
  • Revision ID: pqm@pqm.ubuntu.com-20110418045500-ce6lkgyiq7f47q43
(mbp) Rewrite test_report_bug_legacy away from using doctest (see bug
 764188) (Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
56
56
from itertools import izip
57
57
import operator
58
58
import os
59
 
import sys
60
59
 
61
60
from bzrlib.lazy_import import lazy_import
62
61
lazy_import(globals(), """
 
62
import gzip
 
63
 
63
64
from bzrlib import (
64
 
    annotate,
65
65
    debug,
66
66
    diff,
67
67
    graph as _mod_graph,
68
68
    index as _mod_index,
69
 
    lru_cache,
70
69
    pack,
71
70
    patiencediff,
72
 
    progress,
73
71
    static_tuple,
74
72
    trace,
75
73
    tsort,
76
74
    tuned_gzip,
77
75
    ui,
78
76
    )
 
77
 
 
78
from bzrlib.repofmt import pack_repo
79
79
""")
80
80
from bzrlib import (
 
81
    annotate,
81
82
    errors,
82
83
    osutils,
83
84
    )
84
85
from bzrlib.errors import (
85
 
    FileExists,
86
86
    NoSuchFile,
87
 
    KnitError,
88
87
    InvalidRevisionId,
89
88
    KnitCorrupt,
90
89
    KnitHeaderError,
91
90
    RevisionNotPresent,
92
 
    RevisionAlreadyPresent,
93
91
    SHA1KnitCorrupt,
94
92
    )
95
93
from bzrlib.osutils import (
96
94
    contains_whitespace,
97
 
    contains_linebreaks,
98
95
    sha_string,
99
96
    sha_strings,
100
97
    split_lines,
104
101
    adapter_registry,
105
102
    ConstantMapper,
106
103
    ContentFactory,
107
 
    ChunkedContentFactory,
108
104
    sort_groupcompress,
109
 
    VersionedFile,
110
105
    VersionedFiles,
111
106
    )
112
107
 
805
800
        writer.begin()
806
801
        index = _KnitGraphIndex(graph_index, lambda:True, parents=parents,
807
802
            deltas=delta, add_callback=graph_index.add_nodes)
808
 
        access = _DirectPackAccess({})
 
803
        access = pack_repo._DirectPackAccess({})
809
804
        access.set_writer(writer, graph_index, (transport, 'newpack'))
810
805
        result = KnitVersionedFiles(index, access,
811
806
            max_delta_chain=max_delta_chain)
882
877
            self._factory = KnitAnnotateFactory()
883
878
        else:
884
879
            self._factory = KnitPlainFactory()
885
 
        self._fallback_vfs = []
 
880
        self._immediate_fallback_vfs = []
886
881
        self._reload_func = reload_func
887
882
 
888
883
    def __repr__(self):
896
891
 
897
892
        :param a_versioned_files: A VersionedFiles object.
898
893
        """
899
 
        self._fallback_vfs.append(a_versioned_files)
 
894
        self._immediate_fallback_vfs.append(a_versioned_files)
900
895
 
901
896
    def add_lines(self, key, parents, lines, parent_texts=None,
902
897
        left_matching_blocks=None, nostore_sha=None, random_id=False,
1069
1064
                    raise errors.KnitCorrupt(self,
1070
1065
                        "Missing basis parent %s for %s" % (
1071
1066
                        compression_parent, key))
1072
 
        for fallback_vfs in self._fallback_vfs:
 
1067
        for fallback_vfs in self._immediate_fallback_vfs:
1073
1068
            fallback_vfs.check()
1074
1069
 
1075
1070
    def _check_add(self, key, lines, random_id, check_content):
1195
1190
    def get_known_graph_ancestry(self, keys):
1196
1191
        """Get a KnownGraph instance with the ancestry of keys."""
1197
1192
        parent_map, missing_keys = self._index.find_ancestry(keys)
1198
 
        for fallback in self._fallback_vfs:
 
1193
        for fallback in self._transitive_fallbacks():
1199
1194
            if not missing_keys:
1200
1195
                break
1201
1196
            (f_parent_map, f_missing_keys) = fallback._index.find_ancestry(
1225
1220
            and so on.
1226
1221
        """
1227
1222
        result = {}
1228
 
        sources = [self._index] + self._fallback_vfs
 
1223
        sources = [self._index] + self._immediate_fallback_vfs
1229
1224
        source_results = []
1230
1225
        missing = set(keys)
1231
1226
        for source in sources:
1525
1520
                        yield KnitContentFactory(key, global_map[key],
1526
1521
                            record_details, None, raw_data, self._factory.annotated, None)
1527
1522
                else:
1528
 
                    vf = self._fallback_vfs[parent_maps.index(source) - 1]
 
1523
                    vf = self._immediate_fallback_vfs[parent_maps.index(source) - 1]
1529
1524
                    for record in vf.get_record_stream(keys, ordering,
1530
1525
                        include_delta_closure):
1531
1526
                        yield record
1541
1536
            # record entry 2 is the 'digest'.
1542
1537
            result[key] = details[2]
1543
1538
        missing.difference_update(set(result))
1544
 
        for source in self._fallback_vfs:
 
1539
        for source in self._immediate_fallback_vfs:
1545
1540
            if not missing:
1546
1541
                break
1547
1542
            new_result = source.get_sha1s(missing)
1618
1613
                raise RevisionNotPresent([record.key], self)
1619
1614
            elif ((record.storage_kind in knit_types)
1620
1615
                  and (compression_parent is None
1621
 
                       or not self._fallback_vfs
 
1616
                       or not self._immediate_fallback_vfs
1622
1617
                       or self._index.has_key(compression_parent)
1623
1618
                       or not self.has_key(compression_parent))):
1624
1619
                # we can insert the knit record literally if either it has no
1796
1791
        # vfs, and hope to find them there.  Note that if the keys are found
1797
1792
        # but had no changes or no content, the fallback may not return
1798
1793
        # anything.
1799
 
        if keys and not self._fallback_vfs:
 
1794
        if keys and not self._immediate_fallback_vfs:
1800
1795
            # XXX: strictly the second parameter is meant to be the file id
1801
1796
            # but it's not easily accessible here.
1802
1797
            raise RevisionNotPresent(keys, repr(self))
1803
 
        for source in self._fallback_vfs:
 
1798
        for source in self._immediate_fallback_vfs:
1804
1799
            if not keys:
1805
1800
                break
1806
1801
            source_keys = set()
1879
1874
        :return: the header and the decompressor stream.
1880
1875
                 as (stream, header_record)
1881
1876
        """
1882
 
        df = tuned_gzip.GzipFile(mode='rb', fileobj=StringIO(raw_data))
 
1877
        df = gzip.GzipFile(mode='rb', fileobj=StringIO(raw_data))
1883
1878
        try:
1884
1879
            # Current serialise
1885
1880
            rec = self._check_header(key, df.readline())
1894
1889
        # 4168 calls in 2880 217 internal
1895
1890
        # 4168 calls to _parse_record_header in 2121
1896
1891
        # 4168 calls to readlines in 330
1897
 
        df = tuned_gzip.GzipFile(mode='rb', fileobj=StringIO(data))
 
1892
        df = gzip.GzipFile(mode='rb', fileobj=StringIO(data))
1898
1893
        try:
1899
1894
            record_contents = df.readlines()
1900
1895
        except Exception, e:
2015
2010
        """See VersionedFiles.keys."""
2016
2011
        if 'evil' in debug.debug_flags:
2017
2012
            trace.mutter_callsite(2, "keys scales with size of history")
2018
 
        sources = [self._index] + self._fallback_vfs
 
2013
        sources = [self._index] + self._immediate_fallback_vfs
2019
2014
        result = set()
2020
2015
        for source in sources:
2021
2016
            result.update(source.keys())
2061
2056
 
2062
2057
        missing_keys = set(nonlocal_keys)
2063
2058
        # Read from remote versioned file instances and provide to our caller.
2064
 
        for source in self.vf._fallback_vfs:
 
2059
        for source in self.vf._immediate_fallback_vfs:
2065
2060
            if not missing_keys:
2066
2061
                break
2067
2062
            # Loop over fallback repositories asking them for texts - ignore
3520
3515
        return records, ann_keys
3521
3516
 
3522
3517
    def _get_needed_texts(self, key, pb=None):
3523
 
        # if True or len(self._vf._fallback_vfs) > 0:
3524
 
        if len(self._vf._fallback_vfs) > 0:
 
3518
        # if True or len(self._vf._immediate_fallback_vfs) > 0:
 
3519
        if len(self._vf._immediate_fallback_vfs) > 0:
3525
3520
            # If we have fallbacks, go to the generic path
3526
3521
            for v in annotate.Annotator._get_needed_texts(self, key, pb=pb):
3527
3522
                yield v