/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

Support read locking object stores.

Show diffs side-by-side

added added

removed removed

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