/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 roundtripping support.

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
 
import bzrlib
23
20
from bzrlib import (
24
 
    deprecated_graph,
 
21
    check,
25
22
    errors,
26
 
    graph,
 
23
    graph as _mod_graph,
27
24
    inventory,
28
 
    osutils,
29
25
    repository,
30
26
    revision,
31
 
    revisiontree,
32
 
    urlutils,
33
 
    versionedfile,
34
27
    )
 
28
try:
 
29
    from bzrlib.revisiontree import InventoryRevisionTree
 
30
except ImportError: # bzr < 2.4
 
31
    from bzrlib.revisiontree import RevisionTree as InventoryRevisionTree
35
32
from bzrlib.foreign import (
36
 
        ForeignRepository,
37
 
        )
38
 
from bzrlib.trace import mutter
39
 
from bzrlib.transport import get_transport
40
 
 
41
 
from bzrlib.plugins.git.foreign import (
42
 
    versionedfiles,
43
 
    )
44
 
from bzrlib.plugins.git.mapping import default_mapping
45
 
 
46
 
from bzrlib.plugins.git import git
47
 
 
48
 
 
49
 
class GitTags(object):
50
 
 
51
 
    def __init__(self, tags):
52
 
        self._tags = tags
53
 
 
54
 
    def __iter__(self):
55
 
        return iter(self._tags)
 
33
    ForeignRepository,
 
34
    )
 
35
 
 
36
from bzrlib.plugins.git.commit import (
 
37
    GitCommitBuilder,
 
38
    )
 
39
from bzrlib.plugins.git.filegraph import (
 
40
    GitFileLastChangeScanner,
 
41
    GitFileParentProvider,
 
42
    )
 
43
from bzrlib.plugins.git.mapping import (
 
44
    default_mapping,
 
45
    foreign_vcs_git,
 
46
    mapping_registry,
 
47
    )
 
48
from bzrlib.plugins.git.tree import (
 
49
    GitRevisionTree,
 
50
    )
 
51
 
 
52
 
 
53
from dulwich.objects import (
 
54
    Commit,
 
55
    Tag,
 
56
    ZERO_SHA,
 
57
    )
 
58
from dulwich.object_store import (
 
59
    tree_lookup_path,
 
60
    )
 
61
 
 
62
 
 
63
class RepoReconciler(object):
 
64
    """Reconciler that reconciles a repository.
 
65
 
 
66
    """
 
67
 
 
68
    def __init__(self, repo, other=None, thorough=False):
 
69
        """Construct a RepoReconciler.
 
70
 
 
71
        :param thorough: perform a thorough check which may take longer but
 
72
                         will correct non-data loss issues such as incorrect
 
73
                         cached data.
 
74
        """
 
75
        self.repo = repo
 
76
 
 
77
    def reconcile(self):
 
78
        """Perform reconciliation.
 
79
 
 
80
        After reconciliation the following attributes document found issues:
 
81
        inconsistent_parents: The number of revisions in the repository whose
 
82
                              ancestry was being reported incorrectly.
 
83
        garbage_inventories: The number of inventory objects without revisions
 
84
                             that were garbage collected.
 
85
        """
 
86
 
 
87
 
 
88
class GitCheck(check.Check):
 
89
 
 
90
    def __init__(self, repository, check_repo=True):
 
91
        self.repository = repository
 
92
        self.checked_rev_cnt = 0
 
93
 
 
94
    def check(self, callback_refs=None, check_repo=True):
 
95
        if callback_refs is None:
 
96
            callback_refs = {}
 
97
        self.repository.lock_read()
 
98
        self.repository.unlock()
 
99
 
 
100
    def report_results(self, verbose):
 
101
        pass
56
102
 
57
103
 
58
104
class GitRepository(ForeignRepository):
59
105
    """An adapter to git repositories for bzr."""
60
106
 
61
107
    _serializer = None
 
108
    vcs = foreign_vcs_git
 
109
    chk_bytes = None
62
110
 
63
111
    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)
 
112
        super(GitRepository, self).__init__(GitRepositoryFormat(),
 
113
            gitdir, lockfiles)
 
114
        from bzrlib.plugins.git import fetch, push
 
115
        for optimiser in [fetch.InterRemoteGitNonGitRepository,
 
116
                          fetch.InterLocalGitNonGitRepository,
 
117
                          fetch.InterGitGitRepository,
 
118
                          push.InterToLocalGitRepository,
 
119
                          push.InterToRemoteGitRepository]:
 
120
            repository.InterRepository.register_optimiser(optimiser)
 
121
 
 
122
    def add_fallback_repository(self, basis_url):
 
123
        raise errors.UnstackableRepositoryFormat(self._format,
 
124
            self.control_transport.base)
67
125
 
68
126
    def is_shared(self):
69
 
        return True
 
127
        return False
 
128
 
 
129
    def reconcile(self, other=None, thorough=False):
 
130
        """Reconcile this repository."""
 
131
        reconciler = RepoReconciler(self, thorough=thorough)
 
132
        reconciler.reconcile()
 
133
        return reconciler
70
134
 
71
135
    def supports_rich_root(self):
72
136
        return True
73
137
 
74
 
    def _warn_if_deprecated(self):
 
138
    def _warn_if_deprecated(self, branch=None): # for bzr < 2.4
75
139
        # This class isn't deprecated
76
140
        pass
77
141
 
79
143
        return default_mapping
80
144
 
81
145
    def make_working_trees(self):
82
 
        return True
 
146
        return not self._git.bare
 
147
 
 
148
    def revision_graph_can_have_wrong_parents(self):
 
149
        return False
 
150
 
 
151
    def dfetch(self, source, stop_revision):
 
152
        interrepo = repository.InterRepository.get(source, self)
 
153
        return interrepo.dfetch(stop_revision)
 
154
 
 
155
    def add_signature_text(self, revid, signature):
 
156
        raise errors.UnsupportedOperation(self.add_signature_text, self)
83
157
 
84
158
 
85
159
class LocalGitRepository(GitRepository):
 
160
    """Git repository on the file system."""
86
161
 
87
162
    def __init__(self, gitdir, lockfiles):
88
 
        # FIXME: This also caches negatives. Need to be more careful 
89
 
        # about this once we start writing to git
90
 
        self._parents_provider = graph.CachingParentsProvider(self)
91
163
        GitRepository.__init__(self, gitdir, lockfiles)
92
164
        self.base = gitdir.root_transport.base
93
165
        self._git = gitdir._git
94
 
        self.texts = None
95
 
        self.signatures = versionedfiles.VirtualSignatureTexts(self)
96
 
        self.revisions = versionedfiles.VirtualRevisionTexts(self)
97
 
        self.tags = GitTags(self._git.get_tags())
 
166
        self._file_change_scanner = GitFileLastChangeScanner(self)
 
167
 
 
168
    def get_commit_builder(self, branch, parents, config, timestamp=None,
 
169
                           timezone=None, committer=None, revprops=None,
 
170
                           revision_id=None, lossy=False):
 
171
        """Obtain a CommitBuilder for this repository.
 
172
 
 
173
        :param branch: Branch to commit to.
 
174
        :param parents: Revision ids of the parents of the new revision.
 
175
        :param config: Configuration to use.
 
176
        :param timestamp: Optional timestamp recorded for commit.
 
177
        :param timezone: Optional timezone for timestamp.
 
178
        :param committer: Optional committer to set for commit.
 
179
        :param revprops: Optional dictionary of revision properties.
 
180
        :param revision_id: Optional revision id.
 
181
        :param lossy: Whether to discard data that can not be natively
 
182
            represented, when pushing to a foreign VCS
 
183
        """
 
184
        self.start_write_group()
 
185
        return GitCommitBuilder(self, parents, config,
 
186
            timestamp, timezone, committer, revprops, revision_id,
 
187
            lossy)
 
188
 
 
189
    def get_file_graph(self):
 
190
        return _mod_graph.Graph(GitFileParentProvider(
 
191
            self._file_change_scanner))
 
192
 
 
193
    def iter_files_bytes(self, desired_files):
 
194
        """Iterate through file versions.
 
195
 
 
196
        Files will not necessarily be returned in the order they occur in
 
197
        desired_files.  No specific order is guaranteed.
 
198
 
 
199
        Yields pairs of identifier, bytes_iterator.  identifier is an opaque
 
200
        value supplied by the caller as part of desired_files.  It should
 
201
        uniquely identify the file version in the caller's context.  (Examples:
 
202
        an index number or a TreeTransform trans_id.)
 
203
 
 
204
        bytes_iterator is an iterable of bytestrings for the file.  The
 
205
        kind of iterable and length of the bytestrings are unspecified, but for
 
206
        this implementation, it is a list of bytes produced by
 
207
        VersionedFile.get_record_stream().
 
208
 
 
209
        :param desired_files: a list of (file_id, revision_id, identifier)
 
210
            triples
 
211
        """
 
212
        per_revision = {}
 
213
        for (file_id, revision_id, identifier) in desired_files:
 
214
            per_revision.setdefault(revision_id, []).append(
 
215
                (file_id, identifier))
 
216
        for revid, files in per_revision.iteritems():
 
217
            (commit_id, mapping) = self.lookup_bzr_revision_id(revid)
 
218
            try:
 
219
                commit = self._git.object_store[commit_id]
 
220
            except KeyError:
 
221
                raise errors.RevisionNotPresent(revid, self)
 
222
            root_tree = commit.tree
 
223
            for fileid, identifier in files:
 
224
                path = mapping.parse_file_id(fileid)
 
225
                try:
 
226
                    obj = tree_lookup_path(
 
227
                        self._git.object_store.__getitem__, root_tree, path)
 
228
                    if isinstance(obj, tuple):
 
229
                        (mode, item_id) = obj
 
230
                        obj = self._git.object_store[item_id]
 
231
                except KeyError:
 
232
                    raise errors.RevisionNotPresent((fileid, revid), self)
 
233
                else:
 
234
                    if obj.type_name == "tree":
 
235
                        yield (identifier, [])
 
236
                    elif obj.type_name == "blob":
 
237
                        yield (identifier, obj.chunked)
 
238
                    else:
 
239
                        raise AssertionError("file text resolved to %r" % obj)
 
240
 
 
241
 
 
242
    def _iter_revision_ids(self):
 
243
        mapping = self.get_mapping()
 
244
        for sha in self._git.object_store:
 
245
            o = self._git.object_store[sha]
 
246
            if not isinstance(o, Commit):
 
247
                continue
 
248
            rev, roundtrip_revid, verifiers = mapping.import_commit(o,
 
249
                mapping.revision_id_foreign_to_bzr)
 
250
            yield o.id, rev.revision_id, roundtrip_revid
98
251
 
99
252
    def all_revision_ids(self):
100
 
        ret = set([revision.NULL_REVISION])
101
 
        if self._git.heads() == []:
102
 
            return ret
103
 
        bzr_heads = [self.get_mapping().revision_id_foreign_to_bzr(h) for h in self._git.heads()]
104
 
        ret = set(bzr_heads)
105
 
        graph = self.get_graph()
106
 
        for rev, parents in graph.iter_ancestry(bzr_heads):
107
 
            ret.add(rev)
 
253
        ret = set([])
 
254
        for git_sha, revid, roundtrip_revid in self._iter_revision_ids():
 
255
            ret.add(revid)
 
256
            if roundtrip_revid:
 
257
                ret.add(roundtrip_revid)
108
258
        return ret
109
259
 
110
 
    #def get_revision_delta(self, revision_id):
111
 
    #    parent_revid = self.get_revision(revision_id).parent_ids[0]
112
 
    #    diff = self._git.diff(ids.convert_revision_id_bzr_to_git(parent_revid),
113
 
    #                   ids.convert_revision_id_bzr_to_git(revision_id))
114
 
 
115
 
    def _make_parents_provider(self):
116
 
        """See Repository._make_parents_provider()."""
117
 
        return self._parents_provider
118
 
 
119
260
    def get_parent_map(self, revids):
120
261
        parent_map = {}
121
 
        mutter("get_parent_map(%r)", revids)
122
262
        for revision_id in revids:
123
 
            assert isinstance(revision_id, str)
 
263
            if type(revision_id) != str:
 
264
                raise ValueError
124
265
            if revision_id == revision.NULL_REVISION:
125
266
                parent_map[revision_id] = ()
126
267
                continue
127
 
            hexsha = self.lookup_git_revid(revision_id, self.get_mapping())
128
 
            commit  = self._git.commit(hexsha)
129
 
            if commit is None:
130
 
                continue
131
 
            else:
132
 
                parent_map[revision_id] = [self.get_mapping().revision_id_foreign_to_bzr(p) for p in commit.parents]
 
268
            try:
 
269
                hexsha, mapping = self.lookup_bzr_revision_id(revision_id)
 
270
            except errors.NoSuchRevision:
 
271
                continue
 
272
            try:
 
273
                commit = self._git[hexsha]
 
274
            except KeyError:
 
275
                continue
 
276
            parents = [
 
277
                self.lookup_foreign_revision_id(p, mapping)
 
278
                for p in commit.parents]
 
279
            if len(parents) == 0:
 
280
                parents = [revision.NULL_REVISION]
 
281
            parent_map[revision_id] = tuple(parents)
133
282
        return parent_map
134
283
 
135
 
    def get_ancestry(self, revision_id, topo_sorted=True):
136
 
        """See Repository.get_ancestry().
 
284
    def get_known_graph_ancestry(self, revision_ids):
 
285
        """Return the known graph for a set of revision ids and their ancestors.
137
286
        """
138
 
        if revision_id is None:
139
 
            return self._all_revision_ids()
140
 
        assert isinstance(revision_id, str)
141
 
        ancestry = []
142
 
        graph = self.get_graph()
143
 
        for rev, parents in graph.iter_ancestry([revision_id]):
144
 
            if rev == revision.NULL_REVISION:
145
 
                rev = None
146
 
            ancestry.append(rev)
147
 
        ancestry.reverse()
148
 
        return ancestry
 
287
        pending = set(revision_ids)
 
288
        parent_map = {}
 
289
        while pending:
 
290
            this_parent_map = self.get_parent_map(pending)
 
291
            parent_map.update(this_parent_map)
 
292
            pending = set()
 
293
            map(pending.update, this_parent_map.itervalues())
 
294
            pending = pending.difference(parent_map)
 
295
        return _mod_graph.KnownGraph(parent_map)
149
296
 
150
297
    def get_signature_text(self, revision_id):
151
298
        raise errors.NoSuchRevision(self, revision_id)
152
299
 
153
 
    def lookup_revision_id(self, revid):
 
300
    def check(self, revision_ids=None, callback_refs=None, check_repo=True):
 
301
        result = GitCheck(self, check_repo=check_repo)
 
302
        result.check(callback_refs)
 
303
        return result
 
304
 
 
305
    def pack(self, hint=None, clean_obsolete_packs=False):
 
306
        self._git.object_store.pack_loose_objects()
 
307
 
 
308
    def lookup_foreign_revision_id(self, foreign_revid, mapping=None):
154
309
        """Lookup a revision id.
155
 
        
156
 
        :param revid: Bazaar revision id.
157
 
        :return: Tuple with git revisionid and mapping.
 
310
 
158
311
        """
159
 
        # Yes, this doesn't really work, but good enough as a stub
160
 
        return osutils.sha(rev_id).hexdigest(), self.get_mapping()
 
312
        assert type(foreign_revid) is str
 
313
        if mapping is None:
 
314
            mapping = self.get_mapping()
 
315
        if foreign_revid == ZERO_SHA:
 
316
            return revision.NULL_REVISION
 
317
        commit = self._git.object_store[foreign_revid]
 
318
        while isinstance(commit, Tag):
 
319
            commit = self._git[commit.object[1]]
 
320
        rev, roundtrip_revid, verifiers = mapping.import_commit(commit,
 
321
            mapping.revision_id_foreign_to_bzr)
 
322
        # FIXME: check testament before doing this?
 
323
        if roundtrip_revid:
 
324
            return roundtrip_revid
 
325
        else:
 
326
            return rev.revision_id
161
327
 
162
328
    def has_signature_for_revision_id(self, revision_id):
163
329
        return False
164
330
 
165
 
    def lookup_git_revid(self, bzr_revid, mapping):
 
331
    def lookup_bzr_revision_id(self, bzr_revid, mapping=None):
166
332
        try:
167
 
            return mapping.revision_id_bzr_to_foreign(bzr_revid)
 
333
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
168
334
        except errors.InvalidRevisionId:
169
 
            raise errors.NoSuchRevision(self, bzr_revid)
 
335
            if mapping is None:
 
336
                mapping = self.get_mapping()
 
337
            try:
 
338
                return (self._git.refs[mapping.revid_as_refname(bzr_revid)],
 
339
                        mapping)
 
340
            except KeyError:
 
341
                # Update refs from Git commit objects
 
342
                # FIXME: Hitting this a lot will be very inefficient...
 
343
                for git_sha, revid, roundtrip_revid in self._iter_revision_ids():
 
344
                    if not roundtrip_revid:
 
345
                        continue
 
346
                    refname = mapping.revid_as_refname(roundtrip_revid)
 
347
                    self._git.refs[refname] = git_sha
 
348
                    if roundtrip_revid == bzr_revid:
 
349
                        return git_sha, mapping
 
350
                raise errors.NoSuchRevision(self, bzr_revid)
170
351
 
171
352
    def get_revision(self, revision_id):
172
 
        git_commit_id = self.lookup_git_revid(revision_id, self.get_mapping())
 
353
        if not isinstance(revision_id, str):
 
354
            raise errors.InvalidRevisionId(revision_id, self)
 
355
        git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
173
356
        try:
174
 
            commit = self._git.commit(git_commit_id)
 
357
            commit = self._git[git_commit_id]
175
358
        except KeyError:
176
359
            raise errors.NoSuchRevision(self, revision_id)
177
 
        # print "fetched revision:", git_commit_id
178
 
        revision = self.get_mapping().import_commit(commit)
 
360
        revision, roundtrip_revid, verifiers = mapping.import_commit(
 
361
            commit, self.lookup_foreign_revision_id)
179
362
        assert revision is not None
 
363
        # FIXME: check verifiers ?
 
364
        if roundtrip_revid:
 
365
            revision.revision_id = roundtrip_revid
180
366
        return revision
181
367
 
182
368
    def has_revision(self, revision_id):
 
369
        """See Repository.has_revision."""
 
370
        if revision_id == revision.NULL_REVISION:
 
371
            return True
183
372
        try:
184
 
            self.get_revision(revision_id)
 
373
            git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
185
374
        except errors.NoSuchRevision:
186
375
            return False
187
 
        else:
188
 
            return True
 
376
        return (git_commit_id in self._git)
 
377
 
 
378
    def has_revisions(self, revision_ids):
 
379
        """See Repository.has_revisions."""
 
380
        return set(filter(self.has_revision, revision_ids))
189
381
 
190
382
    def get_revisions(self, revids):
 
383
        """See Repository.get_revisions."""
191
384
        return [self.get_revision(r) for r in revids]
192
385
 
193
386
    def revision_trees(self, revids):
 
387
        """See Repository.revision_trees."""
194
388
        for revid in revids:
195
389
            yield self.revision_tree(revid)
196
390
 
197
391
    def revision_tree(self, revision_id):
 
392
        """See Repository.revision_tree."""
198
393
        revision_id = revision.ensure_null(revision_id)
199
 
 
200
394
        if revision_id == revision.NULL_REVISION:
201
395
            inv = inventory.Inventory(root_id=None)
202
396
            inv.revision_id = revision_id
203
 
            return revisiontree.RevisionTree(self, inv, revision_id)
204
 
 
205
 
        return GitRevisionTree(self, self.get_mapping(), revision_id)
 
397
            return InventoryRevisionTree(self, inv, revision_id)
 
398
        return GitRevisionTree(self, revision_id)
206
399
 
207
400
    def get_inventory(self, revision_id):
208
 
        assert revision_id != None
209
 
        return self.revision_tree(revision_id).inventory
 
401
        raise NotImplementedError(self.get_inventory)
210
402
 
211
403
    def set_make_working_trees(self, trees):
212
 
        pass
 
404
        raise errors.UnsupportedOperation(self.set_make_working_trees, self)
 
405
        # TODO: Set bare= in the configuration bug=777065
213
406
 
214
 
    def fetch_objects(self, determine_wants, graph_walker, progress=None):
 
407
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
 
408
        progress=None):
215
409
        return self._git.fetch_objects(determine_wants, graph_walker, progress)
216
410
 
217
411
 
218
 
class GitRevisionTree(revisiontree.RevisionTree):
219
 
 
220
 
    def __init__(self, repository, mapping, revision_id):
221
 
        self._repository = repository
222
 
        self.revision_id = revision_id
223
 
        assert isinstance(revision_id, str)
224
 
        self.mapping = mapping
225
 
        git_id = repository.lookup_git_revid(revision_id, self.mapping)
226
 
        try:
227
 
            commit = repository._git.commit(git_id)
228
 
        except KeyError, r:
229
 
            raise errors.NoSuchRevision(repository, revision_id)
230
 
        self.tree = commit.tree
231
 
        self._inventory = inventory.Inventory(revision_id=revision_id)
232
 
        self._inventory.root.revision = revision_id
233
 
        self._build_inventory(self.tree, self._inventory.root, "")
234
 
 
235
 
    def get_revision_id(self):
236
 
        return self.revision_id
237
 
 
238
 
    def get_file_text(self, file_id):
239
 
        entry = self._inventory[file_id]
240
 
        if entry.kind == 'directory': return ""
241
 
        return self._repository._git.get_blob(entry.text_id).data
242
 
 
243
 
    def _build_inventory(self, tree_id, ie, path):
244
 
        assert isinstance(path, str)
245
 
        tree = self._repository._git.tree(tree_id)
246
 
        for mode, name, hexsha in tree.entries():
247
 
            basename = name.decode("utf-8")
248
 
            if path == "":
249
 
                child_path = name
250
 
            else:
251
 
                child_path = urlutils.join(path, name)
252
 
            file_id = self.mapping.generate_file_id(child_path)
253
 
            entry_kind = (mode & 0700000) / 0100000
254
 
            if entry_kind == 0:
255
 
                child_ie = inventory.InventoryDirectory(file_id, basename, ie.file_id)
256
 
            elif entry_kind == 1:
257
 
                file_kind = (mode & 070000) / 010000
258
 
                b = self._repository._git.get_blob(hexsha)
259
 
                if file_kind == 0:
260
 
                    child_ie = inventory.InventoryFile(file_id, basename, ie.file_id)
261
 
                    child_ie.text_sha1 = osutils.sha_string(b.data)
262
 
                elif file_kind == 2:
263
 
                    child_ie = inventory.InventoryLink(file_id, basename, ie.file_id)
264
 
                    child_ie.text_sha1 = osutils.sha_string("")
265
 
                else:
266
 
                    raise AssertionError(
267
 
                        "Unknown file kind, perms=%o." % (mode,))
268
 
                child_ie.text_id = b.id
269
 
                child_ie.text_size = len(b.data)
270
 
            else:
271
 
                raise AssertionError(
272
 
                    "Unknown blob kind, perms=%r." % (mode,))
273
 
            fs_mode = mode & 0777
274
 
            child_ie.executable = bool(fs_mode & 0111)
275
 
            child_ie.revision = self.revision_id
276
 
            self._inventory.add(child_ie)
277
 
            if entry_kind == 0:
278
 
                self._build_inventory(hexsha, child_ie, child_path)
279
 
 
280
 
 
281
 
class GitFormat(object):
282
 
 
 
412
class GitRepositoryFormat(repository.RepositoryFormat):
 
413
    """Git repository format."""
 
414
 
 
415
    supports_versioned_directories = False
283
416
    supports_tree_reference = False
284
417
    rich_root_data = True
 
418
    supports_leaving_lock = False
 
419
    fast_deltas = True
 
420
    supports_funky_characters = True
 
421
    supports_external_lookups = False
 
422
    supports_full_versioned_files = False
 
423
    supports_revision_signatures = False
 
424
    revision_graph_can_have_wrong_parents = False
 
425
 
 
426
    @property
 
427
    def _matchingbzrdir(self):
 
428
        from bzrlib.plugins.git.dir import LocalGitControlDirFormat
 
429
        return LocalGitControlDirFormat()
285
430
 
286
431
    def get_format_description(self):
287
432
        return "Git Repository"
288
433
 
289
 
    def initialize(self, url, shared=False, _internal=False):
290
 
        raise bzr_errors.UninitializableFormat(self)
 
434
    def initialize(self, controldir, shared=False, _internal=False):
 
435
        from bzrlib.plugins.git.dir import GitDir
 
436
        if not isinstance(controldir, GitDir):
 
437
            raise errors.UninitializableFormat(self)
 
438
        return controldir.open_repository()
291
439
 
292
440
    def check_conversion_target(self, target_repo_format):
293
441
        return target_repo_format.rich_root_data
 
442
 
 
443
    def get_foreign_tests_repository_factory(self):
 
444
        from bzrlib.plugins.git.tests.test_repository import (
 
445
            ForeignTestsRepositoryFactory,
 
446
            )
 
447
        return ForeignTestsRepositoryFactory()
 
448
 
 
449
    def network_name(self):
 
450
        return "git"