/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/btree_index.py

  • Committer: Aaron Bentley
  • Date: 2009-09-29 04:40:55 UTC
  • mfrom: (4717 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4718.
  • Revision ID: aaron@aaronbentley.com-20090929044055-e9jtpmz6eyut711h
Merged bzr.dev into fix_get_mtime.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""B+Tree indices"""
19
19
 
 
20
import cStringIO
20
21
from bisect import bisect_right
21
22
import math
22
23
import tempfile
60
61
    def __init__(self):
61
62
        """Create a _BuilderRow."""
62
63
        self.nodes = 0
63
 
        self.spool = tempfile.TemporaryFile()
 
64
        self.spool = None# tempfile.TemporaryFile(prefix='bzr-index-row-')
64
65
        self.writer = None
65
66
 
66
67
    def finish_node(self, pad=True):
67
68
        byte_lines, _, padding = self.writer.finish()
68
69
        if self.nodes == 0:
 
70
            self.spool = cStringIO.StringIO()
69
71
            # padded note:
70
72
            self.spool.write("\x00" * _RESERVED_HEADER_BYTES)
 
73
        elif self.nodes == 1:
 
74
            # We got bigger than 1 node, switch to a temp file
 
75
            spool = tempfile.TemporaryFile(prefix='bzr-index-row-')
 
76
            spool.write(self.spool.getvalue())
 
77
            self.spool = spool
71
78
        skipped_bytes = 0
72
79
        if not pad and padding:
73
80
            del byte_lines[-1]
182
189
             backing_pos) = self._spill_mem_keys_and_combine()
183
190
        else:
184
191
            new_backing_file, size = self._spill_mem_keys_without_combining()
185
 
        dir_path, base_name = osutils.split(new_backing_file.name)
186
192
        # Note: The transport here isn't strictly needed, because we will use
187
193
        #       direct access to the new_backing._file object
188
 
        new_backing = BTreeGraphIndex(get_transport(dir_path),
189
 
                                      base_name, size)
 
194
        new_backing = BTreeGraphIndex(get_transport('.'), '<temp>', size)
190
195
        # GC will clean up the file
191
196
        new_backing._file = new_backing_file
192
197
        if self._combine_backing_indices:
379
384
        for row in reversed(rows):
380
385
            pad = (type(row) != _LeafBuilderRow)
381
386
            row.finish_node(pad=pad)
382
 
        result = tempfile.NamedTemporaryFile(prefix='bzr-index-')
383
387
        lines = [_BTSIGNATURE]
384
388
        lines.append(_OPTION_NODE_REFS + str(self.reference_lists) + '\n')
385
389
        lines.append(_OPTION_KEY_ELEMENTS + str(self._key_length) + '\n')
386
390
        lines.append(_OPTION_LEN + str(key_count) + '\n')
387
391
        row_lengths = [row.nodes for row in rows]
388
392
        lines.append(_OPTION_ROW_LENGTHS + ','.join(map(str, row_lengths)) + '\n')
 
393
        if row_lengths and row_lengths[-1] > 1:
 
394
            result = tempfile.NamedTemporaryFile(prefix='bzr-index-')
 
395
        else:
 
396
            result = cStringIO.StringIO()
389
397
        result.writelines(lines)
390
398
        position = sum(map(len, lines))
391
399
        root_row = True
1526
1534
 
1527
1535
try:
1528
1536
    from bzrlib import _btree_serializer_pyx as _btree_serializer
1529
 
except ImportError:
 
1537
except ImportError, e:
 
1538
    osutils.failed_to_load_extension(e)
1530
1539
    from bzrlib import _btree_serializer_py as _btree_serializer