/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

Require dulwich 0.7.1.

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