/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 breezy/bzr/index.py

  • Committer: Martin
  • Date: 2018-06-30 22:18:39 UTC
  • mfrom: (7010 work)
  • mto: This revision was merged to the branch mainline in revision 7012.
  • Revision ID: gzlist@googlemail.com-20180630221839-98zi78xwcggestse
Merge trunk to fix conflict

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
    )
44
44
from ..sixish import (
45
45
    BytesIO,
 
46
    bytesintern,
46
47
    viewvalues,
47
48
    viewitems,
 
49
    zip,
48
50
    )
49
51
from ..static_tuple import StaticTuple
50
52
 
286
288
        """
287
289
        (node_refs,
288
290
         absent_references) = self._check_key_ref_value(key, references, value)
289
 
        if key in self._nodes and self._nodes[key][0] != 'a':
 
291
        if key in self._nodes and self._nodes[key][0] != b'a':
290
292
            raise BadIndexDuplicateKey(key, self)
291
293
        for reference in absent_references:
292
294
            # There may be duplicates, but I don't think it is worth worrying
293
295
            # about
294
 
            self._nodes[reference] = ('a', (), '')
 
296
            self._nodes[reference] = (b'a', (), b'')
295
297
        self._absent_keys.update(absent_references)
296
298
        self._absent_keys.discard(key)
297
 
        self._nodes[key] = ('', node_refs, value)
 
299
        self._nodes[key] = (b'', node_refs, value)
298
300
        if self._nodes_by_key is not None and self._key_length > 1:
299
301
            self._update_nodes_by_key(key, value, node_refs)
300
302
 
499
501
    def __ne__(self, other):
500
502
        return not self.__eq__(other)
501
503
 
 
504
    def __lt__(self, other):
 
505
        # We don't really care about the order, just that there is an order.
 
506
        if (not isinstance(other, GraphIndex) and
 
507
            not isinstance(other, InMemoryGraphIndex)):
 
508
            raise TypeError(other)
 
509
        return hash(self) < hash(other)
 
510
 
 
511
    def __hash__(self):
 
512
        return hash((type(self), self._transport, self._name, self._size))
 
513
 
502
514
    def __repr__(self):
503
515
        return "%s(%r)" % (self.__class__.__name__,
504
516
            self._transport.abspath(self._name))
520
532
                # This is wasteful, but it is better than dealing with
521
533
                # adjusting all the offsets, etc.
522
534
                stream = BytesIO(stream.read()[self._base_offset:])
523
 
        self._read_prefix(stream)
524
 
        self._expected_elements = 3 + self._key_length
525
 
        line_count = 0
526
 
        # raw data keyed by offset
527
 
        self._keys_by_offset = {}
528
 
        # ready-to-return key:value or key:value, node_ref_lists
529
 
        self._nodes = {}
530
 
        self._nodes_by_key = None
531
 
        trailers = 0
532
 
        pos = stream.tell()
533
 
        lines = stream.read().split(b'\n')
534
 
        # GZ 2009-09-20: Should really use a try/finally block to ensure close
535
 
        stream.close()
 
535
        try:
 
536
            self._read_prefix(stream)
 
537
            self._expected_elements = 3 + self._key_length
 
538
            line_count = 0
 
539
            # raw data keyed by offset
 
540
            self._keys_by_offset = {}
 
541
            # ready-to-return key:value or key:value, node_ref_lists
 
542
            self._nodes = {}
 
543
            self._nodes_by_key = None
 
544
            trailers = 0
 
545
            pos = stream.tell()
 
546
            lines = stream.read().split(b'\n')
 
547
        finally:
 
548
            stream.close()
536
549
        del lines[-1]
537
550
        _, _, _, trailers = self._parse_lines(lines, pos)
538
551
        for key, absent, references, value in viewvalues(self._keys_by_offset):
1145
1158
                raise BadIndexData(self)
1146
1159
            # keys are tuples. Each element is a string that may occur many
1147
1160
            # times, so we intern them to save space. AB, RC, 200807
1148
 
            key = tuple([intern(element) for element in elements[:self._key_length]])
 
1161
            key = tuple([bytesintern(element) for element in elements[:self._key_length]])
1149
1162
            if first_key is None:
1150
1163
                first_key = key
1151
1164
            absent, references, value = elements[-3:]
1599
1612
        """
1600
1613
        if self._reload_func is None:
1601
1614
            return False
1602
 
        trace.mutter('Trying to reload after getting exception: %s', error)
 
1615
        trace.mutter('Trying to reload after getting exception: %s', str(error))
1603
1616
        if not self._reload_func():
1604
1617
            # We tried to reload, but nothing changed, so we fail anyway
1605
1618
            trace.mutter('_reload_func indicated nothing has changed.'
1731
1744
    def validate(self):
1732
1745
        """In memory index's have no known corruption at the moment."""
1733
1746
 
 
1747
    def __lt__(self, other):
 
1748
        # We don't really care about the order, just that there is an order.
 
1749
        if (not isinstance(other, GraphIndex) and
 
1750
            not isinstance(other, InMemoryGraphIndex)):
 
1751
            raise TypeError(other)
 
1752
        return hash(self) < hash(other)
 
1753
 
1734
1754
 
1735
1755
class GraphIndexPrefixAdapter(object):
1736
1756
    """An adapter between GraphIndex with different key lengths.