/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

  • Committer: Jelmer Vernooij
  • Date: 2018-03-28 01:51:03 UTC
  • mto: (0.200.1902 work)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180328015103-1zev7bdm87yzo90m
Support reading .git files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008-2018 Jelmer Vernooij <jelmer@jelmer.uk>
 
2
# Copyright (C) 2007 Canonical Ltd
 
3
#
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
17
 
 
18
"""An adapter between a Git Repository and a Bazaar Branch"""
 
19
 
 
20
from __future__ import absolute_import
 
21
 
 
22
from ... import (
 
23
    check,
 
24
    errors,
 
25
    graph as _mod_graph,
 
26
    lock,
 
27
    repository,
 
28
    revision as _mod_revision,
 
29
    transactions,
 
30
    ui,
 
31
    version_info as breezy_version,
 
32
    )
 
33
from ...decorators import only_raises
 
34
from ...foreign import (
 
35
    ForeignRepository,
 
36
    )
 
37
 
 
38
from .commit import (
 
39
    GitCommitBuilder,
 
40
    )
 
41
from .filegraph import (
 
42
    GitFileLastChangeScanner,
 
43
    GitFileParentProvider,
 
44
    )
 
45
from .mapping import (
 
46
    default_mapping,
 
47
    foreign_vcs_git,
 
48
    mapping_registry,
 
49
    )
 
50
from .tree import (
 
51
    GitRevisionTree,
 
52
    )
 
53
 
 
54
 
 
55
from dulwich.errors import (
 
56
    NotCommitError,
 
57
    )
 
58
from dulwich.objects import (
 
59
    Commit,
 
60
    ZERO_SHA,
 
61
    )
 
62
from dulwich.object_store import (
 
63
    tree_lookup_path,
 
64
    )
 
65
 
 
66
 
 
67
class RepoReconciler(object):
 
68
    """Reconciler that reconciles a repository.
 
69
 
 
70
    """
 
71
 
 
72
    def __init__(self, repo, other=None, thorough=False):
 
73
        """Construct a RepoReconciler.
 
74
 
 
75
        :param thorough: perform a thorough check which may take longer but
 
76
                         will correct non-data loss issues such as incorrect
 
77
                         cached data.
 
78
        """
 
79
        self.repo = repo
 
80
 
 
81
    def reconcile(self):
 
82
        """Perform reconciliation.
 
83
 
 
84
        After reconciliation the following attributes document found issues:
 
85
        inconsistent_parents: The number of revisions in the repository whose
 
86
                              ancestry was being reported incorrectly.
 
87
        garbage_inventories: The number of inventory objects without revisions
 
88
                             that were garbage collected.
 
89
        """
 
90
 
 
91
 
 
92
class GitCheck(check.Check):
 
93
 
 
94
    def __init__(self, repository, check_repo=True):
 
95
        self.repository = repository
 
96
        self.checked_rev_cnt = 0
 
97
 
 
98
    def check(self, callback_refs=None, check_repo=True):
 
99
        if callback_refs is None:
 
100
            callback_refs = {}
 
101
        with self.repository.lock_read():
 
102
            # TODO(jelmer): Check some things
 
103
            pass
 
104
 
 
105
    def report_results(self, verbose):
 
106
        pass
 
107
 
 
108
 
 
109
_optimisers_loaded = False
 
110
 
 
111
def lazy_load_optimisers():
 
112
    global _optimisers_loaded
 
113
    if _optimisers_loaded:
 
114
        return
 
115
    from . import fetch, push
 
116
    for optimiser in [fetch.InterRemoteGitNonGitRepository,
 
117
                      fetch.InterLocalGitNonGitRepository,
 
118
                      fetch.InterGitGitRepository,
 
119
                      push.InterToLocalGitRepository,
 
120
                      push.InterToRemoteGitRepository]:
 
121
        repository.InterRepository.register_optimiser(optimiser)
 
122
    _optimisers_loaded = True
 
123
 
 
124
 
 
125
class GitRepository(ForeignRepository):
 
126
    """An adapter to git repositories for bzr."""
 
127
 
 
128
    _serializer = None
 
129
    vcs = foreign_vcs_git
 
130
    chk_bytes = None
 
131
 
 
132
    def __init__(self, gitdir):
 
133
        self._transport = gitdir.root_transport
 
134
        super(GitRepository, self).__init__(GitRepositoryFormat(),
 
135
            gitdir, control_files=None)
 
136
        self.base = gitdir.root_transport.base
 
137
        lazy_load_optimisers()
 
138
        self._lock_mode = None
 
139
        self._lock_count = 0
 
140
 
 
141
    def add_fallback_repository(self, basis_url):
 
142
        raise errors.UnstackableRepositoryFormat(self._format,
 
143
            self.control_transport.base)
 
144
 
 
145
    def is_shared(self):
 
146
        return False
 
147
 
 
148
    def get_physical_lock_status(self):
 
149
        return False
 
150
 
 
151
    def lock_write(self):
 
152
        """See Branch.lock_write()."""
 
153
        if self._lock_mode:
 
154
            if self._lock_mode != 'w':
 
155
                raise errors.ReadOnlyError(self)
 
156
            self._lock_count += 1
 
157
        else:
 
158
            self._lock_mode = 'w'
 
159
            self._lock_count = 1
 
160
            self._transaction = transactions.WriteTransaction()
 
161
        return repository.RepositoryWriteLockResult(self.unlock, None)
 
162
 
 
163
    def break_lock(self):
 
164
        raise NotImplementedError(self.break_lock)
 
165
 
 
166
    def dont_leave_lock_in_place(self):
 
167
        raise NotImplementedError(self.dont_leave_lock_in_place)
 
168
 
 
169
    def leave_lock_in_place(self):
 
170
        raise NotImplementedError(self.leave_lock_in_place)
 
171
 
 
172
    def lock_read(self):
 
173
        if self._lock_mode:
 
174
            if self._lock_mode not in ('r', 'w'):
 
175
                raise AssertionError
 
176
            self._lock_count += 1
 
177
        else:
 
178
            self._lock_mode = 'r'
 
179
            self._lock_count = 1
 
180
            self._transaction = transactions.ReadOnlyTransaction()
 
181
        return lock.LogicalLockResult(self.unlock)
 
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
            transaction = self._transaction
 
198
            self._transaction = None
 
199
            transaction.finish()
 
200
 
 
201
    def is_write_locked(self):
 
202
        return (self._lock_mode == 'w')
 
203
 
 
204
    def is_locked(self):
 
205
        return (self._lock_mode is not None)
 
206
 
 
207
    def get_transaction(self):
 
208
        """See Repository.get_transaction()."""
 
209
        if self._transaction is None:
 
210
            return transactions.PassThroughTransaction()
 
211
        else:
 
212
            return self._transaction
 
213
 
 
214
    def reconcile(self, other=None, thorough=False):
 
215
        """Reconcile this repository."""
 
216
        reconciler = RepoReconciler(self, thorough=thorough)
 
217
        reconciler.reconcile()
 
218
        return reconciler
 
219
 
 
220
    def supports_rich_root(self):
 
221
        return True
 
222
 
 
223
    def get_mapping(self):
 
224
        return default_mapping
 
225
 
 
226
    def make_working_trees(self):
 
227
        return not self._git.get_config().get_boolean(("core", ), "bare")
 
228
 
 
229
    def revision_graph_can_have_wrong_parents(self):
 
230
        return False
 
231
 
 
232
    def add_signature_text(self, revid, signature):
 
233
        raise errors.UnsupportedOperation(self.add_signature_text, self)
 
234
 
 
235
    def sign_revision(self, revision_id, gpg_strategy):
 
236
        raise errors.UnsupportedOperation(self.add_signature_text, self)
 
237
 
 
238
 
 
239
class LocalGitRepository(GitRepository):
 
240
    """Git repository on the file system."""
 
241
 
 
242
    def __init__(self, gitdir):
 
243
        GitRepository.__init__(self, gitdir)
 
244
        self._git = gitdir._git
 
245
        self._file_change_scanner = GitFileLastChangeScanner(self)
 
246
        self._transaction = None
 
247
 
 
248
    def get_commit_builder(self, branch, parents, config, timestamp=None,
 
249
                           timezone=None, committer=None, revprops=None,
 
250
                           revision_id=None, lossy=False):
 
251
        """Obtain a CommitBuilder for this repository.
 
252
 
 
253
        :param branch: Branch to commit to.
 
254
        :param parents: Revision ids of the parents of the new revision.
 
255
        :param config: Configuration to use.
 
256
        :param timestamp: Optional timestamp recorded for commit.
 
257
        :param timezone: Optional timezone for timestamp.
 
258
        :param committer: Optional committer to set for commit.
 
259
        :param revprops: Optional dictionary of revision properties.
 
260
        :param revision_id: Optional revision id.
 
261
        :param lossy: Whether to discard data that can not be natively
 
262
            represented, when pushing to a foreign VCS
 
263
        """
 
264
        builder = GitCommitBuilder(self, parents, config,
 
265
                timestamp, timezone, committer, revprops, revision_id,
 
266
                lossy)
 
267
        self.start_write_group()
 
268
        return builder
 
269
 
 
270
    def get_file_graph(self):
 
271
        return _mod_graph.Graph(GitFileParentProvider(
 
272
            self._file_change_scanner))
 
273
 
 
274
    def iter_files_bytes(self, desired_files):
 
275
        """Iterate through file versions.
 
276
 
 
277
        Files will not necessarily be returned in the order they occur in
 
278
        desired_files.  No specific order is guaranteed.
 
279
 
 
280
        Yields pairs of identifier, bytes_iterator.  identifier is an opaque
 
281
        value supplied by the caller as part of desired_files.  It should
 
282
        uniquely identify the file version in the caller's context.  (Examples:
 
283
        an index number or a TreeTransform trans_id.)
 
284
 
 
285
        bytes_iterator is an iterable of bytestrings for the file.  The
 
286
        kind of iterable and length of the bytestrings are unspecified, but for
 
287
        this implementation, it is a list of bytes produced by
 
288
        VersionedFile.get_record_stream().
 
289
 
 
290
        :param desired_files: a list of (file_id, revision_id, identifier)
 
291
            triples
 
292
        """
 
293
        per_revision = {}
 
294
        for (file_id, revision_id, identifier) in desired_files:
 
295
            per_revision.setdefault(revision_id, []).append(
 
296
                (file_id, identifier))
 
297
        for revid, files in per_revision.iteritems():
 
298
            try:
 
299
                (commit_id, mapping) = self.lookup_bzr_revision_id(revid)
 
300
            except errors.NoSuchRevision:
 
301
                raise errors.RevisionNotPresent(revid, self)
 
302
            try:
 
303
                commit = self._git.object_store[commit_id]
 
304
            except KeyError:
 
305
                raise errors.RevisionNotPresent(revid, self)
 
306
            root_tree = commit.tree
 
307
            for fileid, identifier in files:
 
308
                try:
 
309
                    path = mapping.parse_file_id(fileid)
 
310
                except ValueError:
 
311
                    raise errors.RevisionNotPresent((fileid, revid), self)
 
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
 
338
 
 
339
    def _iter_revision_ids(self):
 
340
        mapping = self.get_mapping()
 
341
        for sha in self._git.object_store:
 
342
            o = self._git.object_store[sha]
 
343
            if not isinstance(o, Commit):
 
344
                continue
 
345
            rev, roundtrip_revid, verifiers = mapping.import_commit(o,
 
346
                mapping.revision_id_foreign_to_bzr)
 
347
            yield o.id, rev.revision_id, roundtrip_revid
 
348
 
 
349
    def all_revision_ids(self):
 
350
        ret = set()
 
351
        for git_sha, revid, roundtrip_revid in self._iter_revision_ids():
 
352
            if roundtrip_revid:
 
353
                ret.add(roundtrip_revid)
 
354
            else:
 
355
                ret.add(revid)
 
356
        return list(ret)
 
357
 
 
358
    def _get_parents(self, revid, no_alternates=False):
 
359
        if type(revid) != bytes:
 
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):
 
378
        parent_map = {}
 
379
        for revision_id in revids:
 
380
            parents = self._get_parents(revision_id, no_alternates=no_alternates)
 
381
            if revision_id == _mod_revision.NULL_REVISION:
 
382
                parent_map[revision_id] = ()
 
383
                continue
 
384
            if parents is None:
 
385
                continue
 
386
            if len(parents) == 0:
 
387
                parents = [_mod_revision.NULL_REVISION]
 
388
            parent_map[revision_id] = tuple(parents)
 
389
        return parent_map
 
390
 
 
391
    def get_known_graph_ancestry(self, revision_ids):
 
392
        """Return the known graph for a set of revision ids and their ancestors.
 
393
        """
 
394
        pending = set(revision_ids)
 
395
        parent_map = {}
 
396
        while pending:
 
397
            this_parent_map = {}
 
398
            for revid in pending:
 
399
                if revid == _mod_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)
 
409
 
 
410
    def get_signature_text(self, revision_id):
 
411
        git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
 
412
        try:
 
413
            commit = self._git.object_store[git_commit_id]
 
414
        except KeyError:
 
415
            raise errors.NoSuchRevision(self, revision_id)
 
416
        if commit.gpgsig is None:
 
417
            raise errors.NoSuchRevision(self, revision_id)
 
418
        return commit.gpgsig
 
419
 
 
420
    def check(self, revision_ids=None, callback_refs=None, check_repo=True):
 
421
        result = GitCheck(self, check_repo=check_repo)
 
422
        result.check(callback_refs)
 
423
        return result
 
424
 
 
425
    def pack(self, hint=None, clean_obsolete_packs=False):
 
426
        self._git.object_store.pack_loose_objects()
 
427
 
 
428
    def lookup_foreign_revision_id(self, foreign_revid, mapping=None):
 
429
        """Lookup a revision id.
 
430
 
 
431
        :param foreign_revid: Foreign revision id to look up
 
432
        :param mapping: Mapping to use (use default mapping if not specified)
 
433
        :raise KeyError: If foreign revision was not found
 
434
        :return: bzr revision id
 
435
        """
 
436
        if type(foreign_revid) is not str:
 
437
            raise TypeError(foreign_revid)
 
438
        if mapping is None:
 
439
            mapping = self.get_mapping()
 
440
        if foreign_revid == ZERO_SHA:
 
441
            return _mod_revision.NULL_REVISION
 
442
        commit = self._git.object_store.peel_sha(foreign_revid)
 
443
        if not isinstance(commit, Commit):
 
444
            raise NotCommitError(commit.id)
 
445
        rev, roundtrip_revid, verifiers = mapping.import_commit(commit,
 
446
            mapping.revision_id_foreign_to_bzr)
 
447
        # FIXME: check testament before doing this?
 
448
        if roundtrip_revid:
 
449
            return roundtrip_revid
 
450
        else:
 
451
            return rev.revision_id
 
452
 
 
453
    def has_signature_for_revision_id(self, revision_id):
 
454
        """Check whether a GPG signature is present for this revision.
 
455
 
 
456
        This is never the case for Git repositories.
 
457
        """
 
458
        try:
 
459
            self.get_signature_text(revision_id)
 
460
        except errors.NoSuchRevision:
 
461
            return False
 
462
        else:
 
463
            return True
 
464
 
 
465
    def verify_revision_signature(self, revision_id, gpg_strategy):
 
466
        """Verify the signature on a revision.
 
467
 
 
468
        :param revision_id: the revision to verify
 
469
        :gpg_strategy: the GPGStrategy object to used
 
470
 
 
471
        :return: gpg.SIGNATURE_VALID or a failed SIGNATURE_ value
 
472
        """
 
473
        from breezy import gpg
 
474
        with self.lock_read():
 
475
            git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
 
476
            try:
 
477
                commit = self._git.object_store[git_commit_id]
 
478
            except KeyError:
 
479
                raise errors.NoSuchRevision(self, revision_id)
 
480
 
 
481
            if commit.gpgsig is None:
 
482
                return gpg.SIGNATURE_NOT_SIGNED, None
 
483
 
 
484
            without_sig = Commit.from_string(commit.as_raw_string())
 
485
            without_sig.gpgsig = None
 
486
 
 
487
            (result, key, plain_text) = gpg_strategy.verify(without_sig.as_raw_string(), commit.gpgsig)
 
488
            return (result, key)
 
489
 
 
490
    def lookup_bzr_revision_id(self, bzr_revid, mapping=None):
 
491
        """Lookup a bzr revision id in a Git repository.
 
492
 
 
493
        :param bzr_revid: Bazaar revision id
 
494
        :param mapping: Optional mapping to use
 
495
        :return: Tuple with git commit id, mapping that was used and supplement
 
496
            details
 
497
        """
 
498
        try:
 
499
            (git_sha, mapping) = mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
 
500
        except errors.InvalidRevisionId:
 
501
            if mapping is None:
 
502
                mapping = self.get_mapping()
 
503
            try:
 
504
                return (self._git.refs[mapping.revid_as_refname(bzr_revid)],
 
505
                        mapping)
 
506
            except KeyError:
 
507
                # Update refs from Git commit objects
 
508
                # FIXME: Hitting this a lot will be very inefficient...
 
509
                pb = ui.ui_factory.nested_progress_bar()
 
510
                try:
 
511
                    for i, (git_sha, revid, roundtrip_revid) in enumerate(self._iter_revision_ids()):
 
512
                        if not roundtrip_revid:
 
513
                            continue
 
514
                        pb.update("resolving revision id", i)
 
515
                        refname = mapping.revid_as_refname(roundtrip_revid)
 
516
                        self._git.refs[refname] = git_sha
 
517
                        if roundtrip_revid == bzr_revid:
 
518
                            return git_sha, mapping
 
519
                finally:
 
520
                    pb.finished()
 
521
                raise errors.NoSuchRevision(self, bzr_revid)
 
522
        else:
 
523
            return (git_sha, mapping)
 
524
 
 
525
    def get_revision(self, revision_id):
 
526
        if not isinstance(revision_id, str):
 
527
            raise errors.InvalidRevisionId(revision_id, self)
 
528
        git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
 
529
        try:
 
530
            commit = self._git.object_store[git_commit_id]
 
531
        except KeyError:
 
532
            raise errors.NoSuchRevision(self, revision_id)
 
533
        revision, roundtrip_revid, verifiers = mapping.import_commit(
 
534
            commit, self.lookup_foreign_revision_id)
 
535
        if revision is None:
 
536
            raise AssertionError
 
537
        # FIXME: check verifiers ?
 
538
        if roundtrip_revid:
 
539
            revision.revision_id = roundtrip_revid
 
540
        return revision
 
541
 
 
542
    def has_revision(self, revision_id):
 
543
        """See Repository.has_revision."""
 
544
        if revision_id == _mod_revision.NULL_REVISION:
 
545
            return True
 
546
        try:
 
547
            git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
 
548
        except errors.NoSuchRevision:
 
549
            return False
 
550
        return (git_commit_id in self._git)
 
551
 
 
552
    def has_revisions(self, revision_ids):
 
553
        """See Repository.has_revisions."""
 
554
        return set(filter(self.has_revision, revision_ids))
 
555
 
 
556
    def iter_revisions(self, revision_ids):
 
557
        """See Repository.get_revisions."""
 
558
        for revid in revision_ids:
 
559
            try:
 
560
                rev = self.get_revision(revid)
 
561
            except errors.NoSuchRevision:
 
562
                rev = None
 
563
            yield (revid, rev)
 
564
 
 
565
    def revision_trees(self, revids):
 
566
        """See Repository.revision_trees."""
 
567
        for revid in revids:
 
568
            yield self.revision_tree(revid)
 
569
 
 
570
    def revision_tree(self, revision_id):
 
571
        """See Repository.revision_tree."""
 
572
        if revision_id is None:
 
573
            raise ValueError('invalid revision id %s' % revision_id)
 
574
        return GitRevisionTree(self, revision_id)
 
575
 
 
576
    def get_deltas_for_revisions(self, revisions, specific_fileids=None):
 
577
        """Produce a generator of revision deltas.
 
578
 
 
579
        Note that the input is a sequence of REVISIONS, not revision_ids.
 
580
        Trees will be held in memory until the generator exits.
 
581
        Each delta is relative to the revision's lefthand predecessor.
 
582
 
 
583
        :param specific_fileids: if not None, the result is filtered
 
584
          so that only those file-ids, their parents and their
 
585
          children are included.
 
586
        """
 
587
        # Get the revision-ids of interest
 
588
        required_trees = set()
 
589
        for revision in revisions:
 
590
            required_trees.add(revision.revision_id)
 
591
            required_trees.update(revision.parent_ids[:1])
 
592
 
 
593
        trees = dict((t.get_revision_id(), t) for
 
594
            t in self.revision_trees(required_trees))
 
595
 
 
596
        # Calculate the deltas
 
597
        for revision in revisions:
 
598
            if not revision.parent_ids:
 
599
                old_tree = self.revision_tree(_mod_revision.NULL_REVISION)
 
600
            else:
 
601
                old_tree = trees[revision.parent_ids[0]]
 
602
            new_tree = trees[revision.revision_id]
 
603
            if specific_fileids is not None:
 
604
                specific_files = [new_tree.id2path(fid) for fid in specific_fileids]
 
605
            else:
 
606
                specific_files = None
 
607
            yield new_tree.changes_from(old_tree, specific_files=specific_files)
 
608
 
 
609
    def set_make_working_trees(self, trees):
 
610
        raise errors.UnsupportedOperation(self.set_make_working_trees, self)
 
611
 
 
612
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
 
613
        progress=None, limit=None):
 
614
        return self._git.fetch_objects(determine_wants, graph_walker, progress,
 
615
            limit=limit)
 
616
 
 
617
 
 
618
class GitRepositoryFormat(repository.RepositoryFormat):
 
619
    """Git repository format."""
 
620
 
 
621
    supports_versioned_directories = False
 
622
    supports_tree_reference = False
 
623
    rich_root_data = True
 
624
    supports_leaving_lock = False
 
625
    fast_deltas = True
 
626
    supports_funky_characters = True
 
627
    supports_external_lookups = False
 
628
    supports_full_versioned_files = False
 
629
    supports_revision_signatures = False
 
630
    supports_nesting_repositories = False
 
631
    revision_graph_can_have_wrong_parents = False
 
632
    supports_unreferenced_revisions = True
 
633
    supports_setting_revision_ids = False
 
634
    supports_storing_branch_nick = False
 
635
    supports_overriding_transport = False
 
636
    supports_custom_revision_properties = False
 
637
    records_per_file_revision = False
 
638
 
 
639
    @property
 
640
    def _matchingcontroldir(self):
 
641
        from .dir import LocalGitControlDirFormat
 
642
        return LocalGitControlDirFormat()
 
643
 
 
644
    def get_format_description(self):
 
645
        return "Git Repository"
 
646
 
 
647
    def initialize(self, controldir, shared=False, _internal=False):
 
648
        from .dir import GitDir
 
649
        if not isinstance(controldir, GitDir):
 
650
            raise errors.UninitializableFormat(self)
 
651
        return controldir.open_repository()
 
652
 
 
653
    def check_conversion_target(self, target_repo_format):
 
654
        return target_repo_format.rich_root_data
 
655
 
 
656
    def get_foreign_tests_repository_factory(self):
 
657
        from .tests.test_repository import (
 
658
            ForeignTestsRepositoryFactory,
 
659
            )
 
660
        return ForeignTestsRepositoryFactory()
 
661
 
 
662
    def network_name(self):
 
663
        return "git"