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

Refactor repository initialization.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
 
48
48
from dulwich.objects import (
49
49
    Commit,
 
50
    Tag,
50
51
    )
51
52
 
52
53
 
56
57
    _serializer = None
57
58
    _commit_builder_class = GitCommitBuilder
58
59
    vcs = foreign_git
 
60
    chk_bytes = None
59
61
 
60
62
    def __init__(self, gitdir, lockfiles):
61
63
        ForeignRepository.__init__(self, GitRepositoryFormat(), gitdir,
74
76
    def supports_rich_root(self):
75
77
        return True
76
78
 
77
 
    def _warn_if_deprecated(self, branch=None):
 
79
    def _warn_if_deprecated(self, branch=None): # for bzr < 2.4
78
80
        # This class isn't deprecated
79
81
        pass
80
82
 
134
136
                commit = self._git[hexsha]
135
137
            except KeyError:
136
138
                continue
137
 
            parent_map[revision_id] = [
 
139
            parents = [
138
140
                self.lookup_foreign_revision_id(p, mapping)
139
141
                for p in commit.parents]
 
142
            if parents == []:
 
143
                parents = [revision.NULL_REVISION]
 
144
            parent_map[revision_id] = tuple(parents)
140
145
        return parent_map
141
146
 
142
147
    def get_ancestry(self, revision_id, topo_sorted=True):
149
154
        graph = self.get_graph()
150
155
        for rev, parents in graph.iter_ancestry([revision_id]):
151
156
            ancestry.append(rev)
 
157
        if revision.NULL_REVISION in ancestry:
 
158
            ancestry.remove(revision.NULL_REVISION)
152
159
        ancestry.reverse()
153
160
        return [None] + ancestry
154
161
 
171
178
        if foreign_revid == ZERO_SHA:
172
179
            return revision.NULL_REVISION
173
180
        commit = self._git[foreign_revid]
 
181
        while isinstance(commit, Tag):
 
182
            commit = self._git[commit.object[1]]
174
183
        rev, roundtrip_revid, verifiers = mapping.import_commit(commit,
175
184
            lambda x: None)
176
185
        # FIXME: check testament before doing this?
189
198
            if mapping is None:
190
199
                mapping = self.get_mapping()
191
200
            try:
192
 
                return (self._git.refs[mapping.revid_as_refname(bzr_revid)],
193
 
                        mapping)
 
201
                return (self._git.refs[mapping.revid_as_refname(bzr_revid)], mapping)
194
202
            except KeyError:
195
203
                # Update refs from Git commit objects
196
204
                # FIXME: Hitting this a lot will be very inefficient...
204
212
                raise errors.NoSuchRevision(self, bzr_revid)
205
213
 
206
214
    def get_revision(self, revision_id):
 
215
        if not isinstance(revision_id, str):
 
216
            raise errors.InvalidRevisionId(revision_id, self)
207
217
        git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
208
218
        try:
209
219
            commit = self._git[git_commit_id]
218
228
        return revision
219
229
 
220
230
    def has_revision(self, revision_id):
 
231
        """See Repository.has_revision."""
221
232
        try:
222
233
            git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
223
234
        except errors.NoSuchRevision:
225
236
        return (git_commit_id in self._git)
226
237
 
227
238
    def has_revisions(self, revision_ids):
 
239
        """See Repository.has_revisions."""
228
240
        return set(filter(self.has_revision, revision_ids))
229
241
 
230
242
    def get_revisions(self, revids):
 
243
        """See Repository.get_revisions."""
231
244
        return [self.get_revision(r) for r in revids]
232
245
 
233
246
    def revision_trees(self, revids):
 
247
        """See Repository.revision_trees."""
234
248
        for revid in revids:
235
249
            yield self.revision_tree(revid)
236
250
 
237
251
    def revision_tree(self, revision_id):
 
252
        """See Repository.revision_tree."""
238
253
        revision_id = revision.ensure_null(revision_id)
239
254
        if revision_id == revision.NULL_REVISION:
240
255
            inv = inventory.Inventory(root_id=None)
253
268
        progress=None):
254
269
        return self._git.fetch_objects(determine_wants, graph_walker, progress)
255
270
 
256
 
    def _get_versioned_file_checker(self, text_key_references=None,
257
 
                        ancestors=None):
 
271
    def _get_versioned_file_checker(self, text_key_references=None, ancestors=None):
258
272
        return GitVersionedFileChecker(self,
259
273
            text_key_references=text_key_references, ancestors=ancestors)
260
274
 
272
286
 
273
287
    supports_tree_reference = False
274
288
    rich_root_data = True
 
289
    supports_leaving_lock = False
 
290
    fast_deltas = True
 
291
 
 
292
    @property
 
293
    def _matchingbzrdir(self):
 
294
        from bzrlib.plugins.git.dir import LocalGitControlDirFormat
 
295
        return LocalGitControlDirFormat()
275
296
 
276
297
    def get_format_description(self):
277
298
        return "Git Repository"
278
299
 
279
 
    def initialize(self, url, shared=False, _internal=False):
280
 
        raise errors.UninitializableFormat(self)
 
300
    def initialize(self, controldir, shared=False, _internal=False):
 
301
        from bzrlib.plugins.git.dir import GitDir
 
302
        if not isinstance(controldir, GitDir):
 
303
            raise errors.UninitializableFormat(self)
 
304
        return controldir.open_repository()
281
305
 
282
306
    def check_conversion_target(self, target_repo_format):
283
307
        return target_repo_format.rich_root_data