/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-30 21:27:44 UTC
  • mto: (0.200.1905 work)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180330212744-k60bo2l6ycft26hd
Move all InterRepository implementations into interrepo.

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 interrepo
 
116
    for optimiser in [interrepo.InterRemoteGitNonGitRepository,
 
117
                      interrepo.InterLocalGitNonGitRepository,
 
118
                      interrepo.InterLocalGitLocalGitRepository,
 
119
                      interrepo.InterRemoteGitLocalGitRepository,
 
120
                      interrepo.InterToLocalGitRepository,
 
121
                      interrepo.InterToRemoteGitRepository]:
 
122
        repository.InterRepository.register_optimiser(optimiser)
 
123
    _optimisers_loaded = True
 
124
 
 
125
 
 
126
class GitRepository(ForeignRepository):
 
127
    """An adapter to git repositories for bzr."""
 
128
 
 
129
    _serializer = None
 
130
    vcs = foreign_vcs_git
 
131
    chk_bytes = None
 
132
 
 
133
    def __init__(self, gitdir):
 
134
        self._transport = gitdir.root_transport
 
135
        super(GitRepository, self).__init__(GitRepositoryFormat(),
 
136
            gitdir, control_files=None)
 
137
        self.base = gitdir.root_transport.base
 
138
        lazy_load_optimisers()
 
139
        self._lock_mode = None
 
140
        self._lock_count = 0
 
141
 
 
142
    def add_fallback_repository(self, basis_url):
 
143
        raise errors.UnstackableRepositoryFormat(self._format,
 
144
            self.control_transport.base)
 
145
 
 
146
    def is_shared(self):
 
147
        return False
 
148
 
 
149
    def get_physical_lock_status(self):
 
150
        return False
 
151
 
 
152
    def lock_write(self):
 
153
        """See Branch.lock_write()."""
 
154
        if self._lock_mode:
 
155
            if self._lock_mode != 'w':
 
156
                raise errors.ReadOnlyError(self)
 
157
            self._lock_count += 1
 
158
        else:
 
159
            self._lock_mode = 'w'
 
160
            self._lock_count = 1
 
161
            self._transaction = transactions.WriteTransaction()
 
162
        return repository.RepositoryWriteLockResult(self.unlock, None)
 
163
 
 
164
    def break_lock(self):
 
165
        raise NotImplementedError(self.break_lock)
 
166
 
 
167
    def dont_leave_lock_in_place(self):
 
168
        raise NotImplementedError(self.dont_leave_lock_in_place)
 
169
 
 
170
    def leave_lock_in_place(self):
 
171
        raise NotImplementedError(self.leave_lock_in_place)
 
172
 
 
173
    def lock_read(self):
 
174
        if self._lock_mode:
 
175
            if self._lock_mode not in ('r', 'w'):
 
176
                raise AssertionError
 
177
            self._lock_count += 1
 
178
        else:
 
179
            self._lock_mode = 'r'
 
180
            self._lock_count = 1
 
181
            self._transaction = transactions.ReadOnlyTransaction()
 
182
        return lock.LogicalLockResult(self.unlock)
 
183
 
 
184
    @only_raises(errors.LockNotHeld, errors.LockBroken)
 
185
    def unlock(self):
 
186
        if self._lock_count == 0:
 
187
            raise errors.LockNotHeld(self)
 
188
        if self._lock_count == 1 and self._lock_mode == 'w':
 
189
            if self._write_group is not None:
 
190
                self.abort_write_group()
 
191
                self._lock_count -= 1
 
192
                self._lock_mode = None
 
193
                raise errors.BzrError(
 
194
                    'Must end write groups before releasing write locks.')
 
195
        self._lock_count -= 1
 
196
        if self._lock_count == 0:
 
197
            self._lock_mode = None
 
198
            transaction = self._transaction
 
199
            self._transaction = None
 
200
            transaction.finish()
 
201
 
 
202
    def is_write_locked(self):
 
203
        return (self._lock_mode == 'w')
 
204
 
 
205
    def is_locked(self):
 
206
        return (self._lock_mode is not None)
 
207
 
 
208
    def get_transaction(self):
 
209
        """See Repository.get_transaction()."""
 
210
        if self._transaction is None:
 
211
            return transactions.PassThroughTransaction()
 
212
        else:
 
213
            return self._transaction
 
214
 
 
215
    def reconcile(self, other=None, thorough=False):
 
216
        """Reconcile this repository."""
 
217
        reconciler = RepoReconciler(self, thorough=thorough)
 
218
        reconciler.reconcile()
 
219
        return reconciler
 
220
 
 
221
    def supports_rich_root(self):
 
222
        return True
 
223
 
 
224
    def get_mapping(self):
 
225
        return default_mapping
 
226
 
 
227
    def make_working_trees(self):
 
228
        return not self._git.get_config().get_boolean(("core", ), "bare")
 
229
 
 
230
    def revision_graph_can_have_wrong_parents(self):
 
231
        return False
 
232
 
 
233
    def add_signature_text(self, revid, signature):
 
234
        raise errors.UnsupportedOperation(self.add_signature_text, self)
 
235
 
 
236
    def sign_revision(self, revision_id, gpg_strategy):
 
237
        raise errors.UnsupportedOperation(self.add_signature_text, self)
 
238
 
 
239
 
 
240
class LocalGitRepository(GitRepository):
 
241
    """Git repository on the file system."""
 
242
 
 
243
    def __init__(self, gitdir):
 
244
        GitRepository.__init__(self, gitdir)
 
245
        self._git = gitdir._git
 
246
        self._file_change_scanner = GitFileLastChangeScanner(self)
 
247
        self._transaction = None
 
248
 
 
249
    def get_commit_builder(self, branch, parents, config, timestamp=None,
 
250
                           timezone=None, committer=None, revprops=None,
 
251
                           revision_id=None, lossy=False):
 
252
        """Obtain a CommitBuilder for this repository.
 
253
 
 
254
        :param branch: Branch to commit to.
 
255
        :param parents: Revision ids of the parents of the new revision.
 
256
        :param config: Configuration to use.
 
257
        :param timestamp: Optional timestamp recorded for commit.
 
258
        :param timezone: Optional timezone for timestamp.
 
259
        :param committer: Optional committer to set for commit.
 
260
        :param revprops: Optional dictionary of revision properties.
 
261
        :param revision_id: Optional revision id.
 
262
        :param lossy: Whether to discard data that can not be natively
 
263
            represented, when pushing to a foreign VCS
 
264
        """
 
265
        builder = GitCommitBuilder(self, parents, config,
 
266
                timestamp, timezone, committer, revprops, revision_id,
 
267
                lossy)
 
268
        self.start_write_group()
 
269
        return builder
 
270
 
 
271
    def get_file_graph(self):
 
272
        return _mod_graph.Graph(GitFileParentProvider(
 
273
            self._file_change_scanner))
 
274
 
 
275
    def iter_files_bytes(self, desired_files):
 
276
        """Iterate through file versions.
 
277
 
 
278
        Files will not necessarily be returned in the order they occur in
 
279
        desired_files.  No specific order is guaranteed.
 
280
 
 
281
        Yields pairs of identifier, bytes_iterator.  identifier is an opaque
 
282
        value supplied by the caller as part of desired_files.  It should
 
283
        uniquely identify the file version in the caller's context.  (Examples:
 
284
        an index number or a TreeTransform trans_id.)
 
285
 
 
286
        bytes_iterator is an iterable of bytestrings for the file.  The
 
287
        kind of iterable and length of the bytestrings are unspecified, but for
 
288
        this implementation, it is a list of bytes produced by
 
289
        VersionedFile.get_record_stream().
 
290
 
 
291
        :param desired_files: a list of (file_id, revision_id, identifier)
 
292
            triples
 
293
        """
 
294
        per_revision = {}
 
295
        for (file_id, revision_id, identifier) in desired_files:
 
296
            per_revision.setdefault(revision_id, []).append(
 
297
                (file_id, identifier))
 
298
        for revid, files in per_revision.iteritems():
 
299
            try:
 
300
                (commit_id, mapping) = self.lookup_bzr_revision_id(revid)
 
301
            except errors.NoSuchRevision:
 
302
                raise errors.RevisionNotPresent(revid, self)
 
303
            try:
 
304
                commit = self._git.object_store[commit_id]
 
305
            except KeyError:
 
306
                raise errors.RevisionNotPresent(revid, self)
 
307
            root_tree = commit.tree
 
308
            for fileid, identifier in files:
 
309
                try:
 
310
                    path = mapping.parse_file_id(fileid)
 
311
                except ValueError:
 
312
                    raise errors.RevisionNotPresent((fileid, revid), self)
 
313
                try:
 
314
                    obj = tree_lookup_path(
 
315
                        self._git.object_store.__getitem__, root_tree, path)
 
316
                    if isinstance(obj, tuple):
 
317
                        (mode, item_id) = obj
 
318
                        obj = self._git.object_store[item_id]
 
319
                except KeyError:
 
320
                    raise errors.RevisionNotPresent((fileid, revid), self)
 
321
                else:
 
322
                    if obj.type_name == "tree":
 
323
                        yield (identifier, [])
 
324
                    elif obj.type_name == "blob":
 
325
                        yield (identifier, obj.chunked)
 
326
                    else:
 
327
                        raise AssertionError("file text resolved to %r" % obj)
 
328
 
 
329
    def gather_stats(self, revid=None, committers=None):
 
330
        """See Repository.gather_stats()."""
 
331
        result = super(LocalGitRepository, self).gather_stats(revid, committers)
 
332
        revs = []
 
333
        for sha in self._git.object_store:
 
334
            o = self._git.object_store[sha]
 
335
            if o.type_name == "commit":
 
336
                revs.append(o.id)
 
337
        result['revisions'] = len(revs)
 
338
        return result
 
339
 
 
340
    def _iter_revision_ids(self):
 
341
        mapping = self.get_mapping()
 
342
        for sha in self._git.object_store:
 
343
            o = self._git.object_store[sha]
 
344
            if not isinstance(o, Commit):
 
345
                continue
 
346
            rev, roundtrip_revid, verifiers = mapping.import_commit(o,
 
347
                mapping.revision_id_foreign_to_bzr)
 
348
            yield o.id, rev.revision_id, roundtrip_revid
 
349
 
 
350
    def all_revision_ids(self):
 
351
        ret = set()
 
352
        for git_sha, revid, roundtrip_revid in self._iter_revision_ids():
 
353
            if roundtrip_revid:
 
354
                ret.add(roundtrip_revid)
 
355
            else:
 
356
                ret.add(revid)
 
357
        return list(ret)
 
358
 
 
359
    def _get_parents(self, revid, no_alternates=False):
 
360
        if type(revid) != bytes:
 
361
            raise ValueError
 
362
        try:
 
363
            (hexsha, mapping) = self.lookup_bzr_revision_id(revid)
 
364
        except errors.NoSuchRevision:
 
365
            return None
 
366
        # FIXME: Honor no_alternates setting
 
367
        try:
 
368
            commit = self._git.object_store[hexsha]
 
369
        except KeyError:
 
370
            return None
 
371
        return [
 
372
            self.lookup_foreign_revision_id(p, mapping)
 
373
            for p in commit.parents]
 
374
 
 
375
    def _get_parent_map_no_fallbacks(self, revids):
 
376
        return self.get_parent_map(revids, no_alternates=True)
 
377
 
 
378
    def get_parent_map(self, revids, no_alternates=False):
 
379
        parent_map = {}
 
380
        for revision_id in revids:
 
381
            parents = self._get_parents(revision_id, no_alternates=no_alternates)
 
382
            if revision_id == _mod_revision.NULL_REVISION:
 
383
                parent_map[revision_id] = ()
 
384
                continue
 
385
            if parents is None:
 
386
                continue
 
387
            if len(parents) == 0:
 
388
                parents = [_mod_revision.NULL_REVISION]
 
389
            parent_map[revision_id] = tuple(parents)
 
390
        return parent_map
 
391
 
 
392
    def get_known_graph_ancestry(self, revision_ids):
 
393
        """Return the known graph for a set of revision ids and their ancestors.
 
394
        """
 
395
        pending = set(revision_ids)
 
396
        parent_map = {}
 
397
        while pending:
 
398
            this_parent_map = {}
 
399
            for revid in pending:
 
400
                if revid == _mod_revision.NULL_REVISION:
 
401
                    continue
 
402
                parents = self._get_parents(revid)
 
403
                if parents is not None:
 
404
                    this_parent_map[revid] = parents
 
405
            parent_map.update(this_parent_map)
 
406
            pending = set()
 
407
            map(pending.update, this_parent_map.itervalues())
 
408
            pending = pending.difference(parent_map)
 
409
        return _mod_graph.KnownGraph(parent_map)
 
410
 
 
411
    def get_signature_text(self, revision_id):
 
412
        git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
 
413
        try:
 
414
            commit = self._git.object_store[git_commit_id]
 
415
        except KeyError:
 
416
            raise errors.NoSuchRevision(self, revision_id)
 
417
        if commit.gpgsig is None:
 
418
            raise errors.NoSuchRevision(self, revision_id)
 
419
        return commit.gpgsig
 
420
 
 
421
    def check(self, revision_ids=None, callback_refs=None, check_repo=True):
 
422
        result = GitCheck(self, check_repo=check_repo)
 
423
        result.check(callback_refs)
 
424
        return result
 
425
 
 
426
    def pack(self, hint=None, clean_obsolete_packs=False):
 
427
        self._git.object_store.pack_loose_objects()
 
428
 
 
429
    def lookup_foreign_revision_id(self, foreign_revid, mapping=None):
 
430
        """Lookup a revision id.
 
431
 
 
432
        :param foreign_revid: Foreign revision id to look up
 
433
        :param mapping: Mapping to use (use default mapping if not specified)
 
434
        :raise KeyError: If foreign revision was not found
 
435
        :return: bzr revision id
 
436
        """
 
437
        if type(foreign_revid) is not str:
 
438
            raise TypeError(foreign_revid)
 
439
        if mapping is None:
 
440
            mapping = self.get_mapping()
 
441
        if foreign_revid == ZERO_SHA:
 
442
            return _mod_revision.NULL_REVISION
 
443
        commit = self._git.object_store.peel_sha(foreign_revid)
 
444
        if not isinstance(commit, Commit):
 
445
            raise NotCommitError(commit.id)
 
446
        rev, roundtrip_revid, verifiers = mapping.import_commit(commit,
 
447
            mapping.revision_id_foreign_to_bzr)
 
448
        # FIXME: check testament before doing this?
 
449
        if roundtrip_revid:
 
450
            return roundtrip_revid
 
451
        else:
 
452
            return rev.revision_id
 
453
 
 
454
    def has_signature_for_revision_id(self, revision_id):
 
455
        """Check whether a GPG signature is present for this revision.
 
456
 
 
457
        This is never the case for Git repositories.
 
458
        """
 
459
        try:
 
460
            self.get_signature_text(revision_id)
 
461
        except errors.NoSuchRevision:
 
462
            return False
 
463
        else:
 
464
            return True
 
465
 
 
466
    def verify_revision_signature(self, revision_id, gpg_strategy):
 
467
        """Verify the signature on a revision.
 
468
 
 
469
        :param revision_id: the revision to verify
 
470
        :gpg_strategy: the GPGStrategy object to used
 
471
 
 
472
        :return: gpg.SIGNATURE_VALID or a failed SIGNATURE_ value
 
473
        """
 
474
        from breezy import gpg
 
475
        with self.lock_read():
 
476
            git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
 
477
            try:
 
478
                commit = self._git.object_store[git_commit_id]
 
479
            except KeyError:
 
480
                raise errors.NoSuchRevision(self, revision_id)
 
481
 
 
482
            if commit.gpgsig is None:
 
483
                return gpg.SIGNATURE_NOT_SIGNED, None
 
484
 
 
485
            without_sig = Commit.from_string(commit.as_raw_string())
 
486
            without_sig.gpgsig = None
 
487
 
 
488
            (result, key, plain_text) = gpg_strategy.verify(without_sig.as_raw_string(), commit.gpgsig)
 
489
            return (result, key)
 
490
 
 
491
    def lookup_bzr_revision_id(self, bzr_revid, mapping=None):
 
492
        """Lookup a bzr revision id in a Git repository.
 
493
 
 
494
        :param bzr_revid: Bazaar revision id
 
495
        :param mapping: Optional mapping to use
 
496
        :return: Tuple with git commit id, mapping that was used and supplement
 
497
            details
 
498
        """
 
499
        try:
 
500
            (git_sha, mapping) = mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
 
501
        except errors.InvalidRevisionId:
 
502
            if mapping is None:
 
503
                mapping = self.get_mapping()
 
504
            try:
 
505
                return (self._git.refs[mapping.revid_as_refname(bzr_revid)],
 
506
                        mapping)
 
507
            except KeyError:
 
508
                # Update refs from Git commit objects
 
509
                # FIXME: Hitting this a lot will be very inefficient...
 
510
                pb = ui.ui_factory.nested_progress_bar()
 
511
                try:
 
512
                    for i, (git_sha, revid, roundtrip_revid) in enumerate(self._iter_revision_ids()):
 
513
                        if not roundtrip_revid:
 
514
                            continue
 
515
                        pb.update("resolving revision id", i)
 
516
                        refname = mapping.revid_as_refname(roundtrip_revid)
 
517
                        self._git.refs[refname] = git_sha
 
518
                        if roundtrip_revid == bzr_revid:
 
519
                            return git_sha, mapping
 
520
                finally:
 
521
                    pb.finished()
 
522
                raise errors.NoSuchRevision(self, bzr_revid)
 
523
        else:
 
524
            return (git_sha, mapping)
 
525
 
 
526
    def get_revision(self, revision_id):
 
527
        if not isinstance(revision_id, str):
 
528
            raise errors.InvalidRevisionId(revision_id, self)
 
529
        git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
 
530
        try:
 
531
            commit = self._git.object_store[git_commit_id]
 
532
        except KeyError:
 
533
            raise errors.NoSuchRevision(self, revision_id)
 
534
        revision, roundtrip_revid, verifiers = mapping.import_commit(
 
535
            commit, self.lookup_foreign_revision_id)
 
536
        if revision is None:
 
537
            raise AssertionError
 
538
        # FIXME: check verifiers ?
 
539
        if roundtrip_revid:
 
540
            revision.revision_id = roundtrip_revid
 
541
        return revision
 
542
 
 
543
    def has_revision(self, revision_id):
 
544
        """See Repository.has_revision."""
 
545
        if revision_id == _mod_revision.NULL_REVISION:
 
546
            return True
 
547
        try:
 
548
            git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
 
549
        except errors.NoSuchRevision:
 
550
            return False
 
551
        return (git_commit_id in self._git)
 
552
 
 
553
    def has_revisions(self, revision_ids):
 
554
        """See Repository.has_revisions."""
 
555
        return set(filter(self.has_revision, revision_ids))
 
556
 
 
557
    def iter_revisions(self, revision_ids):
 
558
        """See Repository.get_revisions."""
 
559
        for revid in revision_ids:
 
560
            try:
 
561
                rev = self.get_revision(revid)
 
562
            except errors.NoSuchRevision:
 
563
                rev = None
 
564
            yield (revid, rev)
 
565
 
 
566
    def revision_trees(self, revids):
 
567
        """See Repository.revision_trees."""
 
568
        for revid in revids:
 
569
            yield self.revision_tree(revid)
 
570
 
 
571
    def revision_tree(self, revision_id):
 
572
        """See Repository.revision_tree."""
 
573
        if revision_id is None:
 
574
            raise ValueError('invalid revision id %s' % revision_id)
 
575
        return GitRevisionTree(self, revision_id)
 
576
 
 
577
    def get_deltas_for_revisions(self, revisions, specific_fileids=None):
 
578
        """Produce a generator of revision deltas.
 
579
 
 
580
        Note that the input is a sequence of REVISIONS, not revision_ids.
 
581
        Trees will be held in memory until the generator exits.
 
582
        Each delta is relative to the revision's lefthand predecessor.
 
583
 
 
584
        :param specific_fileids: if not None, the result is filtered
 
585
          so that only those file-ids, their parents and their
 
586
          children are included.
 
587
        """
 
588
        # Get the revision-ids of interest
 
589
        required_trees = set()
 
590
        for revision in revisions:
 
591
            required_trees.add(revision.revision_id)
 
592
            required_trees.update(revision.parent_ids[:1])
 
593
 
 
594
        trees = dict((t.get_revision_id(), t) for
 
595
            t in self.revision_trees(required_trees))
 
596
 
 
597
        # Calculate the deltas
 
598
        for revision in revisions:
 
599
            if not revision.parent_ids:
 
600
                old_tree = self.revision_tree(_mod_revision.NULL_REVISION)
 
601
            else:
 
602
                old_tree = trees[revision.parent_ids[0]]
 
603
            new_tree = trees[revision.revision_id]
 
604
            if specific_fileids is not None:
 
605
                specific_files = [new_tree.id2path(fid) for fid in specific_fileids]
 
606
            else:
 
607
                specific_files = None
 
608
            yield new_tree.changes_from(old_tree, specific_files=specific_files)
 
609
 
 
610
    def set_make_working_trees(self, trees):
 
611
        raise errors.UnsupportedOperation(self.set_make_working_trees, self)
 
612
 
 
613
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
 
614
        progress=None, limit=None):
 
615
        return self._git.fetch_objects(determine_wants, graph_walker, progress,
 
616
            limit=limit)
 
617
 
 
618
 
 
619
class GitRepositoryFormat(repository.RepositoryFormat):
 
620
    """Git repository format."""
 
621
 
 
622
    supports_versioned_directories = False
 
623
    supports_tree_reference = False
 
624
    rich_root_data = True
 
625
    supports_leaving_lock = False
 
626
    fast_deltas = True
 
627
    supports_funky_characters = True
 
628
    supports_external_lookups = False
 
629
    supports_full_versioned_files = False
 
630
    supports_revision_signatures = False
 
631
    supports_nesting_repositories = False
 
632
    revision_graph_can_have_wrong_parents = False
 
633
    supports_unreferenced_revisions = True
 
634
    supports_setting_revision_ids = False
 
635
    supports_storing_branch_nick = False
 
636
    supports_overriding_transport = False
 
637
    supports_custom_revision_properties = False
 
638
    records_per_file_revision = False
 
639
 
 
640
    @property
 
641
    def _matchingcontroldir(self):
 
642
        from .dir import LocalGitControlDirFormat
 
643
        return LocalGitControlDirFormat()
 
644
 
 
645
    def get_format_description(self):
 
646
        return "Git Repository"
 
647
 
 
648
    def initialize(self, controldir, shared=False, _internal=False):
 
649
        from .dir import GitDir
 
650
        if not isinstance(controldir, GitDir):
 
651
            raise errors.UninitializableFormat(self)
 
652
        return controldir.open_repository()
 
653
 
 
654
    def check_conversion_target(self, target_repo_format):
 
655
        return target_repo_format.rich_root_data
 
656
 
 
657
    def get_foreign_tests_repository_factory(self):
 
658
        from .tests.test_repository import (
 
659
            ForeignTestsRepositoryFactory,
 
660
            )
 
661
        return ForeignTestsRepositoryFactory()
 
662
 
 
663
    def network_name(self):
 
664
        return "git"