~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/index.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-05-19 10:51:37 UTC
  • mfrom: (5891.1.3 api-docs)
  • Revision ID: pqm@pqm.ubuntu.com-20110519105137-amzagrral2ldm1lq
(spiv) Fix the formatting of more docstrings. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007-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
31
31
 
32
32
from bzrlib.lazy_import import lazy_import
33
33
lazy_import(globals(), """
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
 
34
from bzrlib import (
 
35
    bisect_multi,
 
36
    revision as _mod_revision,
 
37
    trace,
 
38
    )
38
39
""")
39
40
from bzrlib import (
40
41
    debug,
69
70
class GraphIndexBuilder(object):
70
71
    """A builder that can build a GraphIndex.
71
72
 
72
 
    The resulting graph has the structure:
 
73
    The resulting graph has the structure::
73
74
 
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
 
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
86
87
    """
87
88
 
88
89
    def __init__(self, reference_lists=0, key_elements=1):
184
185
        :param value: The value associate with this key. Must not contain
185
186
            newlines or null characters.
186
187
        :return: (node_refs, absent_references)
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.
 
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.
192
194
        """
193
195
        as_st = StaticTuple.from_sequence
194
196
        self._check_key(key)
219
221
        :param references: An iterable of iterables of keys. Each is a
220
222
            reference to another key.
221
223
        :param value: The value to associate with the key. It may be any
222
 
            bytes as long as it does not contain \0 or \n.
 
224
            bytes as long as it does not contain \\0 or \\n.
223
225
        """
224
226
        (node_refs,
225
227
         absent_references) = self._check_key_ref_value(key, references, value)
444
446
            # We already did this
445
447
            return
446
448
        if 'index' in debug.debug_flags:
447
 
            mutter('Reading entire index %s', self._transport.abspath(self._name))
 
449
            trace.mutter('Reading entire index %s',
 
450
                          self._transport.abspath(self._name))
448
451
        if stream is None:
449
452
            stream = self._transport.get(self._name)
450
453
            if self._base_offset != 0:
462
465
        trailers = 0
463
466
        pos = stream.tell()
464
467
        lines = stream.read().split('\n')
 
468
        # GZ 2009-09-20: Should really use a try/finally block to ensure close
465
469
        stream.close()
466
470
        del lines[-1]
467
471
        _, _, _, trailers = self._parse_lines(lines, pos)
670
674
        if self._nodes is not None:
671
675
            return self._iter_entries_from_total_buffer(keys)
672
676
        else:
673
 
            return (result[1] for result in bisect_multi_bytes(
 
677
            return (result[1] for result in bisect_multi.bisect_multi_bytes(
674
678
                self._lookup_keys_via_location, self._size, keys))
675
679
 
676
680
    def iter_entries_prefix(self, keys):
1287
1291
    def get_parent_map(self, keys):
1288
1292
        """See graph.StackedParentsProvider.get_parent_map"""
1289
1293
        search_keys = set(keys)
1290
 
        if NULL_REVISION in search_keys:
1291
 
            search_keys.discard(NULL_REVISION)
1292
 
            found_parents = {NULL_REVISION:[]}
 
1294
        if _mod_revision.NULL_REVISION in search_keys:
 
1295
            search_keys.discard(_mod_revision.NULL_REVISION)
 
1296
            found_parents = {_mod_revision.NULL_REVISION:[]}
1293
1297
        else:
1294
1298
            found_parents = {}
1295
1299
        for index, key, value, refs in self.iter_entries(search_keys):
1296
1300
            parents = refs[0]
1297
1301
            if not parents:
1298
 
                parents = (NULL_REVISION,)
 
1302
                parents = (_mod_revision.NULL_REVISION,)
1299
1303
            found_parents[key] = parents
1300
1304
        return found_parents
1301
1305
 
1433
1437
        """
1434
1438
        indices_info = zip(self._index_names, self._indices)
1435
1439
        if 'index' in debug.debug_flags:
1436
 
            mutter('CombinedGraphIndex reordering: currently %r, promoting %r',
1437
 
                   indices_info, hit_indices)
 
1440
            trace.mutter('CombinedGraphIndex reordering: currently %r, '
 
1441
                         'promoting %r', indices_info, hit_indices)
1438
1442
        hit_names = []
1439
1443
        unhit_names = []
1440
1444
        new_hit_indices = []
1457
1461
        self._indices = new_hit_indices + unhit_indices
1458
1462
        self._index_names = hit_names + unhit_names
1459
1463
        if 'index' in debug.debug_flags:
1460
 
            mutter('CombinedGraphIndex reordered: %r', self._indices)
 
1464
            trace.mutter('CombinedGraphIndex reordered: %r', self._indices)
1461
1465
        return hit_names
1462
1466
 
1463
1467
    def _move_to_front_by_name(self, hit_names):