/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

Indicate .git directories are supported.

Show diffs side-by-side

added added

removed removed

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