/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: John Arbash Meinel
  • Date: 2008-03-06 09:53:33 UTC
  • mto: This revision was merged to the branch mainline in revision 3280.
  • Revision ID: john@arbash-meinel.com-20080306095333-ne8gnbxgtuc38aew
Cleanup the extra debugging info, and some >80 char lines.

Show diffs side-by-side

added added

removed removed

Lines of Context:
219
219
 
220
220
    def text(self):
221
221
        try:
222
 
            return [text for origin, text in self._lines]
 
222
            lines = [text for origin, text in self._lines]
223
223
        except ValueError, e:
224
224
            # most commonly (only?) caused by the internal form of the knit
225
225
            # missing annotation information because of a bug - see thread
228
228
                "line in annotated knit missing annotation information: %s"
229
229
                % (e,))
230
230
 
231
 
    def text_lines(self):
232
 
        """Return the official fulltext for this content.
233
 
 
234
 
        This includes stripping the final newline if it should be done.
235
 
        """
236
 
        lines = [text for o, l in self._lines]
237
231
        if self._should_strip_eol:
238
232
            anno, line = lines[-1]
239
233
            lines[-1] = (anno, line.rstrip('\n'))
278
272
        self._should_strip_eol = False
279
273
 
280
274
    def text(self):
281
 
        return self._lines
282
 
 
283
 
    def text_lines(self):
284
 
        """Return the official fulltext for this content.
285
 
 
286
 
        This includes stripping the final newline if it should be done.
287
 
        """
288
275
        lines = self._lines
289
276
        if self._should_strip_eol:
290
277
            lines = lines[:]
2859
2846
    return iter(annotator.get_annotated_lines(revision_id))
2860
2847
 
2861
2848
 
2862
 
_reused_content = 0
2863
 
_unused_content = 0
2864
 
_num_nodes = 0
2865
 
 
2866
 
 
2867
2849
class _KnitAnnotator(object):
2868
2850
    """Build up the annotations for a text."""
2869
2851
 
2895
2877
        self._heads_provider = None
2896
2878
 
2897
2879
        self._nodes_to_keep_annotations = set()
 
2880
        self._generations_until_keep = 100
 
2881
 
 
2882
    def set_generations_until_keep(self, value):
 
2883
        """Set the number of generations before caching a node.
 
2884
 
 
2885
        Setting this to -1 will cache every merge node, setting this higher
 
2886
        will cache fewer nodes.
 
2887
        """
 
2888
        self._generations_until_keep = value
2898
2889
 
2899
2890
    def _add_fulltext_content(self, revision_id, content_obj):
2900
2891
        self._fulltext_contents[revision_id] = content_obj
2901
2892
        # TODO: jam 20080305 It might be good to check the sha1digest here
2902
 
        return content_obj.text_lines()
 
2893
        return content_obj.text()
2903
2894
 
2904
2895
    def _check_parents(self, child, nodes_to_annotate):
2905
2896
        """Check if all parents have been processed.
2965
2956
        pending = set([revision_id])
2966
2957
        records = []
2967
2958
        generation = 0
2968
 
        last_generation = 0
 
2959
        kept_generation = 0
2969
2960
        while pending:
2970
2961
            # get all pending nodes
2971
2962
            generation += 1
2987
2978
                        []).append(rev_id)
2988
2979
                if parents:
2989
2980
                    for parent in parents:
2990
 
                        self._annotate_children.setdefault(parent, []).append(rev_id)
2991
 
                    if ((generation - last_generation >= 10)
 
2981
                        self._annotate_children.setdefault(parent,
 
2982
                            []).append(rev_id)
 
2983
                    num_gens = generation - kept_generation
 
2984
                    if ((num_gens >= self._generations_until_keep)
2992
2985
                        and len(parents) > 1):
2993
 
                        last_generation = generation
 
2986
                        kept_generation = generation
2994
2987
                        self._nodes_to_keep_annotations.add(rev_id)
2995
2988
 
2996
2989
            missing_versions = this_iteration.difference(build_details.keys())
3001
2994
        # Generally we will want to read the records in reverse order, because
3002
2995
        # we find the parent nodes after the children
3003
2996
        records.reverse()
3004
 
        global _num_nodes
3005
 
        _num_nodes = len(records)
3006
2997
        return records
3007
2998
 
3008
2999
    def _annotate_records(self, records):
3009
3000
        """Build the annotations for the listed records."""
3010
3001
        # We iterate in the order read, rather than a strict order requested
3011
 
        # However, process what we can, and put off to the side things that still
3012
 
        # need parents, cleaning them up when those parents are processed.
 
3002
        # However, process what we can, and put off to the side things that
 
3003
        # still need parents, cleaning them up when those parents are
 
3004
        # processed.
3013
3005
        for (rev_id, record,
3014
3006
             digest) in self._knit._data.read_records_iter(records):
3015
3007
            if rev_id in self._annotated_lines:
3049
3041
                        and compression_parent not in
3050
3042
                            self._nodes_to_keep_annotations)
3051
3043
                    if reuse_content:
3052
 
                        global _reused_content
3053
 
                        _reused_content += 1
3054
3044
                        # Remove it from the cache since it will be changing
3055
3045
                        parent_fulltext_content = self._fulltext_contents.pop(compression_parent)
3056
3046
                        # Make sure to copy the fulltext since it might be
3057
3047
                        # modified
3058
 
                        parent_fulltext = list(parent_fulltext_content.text_lines())
 
3048
                        parent_fulltext = list(parent_fulltext_content.text())
3059
3049
                    else:
3060
 
                        global _unused_content
3061
 
                        _unused_content += 1
3062
3050
                        parent_fulltext_content = self._fulltext_contents[compression_parent]
3063
 
                        parent_fulltext = parent_fulltext_content.text_lines()
 
3051
                        parent_fulltext = parent_fulltext_content.text()
3064
3052
                    comp_children.remove(rev_id)
3065
3053
                    fulltext_content, delta = self._knit.factory.parse_record(
3066
 
                        rev_id, record, record_details, parent_fulltext_content,
 
3054
                        rev_id, record, record_details,
 
3055
                        parent_fulltext_content,
3067
3056
                        copy_base_content=(not reuse_content))
3068
 
                    fulltext = self._add_fulltext_content(rev_id, fulltext_content)
 
3057
                    fulltext = self._add_fulltext_content(rev_id,
 
3058
                                                          fulltext_content)
3069
3059
                    blocks = KnitContent.get_line_delta_blocks(delta,
3070
3060
                            parent_fulltext, fulltext)
3071
3061
                else:
3096
3086
        """
3097
3087
        records = self._get_build_graph(revision_id)
3098
3088
        self._annotate_records(records)
3099
 
        trace.note('Total: %d, Reused: %d, unused: %d, num cached: %d, %d',
3100
 
                   _num_nodes,
3101
 
                   _reused_content, _unused_content,
3102
 
                   len(self._fulltext_contents),
3103
 
                   len(self._annotated_lines))
3104
3089
        return self._annotated_lines[revision_id]
3105
3090
 
3106
3091