/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

More work on roundtrip push support.

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