/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

Fix compatibility with newer versions of Dulwich.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""An adapter between a Git Repository and a Bazaar Branch"""
19
19
 
20
 
import bzrlib
21
20
from bzrlib import (
22
21
    errors,
23
22
    graph,
24
23
    inventory,
25
 
    osutils,
26
24
    repository,
27
25
    revision,
28
26
    revisiontree,
29
 
    ui,
30
 
    urlutils,
31
27
    )
32
28
from bzrlib.foreign import (
33
29
    ForeignRepository,
34
30
    )
35
 
from bzrlib.trace import (
36
 
    mutter,
37
 
    )
38
 
from bzrlib.transport import (
39
 
    get_transport,
40
 
    )
41
31
 
42
32
from bzrlib.plugins.git.commit import (
43
33
    GitCommitBuilder,
44
34
    )
45
 
from bzrlib.plugins.git.inventory import (
46
 
    GitInventory,
47
 
    )
48
35
from bzrlib.plugins.git.mapping import (
49
36
    default_mapping,
50
37
    foreign_git,
51
38
    mapping_registry,
52
39
    )
 
40
from bzrlib.plugins.git.tree import (
 
41
    GitRevisionTree,
 
42
    )
53
43
from bzrlib.plugins.git.versionedfiles import (
54
44
    GitRevisions,
55
45
    GitTexts,
64
54
    vcs = foreign_git
65
55
 
66
56
    def __init__(self, gitdir, lockfiles):
67
 
        ForeignRepository.__init__(self, GitRepositoryFormat(), gitdir, 
 
57
        ForeignRepository.__init__(self, GitRepositoryFormat(), gitdir,
68
58
            lockfiles)
69
59
        from bzrlib.plugins.git import fetch, push
70
 
        for optimiser in [fetch.InterRemoteGitNonGitRepository, 
 
60
        for optimiser in [fetch.InterRemoteGitNonGitRepository,
71
61
                          fetch.InterLocalGitNonGitRepository,
72
62
                          fetch.InterGitGitRepository,
73
63
                          push.InterToLocalGitRepository,
75
65
            repository.InterRepository.register_optimiser(optimiser)
76
66
 
77
67
    def is_shared(self):
78
 
        return True
 
68
        return False
79
69
 
80
70
    def supports_rich_root(self):
81
71
        return True
82
72
 
83
 
    def _warn_if_deprecated(self):
 
73
    def _warn_if_deprecated(self, branch=None):
84
74
        # This class isn't deprecated
85
75
        pass
86
76
 
106
96
    """Git repository on the file system."""
107
97
 
108
98
    def __init__(self, gitdir, lockfiles):
109
 
        # FIXME: This also caches negatives. Need to be more careful 
 
99
        # FIXME: This also caches negatives. Need to be more careful
110
100
        # about this once we start writing to git
111
101
        self._parents_provider = graph.CachingParentsProvider(self)
112
102
        GitRepository.__init__(self, gitdir, lockfiles)
113
103
        self.base = gitdir.root_transport.base
114
104
        self._git = gitdir._git
115
 
        self.texts = None
116
105
        self.signatures = None
117
 
        self.revisions = GitRevisions(self._git.object_store)
 
106
        self.revisions = GitRevisions(self, self._git.object_store)
118
107
        self.inventories = None
119
108
        self.texts = GitTexts(self)
120
109
 
121
110
    def all_revision_ids(self):
122
 
        ret = set([revision.NULL_REVISION])
 
111
        ret = set([])
123
112
        heads = self._git.refs.as_dict('refs/heads')
124
113
        if heads == {}:
125
114
            return ret
141
130
            if revision_id == revision.NULL_REVISION:
142
131
                parent_map[revision_id] = ()
143
132
                continue
144
 
            hexsha, mapping = self.lookup_git_revid(revision_id)
145
 
            commit  = self._git.commit(hexsha)
146
 
            if commit is None:
 
133
            hexsha, mapping = self.lookup_bzr_revision_id(revision_id)
 
134
            try:
 
135
                commit = self._git[hexsha]
 
136
            except KeyError:
147
137
                continue
148
 
            else:
149
 
                parent_map[revision_id] = [mapping.revision_id_foreign_to_bzr(p) for p in commit.parents]
 
138
            parent_map[revision_id] = [mapping.revision_id_foreign_to_bzr(p) for p in commit.parents]
150
139
        return parent_map
151
140
 
152
141
    def get_ancestry(self, revision_id, topo_sorted=True):
165
154
    def get_signature_text(self, revision_id):
166
155
        raise errors.NoSuchRevision(self, revision_id)
167
156
 
168
 
    def lookup_revision_id(self, revid):
 
157
    def lookup_foreign_revision_id(self, foreign_revid, mapping=None):
169
158
        """Lookup a revision id.
170
 
        
171
 
        :param revid: Bazaar revision id.
172
 
        :return: Tuple with git revisionid and mapping.
 
159
 
173
160
        """
174
 
        # Yes, this doesn't really work, but good enough as a stub
175
 
        return osutils.sha(rev_id).hexdigest(), self.get_mapping()
 
161
        if mapping is None:
 
162
            mapping = self.get_mapping()
 
163
        return mapping.revision_id_foreign_to_bzr(foreign_revid)
176
164
 
177
165
    def has_signature_for_revision_id(self, revision_id):
178
166
        return False
179
167
 
180
 
    def lookup_git_revid(self, bzr_revid):
 
168
    def lookup_bzr_revision_id(self, bzr_revid):
181
169
        try:
182
170
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
183
171
        except errors.InvalidRevisionId:
184
172
            raise errors.NoSuchRevision(self, bzr_revid)
185
173
 
186
174
    def get_revision(self, revision_id):
187
 
        git_commit_id, mapping = self.lookup_git_revid(revision_id)
 
175
        git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
188
176
        try:
189
 
            commit = self._git.commit(git_commit_id)
 
177
            commit = self._git[git_commit_id]
190
178
        except KeyError:
191
179
            raise errors.NoSuchRevision(self, revision_id)
192
180
        # print "fetched revision:", git_commit_id
196
184
 
197
185
    def has_revision(self, revision_id):
198
186
        try:
199
 
            self.get_revision(revision_id)
 
187
            git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
200
188
        except errors.NoSuchRevision:
201
189
            return False
202
 
        else:
203
 
            return True
 
190
        return (git_commit_id in self._git)
 
191
 
 
192
    def has_revisions(self, revision_ids):
 
193
        ret = set()
 
194
        for revid in revision_ids:
 
195
            if self.has_revision(revid):
 
196
                ret.add(revid)
 
197
        return ret
204
198
 
205
199
    def get_revisions(self, revids):
206
200
        return [self.get_revision(r) for r in revids]
228
222
        progress=None):
229
223
        return self._git.fetch_objects(determine_wants, graph_walker, progress)
230
224
 
231
 
 
232
 
class GitRevisionTree(revisiontree.RevisionTree):
233
 
 
234
 
    def __init__(self, repository, revision_id):
235
 
        self._revision_id = revision_id
236
 
        self._repository = repository
237
 
        store = repository._git.object_store
238
 
        assert isinstance(revision_id, str)
239
 
        git_id, self.mapping = repository.lookup_git_revid(revision_id)
240
 
        try:
241
 
            commit = store[git_id]
242
 
        except KeyError, r:
243
 
            raise errors.NoSuchRevision(repository, revision_id)
244
 
        self.tree = commit.tree
245
 
        self._inventory = GitInventory(self.tree, self.mapping, store, 
246
 
                                       revision_id)
247
 
 
248
 
    def get_revision_id(self):
249
 
        return self._revision_id
250
 
 
251
 
    def get_file_text(self, file_id, path=None):
252
 
        if path is not None:
253
 
            entry = self._inventory._get_ie(path)
254
 
        else:
255
 
            entry = self._inventory[file_id]
256
 
        if entry.kind == 'directory': return ""
257
 
        return entry.object.data
 
225
    def _get_versioned_file_checker(self, text_key_references=None,
 
226
                        ancestors=None):
 
227
        return GitVersionedFileChecker(self,
 
228
            text_key_references=text_key_references, ancestors=ancestors)
 
229
    
 
230
 
 
231
class GitVersionedFileChecker(repository._VersionedFileChecker):
 
232
 
 
233
    file_ids = []
 
234
 
 
235
    def _check_file_version_parents(self, texts, progress_bar):
 
236
        return {}, []
258
237
 
259
238
 
260
239
class GitRepositoryFormat(repository.RepositoryFormat):
267
246
        return "Git Repository"
268
247
 
269
248
    def initialize(self, url, shared=False, _internal=False):
270
 
        raise bzr_errors.UninitializableFormat(self)
 
249
        raise errors.UninitializableFormat(self)
271
250
 
272
251
    def check_conversion_target(self, target_repo_format):
273
252
        return target_repo_format.rich_root_data
274
253
 
 
254
    def get_foreign_tests_repository_factory(self):
 
255
        from bzrlib.plugins.git.tests.test_repository import (
 
256
            ForeignTestsRepositoryFactory,
 
257
            )
 
258
        return ForeignTestsRepositoryFactory()
 
259
 
275
260
    def network_name(self):
276
261
        return "git"