/breezy/unstable

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/unstable

« back to all changes in this revision

Viewing changes to breezy/versionedfile.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-24 01:39:33 UTC
  • mfrom: (3815.3776.6)
  • Revision ID: jelmer@jelmer.uk-20170524013933-ir4y4tqtrsiz2ka2
New upstream snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from __future__ import absolute_import
20
20
 
21
21
from copy import copy
22
 
from cStringIO import StringIO
23
22
import os
24
23
import struct
25
24
from zlib import adler32
26
25
 
27
 
from bzrlib.lazy_import import lazy_import
 
26
from .lazy_import import lazy_import
28
27
lazy_import(globals(), """
29
 
from bzrlib import (
 
28
from breezy import (
30
29
    annotate,
31
30
    bencode,
32
31
    errors,
41
40
    urlutils,
42
41
    )
43
42
""")
44
 
from bzrlib.registry import Registry
45
 
from bzrlib.textmerge import TextMerge
 
43
from .registry import Registry
 
44
from .sixish import (
 
45
    BytesIO,
 
46
    )
 
47
from .textmerge import TextMerge
46
48
 
47
49
 
48
50
adapter_registry = Registry()
49
 
adapter_registry.register_lazy(('knit-delta-gz', 'fulltext'), 'bzrlib.knit',
 
51
adapter_registry.register_lazy(('knit-delta-gz', 'fulltext'), 'breezy.knit',
50
52
    'DeltaPlainToFullText')
51
 
adapter_registry.register_lazy(('knit-ft-gz', 'fulltext'), 'bzrlib.knit',
 
53
adapter_registry.register_lazy(('knit-ft-gz', 'fulltext'), 'breezy.knit',
52
54
    'FTPlainToFullText')
53
55
adapter_registry.register_lazy(('knit-annotated-delta-gz', 'knit-delta-gz'),
54
 
    'bzrlib.knit', 'DeltaAnnotatedToUnannotated')
 
56
    'breezy.knit', 'DeltaAnnotatedToUnannotated')
55
57
adapter_registry.register_lazy(('knit-annotated-delta-gz', 'fulltext'),
56
 
    'bzrlib.knit', 'DeltaAnnotatedToFullText')
 
58
    'breezy.knit', 'DeltaAnnotatedToFullText')
57
59
adapter_registry.register_lazy(('knit-annotated-ft-gz', 'knit-ft-gz'),
58
 
    'bzrlib.knit', 'FTAnnotatedToUnannotated')
 
60
    'breezy.knit', 'FTAnnotatedToUnannotated')
59
61
adapter_registry.register_lazy(('knit-annotated-ft-gz', 'fulltext'),
60
 
    'bzrlib.knit', 'FTAnnotatedToFullText')
 
62
    'breezy.knit', 'FTAnnotatedToFullText')
61
63
# adapter_registry.register_lazy(('knit-annotated-ft-gz', 'chunked'),
62
 
#     'bzrlib.knit', 'FTAnnotatedToChunked')
 
64
#     'breezy.knit', 'FTAnnotatedToChunked')
63
65
 
64
66
 
65
67
class ContentFactory(object):
584
586
        raise NotImplementedError(self.get_lines)
585
587
 
586
588
    def _get_lf_split_line_list(self, version_ids):
587
 
        return [StringIO(t).readlines() for t in self.get_texts(version_ids)]
 
589
        return [BytesIO(t).readlines() for t in self.get_texts(version_ids)]
588
590
 
589
591
    def get_ancestry(self, version_ids, topo_sorted=True):
590
592
        """Return a list of all ancestors of given version(s). This
919
921
 
920
922
    The keyspace is expressed via simple tuples. Any instance of VersionedFiles
921
923
    may have a different length key-size, but that size will be constant for
922
 
    all texts added to or retrieved from it. For instance, bzrlib uses
 
924
    all texts added to or retrieved from it. For instance, breezy uses
923
925
    instances with a key-size of 2 for storing user files in a repository, with
924
926
    the first element the fileid, and the second the version of that file.
925
927
 
1129
1131
        """
1130
1132
        raise NotImplementedError(self.get_sha1s)
1131
1133
 
1132
 
    has_key = index._has_key_from_parent_map
 
1134
    __contains__ = index._has_key_from_parent_map
1133
1135
 
1134
1136
    def get_missing_compression_parent_keys(self):
1135
1137
        """Return an iterable of keys of missing compression parents.
1319
1321
    def _get_all_prefixes(self):
1320
1322
        # Identify all key prefixes.
1321
1323
        # XXX: A bit hacky, needs polish.
1322
 
        if type(self._mapper) == ConstantMapper:
 
1324
        if isinstance(self._mapper, ConstantMapper):
1323
1325
            paths = [self._mapper.map(())]
1324
1326
            prefixes = [()]
1325
1327
        else:
1480
1482
 
1481
1483
    def plan_merge(self, ver_a, ver_b, base=None):
1482
1484
        """See VersionedFile.plan_merge"""
1483
 
        from bzrlib.merge import _PlanMerge
 
1485
        from .merge import _PlanMerge
1484
1486
        if base is None:
1485
1487
            return _PlanMerge(ver_a, ver_b, self, (self._file_id,)).plan_merge()
1486
1488
        old_plan = list(_PlanMerge(ver_a, base, self, (self._file_id,)).plan_merge())
1488
1490
        return _PlanMerge._subtract_plans(old_plan, new_plan)
1489
1491
 
1490
1492
    def plan_lca_merge(self, ver_a, ver_b, base=None):
1491
 
        from bzrlib.merge import _PlanLCAMerge
 
1493
        from .merge import _PlanLCAMerge
1492
1494
        graph = _mod_graph.Graph(self)
1493
1495
        new_plan = _PlanLCAMerge(ver_a, ver_b, self, (self._file_id,), graph).plan_merge()
1494
1496
        if base is None:
1502
1504
        Lines are added locally, not to fallback versionedfiles.  Also, ghosts
1503
1505
        are permitted.  Only reserved ids are permitted.
1504
1506
        """
1505
 
        if type(key) is not tuple:
 
1507
        if not isinstance(key, tuple):
1506
1508
            raise TypeError(key)
1507
1509
        if not revision.is_reserved_id(key[-1]):
1508
1510
            raise ValueError('Only reserved ids may be used')