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

Implement BazaarObjectStore.__contains__, BazaarObjectStore.iter_shas, BazaarObjectStore.get_parents.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
    Blob,
21
21
    Tree,
22
22
    )
 
23
from dulwich.object_store import (
 
24
    ObjectStoreIterator,
 
25
    )
23
26
import stat
24
27
 
25
28
from bzrlib import (
48
51
            self.mapping = mapping
49
52
        self._idmap = SqliteGitShaMap.from_repository(repository)
50
53
 
51
 
    def _update_sha_map(self):
52
 
        all_revids = self.repository.all_revision_ids()
 
54
    def iter_shas(self, shas):
 
55
        return ObjectStoreIterator(self, shas)
 
56
 
 
57
    def _update_sha_map(self, stop_revision=None):
 
58
        if stop_revision is None:
 
59
            all_revids = self.repository.all_revision_ids()
 
60
        else:
 
61
            all_revids = self.repository.get_ancestry(stop_revision)
 
62
            first = all_revids.pop(0) # Pop leading None
 
63
            assert first is None
53
64
        graph = self.repository.get_graph()
54
65
        present_revids = set(self._idmap.revids())
55
66
        missing_revids = [revid for revid in graph.iter_topo_order(all_revids) if revid not in present_revids]
143
154
        self._check_expected_sha(expected_sha, commit)
144
155
        return commit
145
156
 
 
157
    def get_parents(self, sha):
 
158
        return self[sha].parents
 
159
 
146
160
    def _lookup_revision_sha1(self, revid):
147
161
        try:
148
162
            return self._idmap._parent_lookup(revid)
156
170
    def get_raw(self, sha):
157
171
        return self[sha].as_raw_string()
158
172
 
159
 
    def __getitem__(self, sha):
160
 
        # See if sha is in map
161
 
        try:
162
 
            (type, type_data) = self._idmap.lookup_git_sha(sha)
 
173
    def __contains__(self, sha):
 
174
        # See if sha is in map
 
175
        try:
 
176
            self._lookup_git_sha(sha)
 
177
        except KeyError:
 
178
            return False
 
179
        else:
 
180
            return True
 
181
 
 
182
    def _lookup_git_sha(self, sha):
 
183
        # See if sha is in map
 
184
        try:
 
185
            return self._idmap.lookup_git_sha(sha)
163
186
        except KeyError:
164
187
            # if not, see if there are any unconverted revisions and add them 
165
188
            # to the map, search for sha in map again
166
189
            self._update_sha_map()
167
 
            (type, type_data) = self._idmap.lookup_git_sha(sha)
 
190
            return self._idmap.lookup_git_sha(sha)
 
191
 
 
192
    def __getitem__(self, sha):
 
193
        (type, type_data) = self._lookup_git_sha(sha)
168
194
        # convert object to git object
169
195
        if type == "commit":
170
196
            return self._get_commit(type_data[0], type_data[1],