~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_btree_serializer_py.py

  • Committer: Patch Queue Manager
  • Date: 2014-02-12 18:22:22 UTC
  • mfrom: (6589.2.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20140212182222-beouo25gaf1cny76
(vila) The XDG Base Directory Specification uses the XDG_CACHE_HOME,
 not XDG_CACHE_DIR. (Andrew Starr-Bochicchio)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008 Canonical Ltd
 
1
# Copyright (C) 2008, 2009, 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
17
17
 
18
18
"""B+Tree index parsing."""
19
19
 
 
20
from __future__ import absolute_import
 
21
 
 
22
from bzrlib import static_tuple
 
23
 
 
24
 
20
25
def _parse_leaf_lines(bytes, key_length, ref_list_length):
21
26
    lines = bytes.split('\n')
22
27
    nodes = []
 
28
    as_st = static_tuple.StaticTuple.from_sequence
 
29
    stuple = static_tuple.StaticTuple
23
30
    for line in lines[1:]:
24
31
        if line == '':
25
32
            return nodes
26
33
        elements = line.split('\0', key_length)
27
34
        # keys are tuples
28
 
        key = tuple(elements[:key_length])
 
35
        key = as_st(elements[:key_length]).intern()
29
36
        line = elements[-1]
30
37
        references, value = line.rsplit('\0', 1)
31
38
        if ref_list_length:
32
39
            ref_lists = []
33
40
            for ref_string in references.split('\t'):
34
 
                ref_lists.append(tuple([
35
 
                    tuple(ref.split('\0')) for ref in ref_string.split('\r') if ref
36
 
                    ]))
37
 
            ref_lists = tuple(ref_lists)
38
 
            node_value = (value, ref_lists)
 
41
                ref_list = as_st([as_st(ref.split('\0')).intern()
 
42
                                  for ref in ref_string.split('\r') if ref])
 
43
                ref_lists.append(ref_list)
 
44
            ref_lists = as_st(ref_lists)
 
45
            node_value = stuple(value, ref_lists)
39
46
        else:
40
 
            node_value = (value, ())
 
47
            node_value = stuple(value, stuple())
 
48
        # No need for StaticTuple here as it is put into a dict
41
49
        nodes.append((key, node_value))
42
50
    return nodes
43
51