/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

Print proper error about not supporting push.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2007 Canonical Ltd
 
2
# Copyright (C) 2008-2009 Jelmer Vernooij <jelmer@samba.org>
2
3
#
3
4
# This program is free software; you can redistribute it and/or modify
4
5
# it under the terms of the GNU General Public License as published by
16
17
 
17
18
"""An adapter between a Git Repository and a Bazaar Branch"""
18
19
 
19
 
import os
20
 
import time
21
 
 
22
20
import bzrlib
23
21
from bzrlib import (
24
22
    errors,
40
38
from bzrlib.plugins.git.foreign import (
41
39
    versionedfiles,
42
40
    )
43
 
from bzrlib.plugins.git.mapping import default_mapping, mapping_registry, inventory_to_tree_and_blobs, revision_to_commit
 
41
from bzrlib.plugins.git.mapping import (
 
42
    default_mapping,
 
43
    inventory_to_tree_and_blobs,
 
44
    mapping_registry,
 
45
    revision_to_commit,
 
46
    )
44
47
from bzrlib.plugins.git.versionedfiles import GitTexts
45
48
 
46
49
import dulwich as git
 
50
import os
 
51
import time
47
52
 
48
53
 
49
54
class GitTags(object):
61
66
    _serializer = None
62
67
 
63
68
    def __init__(self, gitdir, lockfiles):
64
 
        ForeignRepository.__init__(self, GitFormat(), gitdir, lockfiles)
65
 
        from bzrlib.plugins.git import fetch
66
 
        repository.InterRepository.register_optimiser(fetch.InterGitRepository)
67
 
        repository.InterRepository.register_optimiser(fetch.InterGitNonGitRepository)
 
69
        ForeignRepository.__init__(self, GitRepositoryFormat(), gitdir, 
 
70
            lockfiles)
 
71
        from bzrlib.plugins.git import fetch, push
 
72
        for optimiser in [fetch.InterGitRepository, 
 
73
                          fetch.InterGitNonGitRepository,
 
74
                          push.InterToGitRepository]:
 
75
            repository.InterRepository.register_optimiser(optimiser)
68
76
 
69
77
    def is_shared(self):
70
78
        return True
84
92
 
85
93
 
86
94
class LocalGitRepository(GitRepository):
 
95
    """Git repository on the file system."""
87
96
 
88
97
    def __init__(self, gitdir, lockfiles):
89
98
        # FIXME: This also caches negatives. Need to be more careful 
101
110
 
102
111
    def all_revision_ids(self):
103
112
        ret = set([revision.NULL_REVISION])
104
 
        if self._git.heads() == []:
 
113
        heads = self._git.heads()
 
114
        if heads == {}:
105
115
            return ret
106
 
        bzr_heads = [self.get_mapping().revision_id_foreign_to_bzr(h) for h in self._git.heads()]
 
116
        bzr_heads = [self.get_mapping().revision_id_foreign_to_bzr(h) for h in heads.itervalues()]
107
117
        ret = set(bzr_heads)
108
118
        graph = self.get_graph()
109
119
        for rev, parents in graph.iter_ancestry(bzr_heads):
139
149
        """See Repository.get_ancestry().
140
150
        """
141
151
        if revision_id is None:
142
 
            return self._all_revision_ids()
 
152
            return [None, revision.NULL_REVISION] + self._all_revision_ids()
143
153
        assert isinstance(revision_id, str)
144
154
        ancestry = []
145
155
        graph = self.get_graph()
146
156
        for rev, parents in graph.iter_ancestry([revision_id]):
147
 
            if rev == revision.NULL_REVISION:
148
 
                rev = None
149
157
            ancestry.append(rev)
150
158
        ancestry.reverse()
151
 
        return ancestry
 
159
        return [None] + ancestry
152
160
 
153
161
    def import_revision_gist(self, source, revid, parent_lookup):
154
 
        """Impor the gist of another revision into this Git repository.
 
162
        """Import the gist of a revision into this Git repository.
155
163
 
156
164
        """
157
165
        objects = []
166
174
        return commit.sha().hexdigest()
167
175
 
168
176
    def dfetch(self, source, stop_revision):
 
177
        """Import the gist of the ancestry of a particular revision."""
169
178
        if stop_revision is None:
170
179
            raise NotImplementedError
171
180
        revidmap = {}
172
181
        gitidmap = {}
 
182
        def parent_lookup(revid):
 
183
            try:
 
184
                return gitidmap[revid]
 
185
            except KeyError:
 
186
                return self.lookup_git_revid(revid)[0]
173
187
        todo = []
174
188
        source.lock_write()
175
189
        try:
182
196
            try:
183
197
                for i, revid in enumerate(todo):
184
198
                    pb.update("pushing revisions", i, len(todo))
185
 
                    git_commit = self.import_revision_gist(source, revid, gitidmap.__getitem__)
 
199
                    git_commit = self.import_revision_gist(source, revid,
 
200
                        parent_lookup)
186
201
                    gitidmap[revid] = git_commit
187
 
                    git_revid = self.get_mapping().revision_id_foreign_to_bzr(git_commit)
 
202
                    git_revid = self.get_mapping().revision_id_foreign_to_bzr(
 
203
                        git_commit)
188
204
                    revidmap[revid] = git_revid
189
205
            finally:
190
206
                pb.finished()
242
258
 
243
259
    def revision_tree(self, revision_id):
244
260
        revision_id = revision.ensure_null(revision_id)
245
 
 
246
261
        if revision_id == revision.NULL_REVISION:
247
262
            inv = inventory.Inventory(root_id=None)
248
263
            inv.revision_id = revision_id
249
264
            return revisiontree.RevisionTree(self, inv, revision_id)
250
 
 
251
265
        return GitRevisionTree(self, revision_id)
252
266
 
253
267
    def get_inventory(self, revision_id):
257
271
    def set_make_working_trees(self, trees):
258
272
        pass
259
273
 
260
 
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref, progress=None):
 
274
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
 
275
        progress=None):
261
276
        return self._git.fetch_objects(determine_wants, graph_walker, progress)
262
277
 
263
278
 
323
338
                self._build_inventory(hexsha, child_ie, child_path)
324
339
 
325
340
 
326
 
class GitFormat(object):
 
341
class GitRepositoryFormat(repository.RepositoryFormat):
327
342
 
328
343
    supports_tree_reference = False
329
344
    rich_root_data = True