/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

Some fixes for colocated branch handling.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""An adapter between a Git Repository and a Bazaar Branch"""
19
19
 
20
20
from bzrlib import (
 
21
    check,
21
22
    errors,
 
23
    graph as _mod_graph,
22
24
    inventory,
23
25
    repository,
24
26
    revision,
25
 
    revisiontree,
 
27
    transactions,
 
28
    version_info as bzrlib_version,
26
29
    )
 
30
from bzrlib.decorators import only_raises
 
31
from bzrlib.revisiontree import InventoryRevisionTree
27
32
from bzrlib.foreign import (
28
33
    ForeignRepository,
29
34
    )
31
36
from bzrlib.plugins.git.commit import (
32
37
    GitCommitBuilder,
33
38
    )
 
39
from bzrlib.plugins.git.errors import (
 
40
    NotCommitError,
 
41
    )
 
42
from bzrlib.plugins.git.filegraph import (
 
43
    GitFileLastChangeScanner,
 
44
    GitFileParentProvider,
 
45
    )
34
46
from bzrlib.plugins.git.mapping import (
35
47
    default_mapping,
36
 
    foreign_git,
 
48
    foreign_vcs_git,
37
49
    mapping_registry,
38
50
    )
39
51
from bzrlib.plugins.git.tree import (
40
52
    GitRevisionTree,
41
53
    )
42
 
from bzrlib.plugins.git.versionedfiles import (
43
 
    GitRevisions,
44
 
    GitTexts,
45
 
    )
46
54
 
47
55
 
48
56
from dulwich.objects import (
49
57
    Commit,
50
 
    )
 
58
    ZERO_SHA,
 
59
    )
 
60
from dulwich.object_store import (
 
61
    tree_lookup_path,
 
62
    )
 
63
 
 
64
 
 
65
class RepoReconciler(object):
 
66
    """Reconciler that reconciles a repository.
 
67
 
 
68
    """
 
69
 
 
70
    def __init__(self, repo, other=None, thorough=False):
 
71
        """Construct a RepoReconciler.
 
72
 
 
73
        :param thorough: perform a thorough check which may take longer but
 
74
                         will correct non-data loss issues such as incorrect
 
75
                         cached data.
 
76
        """
 
77
        self.repo = repo
 
78
 
 
79
    def reconcile(self):
 
80
        """Perform reconciliation.
 
81
 
 
82
        After reconciliation the following attributes document found issues:
 
83
        inconsistent_parents: The number of revisions in the repository whose
 
84
                              ancestry was being reported incorrectly.
 
85
        garbage_inventories: The number of inventory objects without revisions
 
86
                             that were garbage collected.
 
87
        """
 
88
 
 
89
 
 
90
class GitCheck(check.Check):
 
91
 
 
92
    def __init__(self, repository, check_repo=True):
 
93
        self.repository = repository
 
94
        self.checked_rev_cnt = 0
 
95
 
 
96
    def check(self, callback_refs=None, check_repo=True):
 
97
        if callback_refs is None:
 
98
            callback_refs = {}
 
99
        self.repository.lock_read()
 
100
        self.repository.unlock()
 
101
 
 
102
    def report_results(self, verbose):
 
103
        pass
 
104
 
 
105
 
 
106
_optimisers_loaded = False
 
107
 
 
108
def lazy_load_optimisers():
 
109
    global _optimisers_loaded
 
110
    if _optimisers_loaded:
 
111
        return
 
112
    from bzrlib.plugins.git import fetch, push
 
113
    for optimiser in [fetch.InterRemoteGitNonGitRepository,
 
114
                      fetch.InterLocalGitNonGitRepository,
 
115
                      fetch.InterGitGitRepository,
 
116
                      push.InterToLocalGitRepository,
 
117
                      push.InterToRemoteGitRepository]:
 
118
        repository.InterRepository.register_optimiser(optimiser)
 
119
    _optimisers_loaded = True
51
120
 
52
121
 
53
122
class GitRepository(ForeignRepository):
54
123
    """An adapter to git repositories for bzr."""
55
124
 
56
125
    _serializer = None
57
 
    _commit_builder_class = GitCommitBuilder
58
 
    vcs = foreign_git
59
 
 
60
 
    def __init__(self, gitdir, lockfiles):
61
 
        ForeignRepository.__init__(self, GitRepositoryFormat(), gitdir,
62
 
            lockfiles)
63
 
        from bzrlib.plugins.git import fetch, push
64
 
        for optimiser in [fetch.InterRemoteGitNonGitRepository,
65
 
                          fetch.InterLocalGitNonGitRepository,
66
 
                          fetch.InterGitGitRepository,
67
 
                          push.InterToLocalGitRepository,
68
 
                          push.InterToRemoteGitRepository]:
69
 
            repository.InterRepository.register_optimiser(optimiser)
 
126
    vcs = foreign_vcs_git
 
127
    chk_bytes = None
 
128
 
 
129
    def __init__(self, gitdir):
 
130
        if bzrlib_version >= (2, 5):
 
131
            control_files = None
 
132
        else:
 
133
            class DummyControlFiles(object):
 
134
                def __init__(self):
 
135
                    self._transport = gitdir.root_transport
 
136
            control_files = DummyControlFiles()
 
137
        self._transport = gitdir.root_transport
 
138
        super(GitRepository, self).__init__(GitRepositoryFormat(),
 
139
            gitdir, control_files)
 
140
        self.base = gitdir.root_transport.base
 
141
        lazy_load_optimisers()
 
142
        self._lock_mode = None
 
143
        self._lock_count = 0
 
144
 
 
145
    def add_fallback_repository(self, basis_url):
 
146
        raise errors.UnstackableRepositoryFormat(self._format,
 
147
            self.control_transport.base)
70
148
 
71
149
    def is_shared(self):
72
150
        return False
73
151
 
 
152
    def get_physical_lock_status(self):
 
153
        return False
 
154
 
 
155
    def lock_write(self):
 
156
        """See Branch.lock_write()."""
 
157
        if self._lock_mode:
 
158
            assert self._lock_mode == 'w'
 
159
            self._lock_count += 1
 
160
        else:
 
161
            self._lock_mode = 'w'
 
162
            self._lock_count = 1
 
163
        return GitRepositoryLock(self)
 
164
 
 
165
    def break_lock(self):
 
166
        raise NotImplementedError(self.break_lock)
 
167
 
 
168
    def dont_leave_lock_in_place(self):
 
169
        raise NotImplementedError(self.dont_leave_lock_in_place)
 
170
 
 
171
    def leave_lock_in_place(self):
 
172
        raise NotImplementedError(self.leave_lock_in_place)
 
173
 
 
174
    def lock_read(self):
 
175
        if self._lock_mode:
 
176
            assert self._lock_mode in ('r', 'w')
 
177
            self._lock_count += 1
 
178
        else:
 
179
            self._lock_mode = 'r'
 
180
            self._lock_count = 1
 
181
        return self
 
182
 
 
183
    @only_raises(errors.LockNotHeld, errors.LockBroken)
 
184
    def unlock(self):
 
185
        if self._lock_count == 0:
 
186
            raise errors.LockNotHeld(self)
 
187
        if self._lock_count == 1 and self._lock_mode == 'w':
 
188
            if self._write_group is not None:
 
189
                self.abort_write_group()
 
190
                self._lock_count -= 1
 
191
                self._lock_mode = None
 
192
                raise errors.BzrError(
 
193
                    'Must end write groups before releasing write locks.')
 
194
        self._lock_count -= 1
 
195
        if self._lock_count == 0:
 
196
            self._lock_mode = None
 
197
 
 
198
    def is_write_locked(self):
 
199
        return (self._lock_mode == 'w')
 
200
 
 
201
    def is_locked(self):
 
202
        return (self._lock_mode is not None)
 
203
 
 
204
    def get_transaction(self):
 
205
        """See Repository.get_transaction()."""
 
206
        if self._write_group is None:
 
207
            return transactions.PassThroughTransaction()
 
208
        else:
 
209
            return self._write_group
 
210
 
 
211
    def reconcile(self, other=None, thorough=False):
 
212
        """Reconcile this repository."""
 
213
        reconciler = RepoReconciler(self, thorough=thorough)
 
214
        reconciler.reconcile()
 
215
        return reconciler
 
216
 
74
217
    def supports_rich_root(self):
75
218
        return True
76
219
 
77
 
    def _warn_if_deprecated(self, branch=None):
78
 
        # This class isn't deprecated
79
 
        pass
80
 
 
81
220
    def get_mapping(self):
82
221
        return default_mapping
83
222
 
84
223
    def make_working_trees(self):
85
 
        return not self._git.bare
 
224
        return not self._git.get_config().get_boolean(("core", ), "bare")
86
225
 
87
226
    def revision_graph_can_have_wrong_parents(self):
88
227
        return False
89
228
 
90
 
    def dfetch(self, source, stop_revision):
91
 
        interrepo = repository.InterRepository.get(source, self)
92
 
        return interrepo.dfetch(stop_revision)
 
229
    def add_signature_text(self, revid, signature):
 
230
        raise errors.UnsupportedOperation(self.add_signature_text, self)
 
231
 
 
232
    def sign_revision(self, revision_id, gpg_strategy):
 
233
        raise errors.UnsupportedOperation(self.add_signature_text, self)
 
234
 
 
235
 
 
236
class GitRepositoryLock(object):
 
237
    """Subversion lock."""
 
238
 
 
239
    def __init__(self, repository):
 
240
        self.repository_token = None
 
241
        self.repository = repository
 
242
 
 
243
    def unlock(self):
 
244
        self.repository.unlock()
93
245
 
94
246
 
95
247
class LocalGitRepository(GitRepository):
96
248
    """Git repository on the file system."""
97
249
 
98
 
    def __init__(self, gitdir, lockfiles):
99
 
        GitRepository.__init__(self, gitdir, lockfiles)
100
 
        self.base = gitdir.root_transport.base
 
250
    def __init__(self, gitdir):
 
251
        GitRepository.__init__(self, gitdir)
101
252
        self._git = gitdir._git
102
 
        self.signatures = None
103
 
        self.revisions = GitRevisions(self, self._git.object_store)
104
 
        self.inventories = None
105
 
        self.texts = GitTexts(self)
 
253
        self._file_change_scanner = GitFileLastChangeScanner(self)
 
254
 
 
255
    def get_commit_builder(self, branch, parents, config, timestamp=None,
 
256
                           timezone=None, committer=None, revprops=None,
 
257
                           revision_id=None, lossy=False):
 
258
        """Obtain a CommitBuilder for this repository.
 
259
 
 
260
        :param branch: Branch to commit to.
 
261
        :param parents: Revision ids of the parents of the new revision.
 
262
        :param config: Configuration to use.
 
263
        :param timestamp: Optional timestamp recorded for commit.
 
264
        :param timezone: Optional timezone for timestamp.
 
265
        :param committer: Optional committer to set for commit.
 
266
        :param revprops: Optional dictionary of revision properties.
 
267
        :param revision_id: Optional revision id.
 
268
        :param lossy: Whether to discard data that can not be natively
 
269
            represented, when pushing to a foreign VCS
 
270
        """
 
271
        self.start_write_group()
 
272
        return GitCommitBuilder(self, parents, config,
 
273
            timestamp, timezone, committer, revprops, revision_id,
 
274
            lossy)
 
275
 
 
276
    def get_file_graph(self):
 
277
        return _mod_graph.Graph(GitFileParentProvider(
 
278
            self._file_change_scanner))
 
279
 
 
280
    def iter_files_bytes(self, desired_files):
 
281
        """Iterate through file versions.
 
282
 
 
283
        Files will not necessarily be returned in the order they occur in
 
284
        desired_files.  No specific order is guaranteed.
 
285
 
 
286
        Yields pairs of identifier, bytes_iterator.  identifier is an opaque
 
287
        value supplied by the caller as part of desired_files.  It should
 
288
        uniquely identify the file version in the caller's context.  (Examples:
 
289
        an index number or a TreeTransform trans_id.)
 
290
 
 
291
        bytes_iterator is an iterable of bytestrings for the file.  The
 
292
        kind of iterable and length of the bytestrings are unspecified, but for
 
293
        this implementation, it is a list of bytes produced by
 
294
        VersionedFile.get_record_stream().
 
295
 
 
296
        :param desired_files: a list of (file_id, revision_id, identifier)
 
297
            triples
 
298
        """
 
299
        per_revision = {}
 
300
        for (file_id, revision_id, identifier) in desired_files:
 
301
            per_revision.setdefault(revision_id, []).append(
 
302
                (file_id, identifier))
 
303
        for revid, files in per_revision.iteritems():
 
304
            (commit_id, mapping) = self.lookup_bzr_revision_id(revid)
 
305
            try:
 
306
                commit = self._git.object_store[commit_id]
 
307
            except KeyError:
 
308
                raise errors.RevisionNotPresent(revid, self)
 
309
            root_tree = commit.tree
 
310
            for fileid, identifier in files:
 
311
                path = mapping.parse_file_id(fileid)
 
312
                try:
 
313
                    obj = tree_lookup_path(
 
314
                        self._git.object_store.__getitem__, root_tree, path)
 
315
                    if isinstance(obj, tuple):
 
316
                        (mode, item_id) = obj
 
317
                        obj = self._git.object_store[item_id]
 
318
                except KeyError:
 
319
                    raise errors.RevisionNotPresent((fileid, revid), self)
 
320
                else:
 
321
                    if obj.type_name == "tree":
 
322
                        yield (identifier, [])
 
323
                    elif obj.type_name == "blob":
 
324
                        yield (identifier, obj.chunked)
 
325
                    else:
 
326
                        raise AssertionError("file text resolved to %r" % obj)
 
327
 
 
328
    def gather_stats(self, revid=None, committers=None):
 
329
        """See Repository.gather_stats()."""
 
330
        result = super(LocalGitRepository, self).gather_stats(revid, committers)
 
331
        revs = []
 
332
        for sha in self._git.object_store:
 
333
            o = self._git.object_store[sha]
 
334
            if o.type_name == "commit":
 
335
                revs.append(o.id)
 
336
        result['revisions'] = len(revs)
 
337
        return result
106
338
 
107
339
    def _iter_revision_ids(self):
108
340
        mapping = self.get_mapping()
111
343
            if not isinstance(o, Commit):
112
344
                continue
113
345
            rev, roundtrip_revid, verifiers = mapping.import_commit(o,
114
 
                self.lookup_foreign_revision_id)
 
346
                mapping.revision_id_foreign_to_bzr)
115
347
            yield o.id, rev.revision_id, roundtrip_revid
116
348
 
117
349
    def all_revision_ids(self):
118
350
        ret = set([])
119
351
        for git_sha, revid, roundtrip_revid in self._iter_revision_ids():
120
 
            ret.add(revid)
121
352
            if roundtrip_revid:
122
353
                ret.add(roundtrip_revid)
 
354
            else:
 
355
                ret.add(revid)
123
356
        return ret
124
357
 
125
 
    def get_parent_map(self, revids):
 
358
    def _get_parents(self, revid, no_alternates=False):
 
359
        if type(revid) != str:
 
360
            raise ValueError
 
361
        try:
 
362
            (hexsha, mapping) = self.lookup_bzr_revision_id(revid)
 
363
        except errors.NoSuchRevision:
 
364
            return None
 
365
        # FIXME: Honor no_alternates setting
 
366
        try:
 
367
            commit = self._git.object_store[hexsha]
 
368
        except KeyError:
 
369
            return None
 
370
        return [
 
371
            self.lookup_foreign_revision_id(p, mapping)
 
372
            for p in commit.parents]
 
373
 
 
374
    def _get_parent_map_no_fallbacks(self, revids):
 
375
        return self.get_parent_map(revids, no_alternates=True)
 
376
 
 
377
    def get_parent_map(self, revids, no_alternates=False):
126
378
        parent_map = {}
127
379
        for revision_id in revids:
128
 
            assert isinstance(revision_id, str)
 
380
            parents = self._get_parents(revision_id, no_alternates=no_alternates)
129
381
            if revision_id == revision.NULL_REVISION:
130
382
                parent_map[revision_id] = ()
131
383
                continue
132
 
            hexsha, mapping = self.lookup_bzr_revision_id(revision_id)
133
 
            try:
134
 
                commit = self._git[hexsha]
135
 
            except KeyError:
 
384
            if parents is None:
136
385
                continue
137
 
            parent_map[revision_id] = [
138
 
                self.lookup_foreign_revision_id(p, mapping)
139
 
                for p in commit.parents]
 
386
            if len(parents) == 0:
 
387
                parents = [revision.NULL_REVISION]
 
388
            parent_map[revision_id] = tuple(parents)
140
389
        return parent_map
141
390
 
142
 
    def get_ancestry(self, revision_id, topo_sorted=True):
143
 
        """See Repository.get_ancestry().
 
391
    def get_known_graph_ancestry(self, revision_ids):
 
392
        """Return the known graph for a set of revision ids and their ancestors.
144
393
        """
145
 
        if revision_id is None:
146
 
            return [None, revision.NULL_REVISION] + self._all_revision_ids()
147
 
        assert isinstance(revision_id, str)
148
 
        ancestry = []
149
 
        graph = self.get_graph()
150
 
        for rev, parents in graph.iter_ancestry([revision_id]):
151
 
            ancestry.append(rev)
152
 
        ancestry.reverse()
153
 
        return [None] + ancestry
 
394
        pending = set(revision_ids)
 
395
        parent_map = {}
 
396
        while pending:
 
397
            this_parent_map = {}
 
398
            for revid in pending:
 
399
                if revid == revision.NULL_REVISION:
 
400
                    continue
 
401
                parents = self._get_parents(revid)
 
402
                if parents is not None:
 
403
                    this_parent_map[revid] = parents
 
404
            parent_map.update(this_parent_map)
 
405
            pending = set()
 
406
            map(pending.update, this_parent_map.itervalues())
 
407
            pending = pending.difference(parent_map)
 
408
        return _mod_graph.KnownGraph(parent_map)
154
409
 
155
410
    def get_signature_text(self, revision_id):
156
411
        raise errors.NoSuchRevision(self, revision_id)
157
412
 
 
413
    def check(self, revision_ids=None, callback_refs=None, check_repo=True):
 
414
        result = GitCheck(self, check_repo=check_repo)
 
415
        result.check(callback_refs)
 
416
        return result
 
417
 
158
418
    def pack(self, hint=None, clean_obsolete_packs=False):
159
419
        self._git.object_store.pack_loose_objects()
160
420
 
161
421
    def lookup_foreign_revision_id(self, foreign_revid, mapping=None):
162
422
        """Lookup a revision id.
163
423
 
 
424
        :param foreign_revid: Foreign revision id to look up
 
425
        :param mapping: Mapping to use (use default mapping if not specified)
 
426
        :raise KeyError: If foreign revision was not found
 
427
        :return: bzr revision id
164
428
        """
165
429
        assert type(foreign_revid) is str
166
430
        if mapping is None:
167
431
            mapping = self.get_mapping()
168
 
        from dulwich.protocol import (
169
 
            ZERO_SHA,
170
 
            )
171
432
        if foreign_revid == ZERO_SHA:
172
433
            return revision.NULL_REVISION
173
 
        commit = self._git[foreign_revid]
 
434
        commit = self._git.object_store.peel_sha(foreign_revid)
 
435
        if not isinstance(commit, Commit):
 
436
            raise NotCommitError(commit.id)
174
437
        rev, roundtrip_revid, verifiers = mapping.import_commit(commit,
175
 
            lambda x: None)
 
438
            mapping.revision_id_foreign_to_bzr)
176
439
        # FIXME: check testament before doing this?
177
440
        if roundtrip_revid:
178
441
            return roundtrip_revid
180
443
            return rev.revision_id
181
444
 
182
445
    def has_signature_for_revision_id(self, revision_id):
 
446
        """Check whether a GPG signature is present for this revision.
 
447
 
 
448
        This is never the case for Git repositories.
 
449
        """
183
450
        return False
184
451
 
185
452
    def lookup_bzr_revision_id(self, bzr_revid, mapping=None):
 
453
        """Lookup a bzr revision id in a Git repository.
 
454
 
 
455
        :param bzr_revid: Bazaar revision id
 
456
        :param mapping: Optional mapping to use
 
457
        :return: Tuple with git commit id, mapping that was used and supplement
 
458
            details
 
459
        """
186
460
        try:
187
 
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
 
461
            (git_sha, mapping) = mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
188
462
        except errors.InvalidRevisionId:
189
463
            if mapping is None:
190
464
                mapping = self.get_mapping()
202
476
                    if roundtrip_revid == bzr_revid:
203
477
                        return git_sha, mapping
204
478
                raise errors.NoSuchRevision(self, bzr_revid)
 
479
        else:
 
480
            return (git_sha, mapping)
205
481
 
206
482
    def get_revision(self, revision_id):
 
483
        if not isinstance(revision_id, str):
 
484
            raise errors.InvalidRevisionId(revision_id, self)
207
485
        git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
208
486
        try:
209
 
            commit = self._git[git_commit_id]
 
487
            commit = self._git.object_store[git_commit_id]
210
488
        except KeyError:
211
489
            raise errors.NoSuchRevision(self, revision_id)
212
490
        revision, roundtrip_revid, verifiers = mapping.import_commit(
218
496
        return revision
219
497
 
220
498
    def has_revision(self, revision_id):
 
499
        """See Repository.has_revision."""
 
500
        if revision_id == revision.NULL_REVISION:
 
501
            return True
221
502
        try:
222
503
            git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
223
504
        except errors.NoSuchRevision:
225
506
        return (git_commit_id in self._git)
226
507
 
227
508
    def has_revisions(self, revision_ids):
 
509
        """See Repository.has_revisions."""
228
510
        return set(filter(self.has_revision, revision_ids))
229
511
 
230
512
    def get_revisions(self, revids):
 
513
        """See Repository.get_revisions."""
231
514
        return [self.get_revision(r) for r in revids]
232
515
 
233
516
    def revision_trees(self, revids):
 
517
        """See Repository.revision_trees."""
234
518
        for revid in revids:
235
519
            yield self.revision_tree(revid)
236
520
 
237
521
    def revision_tree(self, revision_id):
 
522
        """See Repository.revision_tree."""
238
523
        revision_id = revision.ensure_null(revision_id)
239
524
        if revision_id == revision.NULL_REVISION:
240
525
            inv = inventory.Inventory(root_id=None)
241
526
            inv.revision_id = revision_id
242
 
            return revisiontree.RevisionTree(self, inv, revision_id)
 
527
            return InventoryRevisionTree(self, inv, revision_id)
243
528
        return GitRevisionTree(self, revision_id)
244
529
 
245
530
    def get_inventory(self, revision_id):
246
 
        assert revision_id != None
247
 
        return self.revision_tree(revision_id).inventory
 
531
        raise NotImplementedError(self.get_inventory)
248
532
 
249
533
    def set_make_working_trees(self, trees):
250
 
        pass
 
534
        if trees:
 
535
            self._git.get_config().set(("core", ), "bare", "false")
 
536
        else:
 
537
            self._git.get_config().set(("core", ), "bare", "true")
251
538
 
252
539
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
253
540
        progress=None):
254
541
        return self._git.fetch_objects(determine_wants, graph_walker, progress)
255
542
 
256
 
    def _get_versioned_file_checker(self, text_key_references=None,
257
 
                        ancestors=None):
258
 
        return GitVersionedFileChecker(self,
259
 
            text_key_references=text_key_references, ancestors=ancestors)
260
 
 
261
 
 
262
 
class GitVersionedFileChecker(repository._VersionedFileChecker):
263
 
 
264
 
    file_ids = []
265
 
 
266
 
    def _check_file_version_parents(self, texts, progress_bar):
267
 
        return {}, []
268
 
 
269
543
 
270
544
class GitRepositoryFormat(repository.RepositoryFormat):
271
545
    """Git repository format."""
272
546
 
 
547
    supports_versioned_directories = False
273
548
    supports_tree_reference = False
274
549
    rich_root_data = True
 
550
    supports_leaving_lock = False
 
551
    fast_deltas = True
 
552
    supports_funky_characters = True
 
553
    supports_external_lookups = False
 
554
    supports_full_versioned_files = False
 
555
    supports_revision_signatures = False
 
556
    supports_nesting_repositories = False
 
557
    revision_graph_can_have_wrong_parents = False
 
558
    supports_unreferenced_revisions = True
 
559
 
 
560
    @property
 
561
    def _matchingbzrdir(self):
 
562
        from bzrlib.plugins.git.dir import LocalGitControlDirFormat
 
563
        return LocalGitControlDirFormat()
275
564
 
276
565
    def get_format_description(self):
277
566
        return "Git Repository"
278
567
 
279
 
    def initialize(self, url, shared=False, _internal=False):
280
 
        raise errors.UninitializableFormat(self)
 
568
    def initialize(self, controldir, shared=False, _internal=False):
 
569
        from bzrlib.plugins.git.dir import GitDir
 
570
        if not isinstance(controldir, GitDir):
 
571
            raise errors.UninitializableFormat(self)
 
572
        return controldir.open_repository()
281
573
 
282
574
    def check_conversion_target(self, target_repo_format):
283
575
        return target_repo_format.rich_root_data