/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 breezy/git/repository.py

  • Committer: Jelmer Vernooij
  • Date: 2019-10-28 01:38:39 UTC
  • mto: This revision was merged to the branch mainline in revision 7412.
  • Revision ID: jelmer@jelmer.uk-20191028013839-q63zzm4yr0id9b3o
Allow unknown extras in git commits when just inspecting revisions, rather than importing.

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