~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/index.py

  • Committer: Andrew Bennetts
  • Date: 2010-08-17 06:45:33 UTC
  • mfrom: (5050.17.9 2.2)
  • mto: This revision was merged to the branch mainline in revision 5379.
  • Revision ID: andrew.bennetts@canonical.com-20100817064533-kof2i2f3r6mr4ayb
Merge lp:bzr/2.2 into lp:bzr, including fixes for #192859, #224373, #300062, #585667, #614404, #617503.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2011 Canonical Ltd
 
1
# Copyright (C) 2007-2010 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
31
31
 
32
32
from bzrlib.lazy_import import lazy_import
33
33
lazy_import(globals(), """
34
 
from bzrlib import (
35
 
    bisect_multi,
36
 
    revision as _mod_revision,
37
 
    trace,
38
 
    )
 
34
from bzrlib import trace
 
35
from bzrlib.bisect_multi import bisect_multi_bytes
 
36
from bzrlib.revision import NULL_REVISION
 
37
from bzrlib.trace import mutter
39
38
""")
40
39
from bzrlib import (
41
40
    debug,
70
69
class GraphIndexBuilder(object):
71
70
    """A builder that can build a GraphIndex.
72
71
 
73
 
    The resulting graph has the structure::
 
72
    The resulting graph has the structure:
74
73
 
75
 
      _SIGNATURE OPTIONS NODES NEWLINE
76
 
      _SIGNATURE     := 'Bazaar Graph Index 1' NEWLINE
77
 
      OPTIONS        := 'node_ref_lists=' DIGITS NEWLINE
78
 
      NODES          := NODE*
79
 
      NODE           := KEY NULL ABSENT? NULL REFERENCES NULL VALUE NEWLINE
80
 
      KEY            := Not-whitespace-utf8
81
 
      ABSENT         := 'a'
82
 
      REFERENCES     := REFERENCE_LIST (TAB REFERENCE_LIST){node_ref_lists - 1}
83
 
      REFERENCE_LIST := (REFERENCE (CR REFERENCE)*)?
84
 
      REFERENCE      := DIGITS  ; digits is the byte offset in the index of the
85
 
                                ; referenced key.
86
 
      VALUE          := no-newline-no-null-bytes
 
74
    _SIGNATURE OPTIONS NODES NEWLINE
 
75
    _SIGNATURE     := 'Bazaar Graph Index 1' NEWLINE
 
76
    OPTIONS        := 'node_ref_lists=' DIGITS NEWLINE
 
77
    NODES          := NODE*
 
78
    NODE           := KEY NULL ABSENT? NULL REFERENCES NULL VALUE NEWLINE
 
79
    KEY            := Not-whitespace-utf8
 
80
    ABSENT         := 'a'
 
81
    REFERENCES     := REFERENCE_LIST (TAB REFERENCE_LIST){node_ref_lists - 1}
 
82
    REFERENCE_LIST := (REFERENCE (CR REFERENCE)*)?
 
83
    REFERENCE      := DIGITS  ; digits is the byte offset in the index of the
 
84
                              ; referenced key.
 
85
    VALUE          := no-newline-no-null-bytes
87
86
    """
88
87
 
89
88
    def __init__(self, reference_lists=0, key_elements=1):
185
184
        :param value: The value associate with this key. Must not contain
186
185
            newlines or null characters.
187
186
        :return: (node_refs, absent_references)
188
 
        
189
 
            * node_refs: basically a packed form of 'references' where all
190
 
              iterables are tuples
191
 
            * absent_references: reference keys that are not in self._nodes.
192
 
              This may contain duplicates if the same key is referenced in
193
 
              multiple lists.
 
187
            node_refs   basically a packed form of 'references' where all
 
188
                        iterables are tuples
 
189
            absent_references   reference keys that are not in self._nodes.
 
190
                                This may contain duplicates if the same key is
 
191
                                referenced in multiple lists.
194
192
        """
195
193
        as_st = StaticTuple.from_sequence
196
194
        self._check_key(key)
221
219
        :param references: An iterable of iterables of keys. Each is a
222
220
            reference to another key.
223
221
        :param value: The value to associate with the key. It may be any
224
 
            bytes as long as it does not contain \\0 or \\n.
 
222
            bytes as long as it does not contain \0 or \n.
225
223
        """
226
224
        (node_refs,
227
225
         absent_references) = self._check_key_ref_value(key, references, value)
446
444
            # We already did this
447
445
            return
448
446
        if 'index' in debug.debug_flags:
449
 
            trace.mutter('Reading entire index %s',
450
 
                          self._transport.abspath(self._name))
 
447
            mutter('Reading entire index %s', self._transport.abspath(self._name))
451
448
        if stream is None:
452
449
            stream = self._transport.get(self._name)
453
450
            if self._base_offset != 0:
674
671
        if self._nodes is not None:
675
672
            return self._iter_entries_from_total_buffer(keys)
676
673
        else:
677
 
            return (result[1] for result in bisect_multi.bisect_multi_bytes(
 
674
            return (result[1] for result in bisect_multi_bytes(
678
675
                self._lookup_keys_via_location, self._size, keys))
679
676
 
680
677
    def iter_entries_prefix(self, keys):
1291
1288
    def get_parent_map(self, keys):
1292
1289
        """See graph.StackedParentsProvider.get_parent_map"""
1293
1290
        search_keys = set(keys)
1294
 
        if _mod_revision.NULL_REVISION in search_keys:
1295
 
            search_keys.discard(_mod_revision.NULL_REVISION)
1296
 
            found_parents = {_mod_revision.NULL_REVISION:[]}
 
1291
        if NULL_REVISION in search_keys:
 
1292
            search_keys.discard(NULL_REVISION)
 
1293
            found_parents = {NULL_REVISION:[]}
1297
1294
        else:
1298
1295
            found_parents = {}
1299
1296
        for index, key, value, refs in self.iter_entries(search_keys):
1300
1297
            parents = refs[0]
1301
1298
            if not parents:
1302
 
                parents = (_mod_revision.NULL_REVISION,)
 
1299
                parents = (NULL_REVISION,)
1303
1300
            found_parents[key] = parents
1304
1301
        return found_parents
1305
1302
 
1437
1434
        """
1438
1435
        indices_info = zip(self._index_names, self._indices)
1439
1436
        if 'index' in debug.debug_flags:
1440
 
            trace.mutter('CombinedGraphIndex reordering: currently %r, '
1441
 
                         'promoting %r', indices_info, hit_indices)
 
1437
            mutter('CombinedGraphIndex reordering: currently %r, promoting %r',
 
1438
                   indices_info, hit_indices)
1442
1439
        hit_names = []
1443
1440
        unhit_names = []
1444
1441
        new_hit_indices = []
1461
1458
        self._indices = new_hit_indices + unhit_indices
1462
1459
        self._index_names = hit_names + unhit_names
1463
1460
        if 'index' in debug.debug_flags:
1464
 
            trace.mutter('CombinedGraphIndex reordered: %r', self._indices)
 
1461
            mutter('CombinedGraphIndex reordered: %r', self._indices)
1465
1462
        return hit_names
1466
1463
 
1467
1464
    def _move_to_front_by_name(self, hit_names):