/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

  • Committer: Jelmer Vernooij
  • Date: 2009-10-18 15:44:38 UTC
  • mto: (0.200.636 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20091018154438-l53yy8s00eomwc9v
Add support for parsing hg-git metadata in the experimental mappings.

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