/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

More tests for sha maps, fix cache misses in tdb.

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
 
 
25
from bzrlib.revision import (
 
26
    NULL_REVISION,
 
27
    )
26
28
from bzrlib.versionedfile import (
27
29
    AbsentContentFactory,
28
30
    FulltextContentFactory,
30
32
    )
31
33
 
32
34
 
33
 
class GitRevisions(VersionedFiles):
34
 
 
35
 
    def __init__(self, repository, object_store):
36
 
        self.repository = repository
37
 
        self.object_store = object_store
38
 
 
39
 
    def check(self, progressbar=None):
40
 
        return True
41
 
 
42
 
    def iterkeys(self):
43
 
        for sha in self.object_store:
44
 
            if type(sha) == Commit:
45
 
                yield (sha,)
46
 
 
47
 
    def keys(self):
48
 
        return list(self.iterkeys())
49
 
 
50
 
    def add_mpdiffs(self, records):
51
 
        raise NotImplementedError(self.add_mpdiffs)
52
 
 
53
 
    def get_record_stream(self, keys, ordering, include_delta_closure):
54
 
        for key in keys:
55
 
            (revid,) = key
56
 
            (commit_id, mapping) = self.repository.lookup_bzr_revision_id(revid)
57
 
            try:
58
 
                commit = self.object_store[commit_id]
59
 
            except KeyError:
60
 
                yield AbsentContentFactory(key)
61
 
            else:
62
 
                yield FulltextContentFactory(key, 
63
 
                    tuple([(self.repository.lookup_foreign_revision_id(p, mapping),) for p in commit.parents]), None, 
64
 
                    commit.as_raw_string())
65
 
 
66
 
    def get_parent_map(self, keys):
67
 
        ret = {}
68
 
        for (revid,) in keys:
69
 
            (commit_id, mapping) = self.repository.lookup_bzr_revision_id(revid)
70
 
            try:
71
 
                ret[(revid,)] = [(self.repository.lookup_foreign_revision_id(p, mapping),) for p in self.object_store[commit_id].parents]
72
 
            except KeyError:
73
 
                ret[(revid,)] = None
74
 
        return ret
75
 
 
76
 
 
77
35
class GitTexts(VersionedFiles):
78
36
    """A texts VersionedFiles instance that is backed onto a Git object store."""
79
37
 
90
48
    def get_record_stream(self, keys, ordering, include_delta_closure):
91
49
        for key in keys:
92
50
            (fileid, revid) = key
93
 
            (commit_id, mapping) = self.repository.lookup_bzr_revision_id(revid)
94
 
            root_tree = self.object_store[commit_id].tree
 
51
            (foreign_revid, mapping) = self.repository.lookup_git_revid(revid)
 
52
            root_tree = self.object_store[foreign_revid].tree
95
53
            path = mapping.parse_file_id(fileid)
96
54
            try:
97
 
                obj = tree_lookup_path(
98
 
                    self.object_store.__getitem__, root_tree, path)
99
 
                if isinstance(obj, tuple):
100
 
                    (mode, item_id) = obj
101
 
                    obj = self.object_store[item_id]
 
55
                obj = tree_lookup_path(self.object_store.__getitem__, 
 
56
                                       root_tree, path)
102
57
            except KeyError:
103
58
                yield AbsentContentFactory(key)
104
59
            else:
105
60
                if isinstance(obj, Tree):
106
61
                    yield FulltextContentFactory(key, None, None, "")
107
62
                elif isinstance(obj, Blob):
108
 
                    yield FulltextContentFactory(key, None, None, obj.data)
 
63
                    yield FulltextContentFactory(key, None, None, obj._text)
109
64
                else:
110
 
                    raise AssertionError("file text resolved to %r" % obj)
 
65
                    yield AbsentContentFactory(key)
111
66
 
112
67
    def get_parent_map(self, keys):
113
68
        raise NotImplementedError(self.get_parent_map)