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

merge new bzr-foreign.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
    )
20
20
from dulwich.objects import (
21
21
    Blob,
22
 
    Commit,
23
22
    Tree,
24
23
    )
25
24
 
26
 
from bzrlib import (
27
 
    annotate,
 
25
from bzrlib.revision import (
 
26
    NULL_REVISION,
28
27
    )
29
 
 
30
28
from bzrlib.versionedfile import (
31
29
    AbsentContentFactory,
32
 
    ChunkedContentFactory,
 
30
    FulltextContentFactory,
33
31
    VersionedFiles,
34
32
    )
35
33
 
36
 
 
37
 
class GitRevisions(VersionedFiles):
38
 
 
39
 
    def __init__(self, repository, object_store):
40
 
        self.repository = repository
41
 
        self.object_store = object_store
42
 
 
43
 
    def check(self, progressbar=None):
44
 
        return True
45
 
 
46
 
    def get_annotator(self):
47
 
        return annotate.Annotator(self)
48
 
 
49
 
    def iterkeys(self):
50
 
        for sha in self.object_store:
51
 
            if type(sha) == Commit:
52
 
                yield (sha,)
53
 
 
54
 
    def keys(self):
55
 
        return list(self.iterkeys())
56
 
 
57
 
    def add_mpdiffs(self, records):
58
 
        raise NotImplementedError(self.add_mpdiffs)
59
 
 
60
 
    def get_record_stream(self, keys, ordering, include_delta_closure):
61
 
        for key in keys:
62
 
            (revid,) = key
63
 
            (commit_id, mapping) = self.repository.lookup_bzr_revision_id(revid)
64
 
            try:
65
 
                commit = self.object_store[commit_id]
66
 
            except KeyError:
67
 
                yield AbsentContentFactory(key)
68
 
            else:
69
 
                yield ChunkedContentFactory(key, 
70
 
                    tuple([(self.repository.lookup_foreign_revision_id(p, mapping),) for p in commit.parents]), None, 
71
 
                    commit.as_raw_chunks())
72
 
 
73
 
    def get_parent_map(self, keys):
74
 
        ret = {}
75
 
        for (revid,) in keys:
76
 
            (commit_id, mapping) = self.repository.lookup_bzr_revision_id(revid)
77
 
            try:
78
 
                ret[(revid,)] = [(self.repository.lookup_foreign_revision_id(p, mapping),) for p in self.object_store[commit_id].parents]
79
 
            except KeyError:
80
 
                ret[(revid,)] = None
81
 
        return ret
82
 
 
 
34
from bzrlib.plugins.git.converter import (
 
35
    BazaarObjectStore,
 
36
    )
83
37
 
84
38
class GitTexts(VersionedFiles):
85
39
    """A texts VersionedFiles instance that is backed onto a Git object store."""
91
45
    def check(self, progressbar=None):
92
46
        return True
93
47
 
94
 
    def get_annotator(self):
95
 
        return annotate.Annotator(self)
96
 
 
97
48
    def add_mpdiffs(self, records):
98
49
        raise NotImplementedError(self.add_mpdiffs)
99
50
 
100
51
    def get_record_stream(self, keys, ordering, include_delta_closure):
101
52
        for key in keys:
102
53
            (fileid, revid) = key
103
 
            (commit_id, mapping) = self.repository.lookup_bzr_revision_id(revid)
104
 
            root_tree = self.object_store[commit_id].tree
 
54
            (foreign_revid, mapping) = self.repository.lookup_git_revid(revid)
 
55
            root_tree = self.object_store[foreign_revid].tree
105
56
            path = mapping.parse_file_id(fileid)
106
57
            try:
107
 
                obj = tree_lookup_path(
108
 
                    self.object_store.__getitem__, root_tree, path)
109
 
                if isinstance(obj, tuple):
110
 
                    (mode, item_id) = obj
111
 
                    obj = self.object_store[item_id]
 
58
                obj = tree_lookup_path(self.object_store, root_tree, path)
112
59
            except KeyError:
113
60
                yield AbsentContentFactory(key)
114
61
            else:
115
62
                if isinstance(obj, Tree):
116
 
                    yield ChunkedContentFactory(key, None, None, [])
 
63
                    yield FulltextContentFactory(key, None, None, "")
117
64
                elif isinstance(obj, Blob):
118
 
                    yield ChunkedContentFactory(key, None, None, obj.chunked)
 
65
                    yield FulltextContentFactory(key, None, None, obj._text)
119
66
                else:
120
 
                    raise AssertionError("file text resolved to %r" % obj)
 
67
                    yield AbsentContentFactory(key)
121
68
 
122
69
    def get_parent_map(self, keys):
123
70
        raise NotImplementedError(self.get_parent_map)