/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.358.2 by Jelmer Vernooij
Refresh copyright headers, add my email.
1
# Copyright (C) 2008-2018 Jelmer Vernooij <jelmer@jelmer.uk>
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
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
0.358.1 by Jelmer Vernooij
Fix FSF address.
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
17
18
"""An adapter between a Git Repository and a Bazaar Branch"""
19
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
20
from .. import (
0.200.1244 by Jelmer Vernooij
Implement GitRepository.check.
21
    check,
0.200.43 by David Allouche
Ultra-experimental support for "bzr pull". No test. No sanity.
22
    errors,
0.200.1281 by Jelmer Vernooij
Provide Repository.get_known_graph_ancestry.
23
    graph as _mod_graph,
0.200.1670 by Jelmer Vernooij
Fix compatibility with newer versions of bzr.
24
    lock,
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
25
    repository,
0.285.5 by Jelmer Vernooij
Fix import.
26
    revision as _mod_revision,
0.425.1 by Jelmer Vernooij
Add really basic check implementation.
27
    trace,
0.200.1411 by Jelmer Vernooij
Fix control files.
28
    transactions,
0.200.1601 by Jelmer Vernooij
remove compatibility code for bzr < 2.5.
29
    ui,
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
30
    )
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
31
from ..decorators import only_raises
32
from ..foreign import (
0.200.292 by Jelmer Vernooij
Fix formatting.
33
    ForeignRepository,
34
    )
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
35
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
36
from .filegraph import (
0.200.1283 by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision().
37
    GitFileLastChangeScanner,
38
    GitFileParentProvider,
39
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
40
from .mapping import (
0.200.256 by Jelmer Vernooij
Add tests for import_revision_gist.
41
    default_mapping,
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
42
    encode_git_path,
0.200.1263 by Jelmer Vernooij
Fix foreign_vcs_git.
43
    foreign_vcs_git,
0.200.256 by Jelmer Vernooij
Add tests for import_revision_gist.
44
    mapping_registry,
45
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
46
from .tree import (
0.200.617 by Jelmer Vernooij
Add custom InterTree for use between git revision trees.
47
    GitRevisionTree,
48
    )
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
49
50
0.200.1636 by Jelmer Vernooij
Some formatting fixes.
51
from dulwich.errors import (
52
    NotCommitError,
53
    )
0.252.21 by Jelmer Vernooij
Fix GitRepository.all_revision_ids() to find all revisions.
54
from dulwich.objects import (
55
    Commit,
0.200.1153 by Jelmer Vernooij
Import ZERO_SHA from dulwich.objects.
56
    ZERO_SHA,
0.252.21 by Jelmer Vernooij
Fix GitRepository.all_revision_ids() to find all revisions.
57
    )
0.200.1233 by Jelmer Vernooij
Implement Repository.iter_files_bytes.
58
from dulwich.object_store import (
59
    tree_lookup_path,
60
    )
0.252.21 by Jelmer Vernooij
Fix GitRepository.all_revision_ids() to find all revisions.
61
62
0.200.1244 by Jelmer Vernooij
Implement GitRepository.check.
63
class GitCheck(check.Check):
64
65
    def __init__(self, repository, check_repo=True):
66
        self.repository = repository
0.425.1 by Jelmer Vernooij
Add really basic check implementation.
67
        self.check_repo = check_repo
0.200.1244 by Jelmer Vernooij
Implement GitRepository.check.
68
        self.checked_rev_cnt = 0
0.425.1 by Jelmer Vernooij
Add really basic check implementation.
69
        self.object_count = None
70
        self.problems = []
0.200.1244 by Jelmer Vernooij
Implement GitRepository.check.
71
72
    def check(self, callback_refs=None, check_repo=True):
73
        if callback_refs is None:
74
            callback_refs = {}
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
75
        with self.repository.lock_read(), \
76
                ui.ui_factory.nested_progress_bar() as self.progress:
0.425.1 by Jelmer Vernooij
Add really basic check implementation.
77
            shas = set(self.repository._git.object_store)
78
            self.object_count = len(shas)
79
            # TODO(jelmer): Check more things
80
            for i, sha in enumerate(shas):
81
                self.progress.update('checking objects', i, self.object_count)
82
                o = self.repository._git.object_store[sha]
83
                try:
84
                    o.check()
85
                except Exception as e:
86
                    self.problems.append((sha, e))
87
88
    def _report_repo_results(self, verbose):
89
        trace.note('checked repository {0} format {1}'.format(
90
            self.repository.user_url,
91
            self.repository._format))
92
        trace.note('%6d objects', self.object_count)
93
        for sha, problem in self.problems:
94
            trace.note('%s: %s', sha, problem)
0.200.1244 by Jelmer Vernooij
Implement GitRepository.check.
95
96
    def report_results(self, verbose):
0.425.1 by Jelmer Vernooij
Add really basic check implementation.
97
        if self.check_repo:
98
            self._report_repo_results(verbose)
0.200.1244 by Jelmer Vernooij
Implement GitRepository.check.
99
100
7490.64.1 by Jelmer Vernooij
Add import tariff test for 'brz st' in a git repository.
101
for optimiser in ['InterRemoteGitNonGitRepository',
102
                  'InterLocalGitNonGitRepository',
103
                  'InterLocalGitLocalGitRepository',
104
                  'InterRemoteGitLocalGitRepository',
105
                  'InterToLocalGitRepository',
106
                  'InterToRemoteGitRepository',
107
                  ]:
108
    repository.InterRepository.register_lazy_optimiser(
109
        'breezy.git.interrepo', optimiser)
0.200.1447 by Jelmer Vernooij
Load optimisers at most once.
110
111
0.200.115 by Jelmer Vernooij
Pass mapping object.
112
class GitRepository(ForeignRepository):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
113
    """An adapter to git repositories for bzr."""
114
0.200.41 by David Allouche
Define _serializer = None in GitRepository.
115
    _serializer = None
0.200.1263 by Jelmer Vernooij
Fix foreign_vcs_git.
116
    vcs = foreign_vcs_git
0.200.1086 by Jelmer Vernooij
Provide chk_bytes attribute.
117
    chk_bytes = None
0.200.41 by David Allouche
Define _serializer = None in GitRepository.
118
0.200.1411 by Jelmer Vernooij
Fix control files.
119
    def __init__(self, gitdir):
0.200.1447 by Jelmer Vernooij
Load optimisers at most once.
120
        self._transport = gitdir.root_transport
0.200.1307 by Jelmer Vernooij
Formatting fixes, specify path to a couple more functions.
121
        super(GitRepository, self).__init__(GitRepositoryFormat(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
122
                                            gitdir, control_files=None)
0.200.1449 by Jelmer Vernooij
Fix compatibility with bzr < 2.5 when used with remote repositories.
123
        self.base = gitdir.root_transport.base
0.200.1411 by Jelmer Vernooij
Fix control files.
124
        self._lock_mode = None
125
        self._lock_count = 0
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
126
0.200.1231 by Jelmer Vernooij
Implement GitRepository.add_fallback_repository.
127
    def add_fallback_repository(self, basis_url):
0.200.1307 by Jelmer Vernooij
Formatting fixes, specify path to a couple more functions.
128
        raise errors.UnstackableRepositoryFormat(self._format,
7143.15.2 by Jelmer Vernooij
Run autopep8.
129
                                                 self.control_transport.base)
0.200.1231 by Jelmer Vernooij
Implement GitRepository.add_fallback_repository.
130
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
131
    def is_shared(self):
0.200.886 by Jelmer Vernooij
Git repositories are not shared.
132
        return False
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
133
0.200.1411 by Jelmer Vernooij
Fix control files.
134
    def get_physical_lock_status(self):
135
        return False
136
137
    def lock_write(self):
138
        """See Branch.lock_write()."""
139
        if self._lock_mode:
0.361.1 by Jelmer Vernooij
Don't use assert.
140
            if self._lock_mode != 'w':
141
                raise errors.ReadOnlyError(self)
0.200.1411 by Jelmer Vernooij
Fix control files.
142
            self._lock_count += 1
143
        else:
144
            self._lock_mode = 'w'
145
            self._lock_count = 1
0.334.1 by Jelmer Vernooij
Improve transaction and write group handling.
146
            self._transaction = transactions.WriteTransaction()
0.200.1680 by Jelmer Vernooij
Fix repo locks.
147
        return repository.RepositoryWriteLockResult(self.unlock, None)
0.200.1411 by Jelmer Vernooij
Fix control files.
148
0.200.1454 by Jelmer Vernooij
Provide Repository.break_lock.
149
    def break_lock(self):
150
        raise NotImplementedError(self.break_lock)
151
0.200.1411 by Jelmer Vernooij
Fix control files.
152
    def dont_leave_lock_in_place(self):
153
        raise NotImplementedError(self.dont_leave_lock_in_place)
154
155
    def leave_lock_in_place(self):
156
        raise NotImplementedError(self.leave_lock_in_place)
157
158
    def lock_read(self):
159
        if self._lock_mode:
0.361.1 by Jelmer Vernooij
Don't use assert.
160
            if self._lock_mode not in ('r', 'w'):
161
                raise AssertionError
0.200.1411 by Jelmer Vernooij
Fix control files.
162
            self._lock_count += 1
163
        else:
164
            self._lock_mode = 'r'
165
            self._lock_count = 1
0.334.1 by Jelmer Vernooij
Improve transaction and write group handling.
166
            self._transaction = transactions.ReadOnlyTransaction()
0.200.1670 by Jelmer Vernooij
Fix compatibility with newer versions of bzr.
167
        return lock.LogicalLockResult(self.unlock)
0.200.1411 by Jelmer Vernooij
Fix control files.
168
169
    @only_raises(errors.LockNotHeld, errors.LockBroken)
170
    def unlock(self):
171
        if self._lock_count == 0:
172
            raise errors.LockNotHeld(self)
173
        if self._lock_count == 1 and self._lock_mode == 'w':
174
            if self._write_group is not None:
175
                self.abort_write_group()
176
                self._lock_count -= 1
177
                self._lock_mode = None
178
                raise errors.BzrError(
179
                    'Must end write groups before releasing write locks.')
180
        self._lock_count -= 1
181
        if self._lock_count == 0:
182
            self._lock_mode = None
0.334.1 by Jelmer Vernooij
Improve transaction and write group handling.
183
            transaction = self._transaction
184
            self._transaction = None
185
            transaction.finish()
0.200.1411 by Jelmer Vernooij
Fix control files.
186
187
    def is_write_locked(self):
188
        return (self._lock_mode == 'w')
189
190
    def is_locked(self):
191
        return (self._lock_mode is not None)
192
193
    def get_transaction(self):
194
        """See Repository.get_transaction()."""
0.334.1 by Jelmer Vernooij
Improve transaction and write group handling.
195
        if self._transaction is None:
0.200.1411 by Jelmer Vernooij
Fix control files.
196
            return transactions.PassThroughTransaction()
197
        else:
0.334.1 by Jelmer Vernooij
Improve transaction and write group handling.
198
            return self._transaction
0.200.1411 by Jelmer Vernooij
Fix control files.
199
0.200.1246 by Jelmer Vernooij
Provide GitRepository.reconcile.
200
    def reconcile(self, other=None, thorough=False):
201
        """Reconcile this repository."""
7206.6.4 by Jelmer Vernooij
Move reconcile logic to breezy.bzr.reconcile.
202
        from ..reconcile import ReconcileResult
203
        ret = ReconcileResult()
204
        ret.aborted = False
205
        return ret
0.200.1246 by Jelmer Vernooij
Provide GitRepository.reconcile.
206
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
207
    def supports_rich_root(self):
208
        return True
209
210
    def get_mapping(self):
211
        return default_mapping
212
0.200.147 by Jelmer Vernooij
Merge new dulwich; fetching objects from local repository works now; they aren't converted yet though.
213
    def make_working_trees(self):
0.200.1546 by Jelmer Vernooij
Provide get_config.
214
        return not self._git.get_config().get_boolean(("core", ), "bare")
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
215
0.200.557 by Jelmer Vernooij
Implement GitRepository.revision_graph_can_have_wrong_parents().
216
    def revision_graph_can_have_wrong_parents(self):
217
        return False
218
0.200.1158 by Jelmer Vernooij
Implement stub Repositor.add_signature_text.
219
    def add_signature_text(self, revid, signature):
220
        raise errors.UnsupportedOperation(self.add_signature_text, self)
221
0.200.1467 by Jelmer Vernooij
Implement GitRepository.sign_revision.
222
    def sign_revision(self, revision_id, gpg_strategy):
223
        raise errors.UnsupportedOperation(self.add_signature_text, self)
224
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
225
226
class LocalGitRepository(GitRepository):
0.200.276 by Jelmer Vernooij
Improve formatting.
227
    """Git repository on the file system."""
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
228
0.200.1411 by Jelmer Vernooij
Fix control files.
229
    def __init__(self, gitdir):
230
        GitRepository.__init__(self, gitdir)
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
231
        self._git = gitdir._git
0.200.1283 by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision().
232
        self._file_change_scanner = GitFileLastChangeScanner(self)
0.334.1 by Jelmer Vernooij
Improve transaction and write group handling.
233
        self._transaction = None
0.200.45 by David Allouche
More performance hacking, introduce sqlite cache, escape characters in commits that break serializers.
234
0.200.1224 by Jelmer Vernooij
provide explicit GitRepository.get_commit_builder.
235
    def get_commit_builder(self, branch, parents, config, timestamp=None,
236
                           timezone=None, committer=None, revprops=None,
237
                           revision_id=None, lossy=False):
238
        """Obtain a CommitBuilder for this repository.
239
240
        :param branch: Branch to commit to.
241
        :param parents: Revision ids of the parents of the new revision.
242
        :param config: Configuration to use.
243
        :param timestamp: Optional timestamp recorded for commit.
244
        :param timezone: Optional timezone for timestamp.
245
        :param committer: Optional committer to set for commit.
246
        :param revprops: Optional dictionary of revision properties.
247
        :param revision_id: Optional revision id.
248
        :param lossy: Whether to discard data that can not be natively
249
            represented, when pushing to a foreign VCS
250
        """
7490.62.3 by Jelmer Vernooij
Move btree and remove references.
251
        from .commit import (
252
            GitCommitBuilder,
253
            )
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
254
        builder = GitCommitBuilder(
255
            self, parents, config, timestamp, timezone, committer, revprops,
256
            revision_id, lossy)
0.200.1229 by Jelmer Vernooij
Provide CommitBuilder.any_changes.
257
        self.start_write_group()
0.294.1 by Jelmer Vernooij
Fix write group handling when creating commit builder fails.
258
        return builder
0.200.1224 by Jelmer Vernooij
provide explicit GitRepository.get_commit_builder.
259
0.200.1283 by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision().
260
    def get_file_graph(self):
0.200.1307 by Jelmer Vernooij
Formatting fixes, specify path to a couple more functions.
261
        return _mod_graph.Graph(GitFileParentProvider(
262
            self._file_change_scanner))
0.200.1283 by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision().
263
0.200.1233 by Jelmer Vernooij
Implement Repository.iter_files_bytes.
264
    def iter_files_bytes(self, desired_files):
265
        """Iterate through file versions.
266
267
        Files will not necessarily be returned in the order they occur in
268
        desired_files.  No specific order is guaranteed.
269
270
        Yields pairs of identifier, bytes_iterator.  identifier is an opaque
271
        value supplied by the caller as part of desired_files.  It should
272
        uniquely identify the file version in the caller's context.  (Examples:
273
        an index number or a TreeTransform trans_id.)
274
275
        bytes_iterator is an iterable of bytestrings for the file.  The
276
        kind of iterable and length of the bytestrings are unspecified, but for
277
        this implementation, it is a list of bytes produced by
278
        VersionedFile.get_record_stream().
279
280
        :param desired_files: a list of (file_id, revision_id, identifier)
281
            triples
282
        """
283
        per_revision = {}
284
        for (file_id, revision_id, identifier) in desired_files:
0.200.1307 by Jelmer Vernooij
Formatting fixes, specify path to a couple more functions.
285
            per_revision.setdefault(revision_id, []).append(
286
                (file_id, identifier))
7479.2.1 by Jelmer Vernooij
Drop python2 support.
287
        for revid, files in per_revision.items():
0.200.1745 by Jelmer Vernooij
Fix iter_files_bytes.
288
            try:
289
                (commit_id, mapping) = self.lookup_bzr_revision_id(revid)
290
            except errors.NoSuchRevision:
291
                raise errors.RevisionNotPresent(revid, self)
0.200.1233 by Jelmer Vernooij
Implement Repository.iter_files_bytes.
292
            try:
293
                commit = self._git.object_store[commit_id]
294
            except KeyError:
295
                raise errors.RevisionNotPresent(revid, self)
296
            root_tree = commit.tree
297
            for fileid, identifier in files:
0.200.1715 by Jelmer Vernooij
Fix some more tests.
298
                try:
299
                    path = mapping.parse_file_id(fileid)
300
                except ValueError:
301
                    raise errors.RevisionNotPresent((fileid, revid), self)
0.200.1233 by Jelmer Vernooij
Implement Repository.iter_files_bytes.
302
                try:
303
                    obj = tree_lookup_path(
7045.4.1 by Jelmer Vernooij
Some brz-git fixes.
304
                        self._git.object_store.__getitem__, root_tree,
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
305
                        encode_git_path(path))
0.200.1233 by Jelmer Vernooij
Implement Repository.iter_files_bytes.
306
                    if isinstance(obj, tuple):
307
                        (mode, item_id) = obj
308
                        obj = self._git.object_store[item_id]
309
                except KeyError:
310
                    raise errors.RevisionNotPresent((fileid, revid), self)
311
                else:
7045.2.13 by Jelmer Vernooij
Fix some workingtree_4 tests.
312
                    if obj.type_name == b"tree":
0.200.1233 by Jelmer Vernooij
Implement Repository.iter_files_bytes.
313
                        yield (identifier, [])
7045.2.13 by Jelmer Vernooij
Fix some workingtree_4 tests.
314
                    elif obj.type_name == b"blob":
0.200.1233 by Jelmer Vernooij
Implement Repository.iter_files_bytes.
315
                        yield (identifier, obj.chunked)
316
                    else:
317
                        raise AssertionError("file text resolved to %r" % obj)
318
0.200.1533 by Jelmer Vernooij
Improve gather_stats.
319
    def gather_stats(self, revid=None, committers=None):
320
        """See Repository.gather_stats()."""
7143.15.2 by Jelmer Vernooij
Run autopep8.
321
        result = super(LocalGitRepository, self).gather_stats(
322
            revid, committers)
0.200.1533 by Jelmer Vernooij
Improve gather_stats.
323
        revs = []
324
        for sha in self._git.object_store:
325
            o = self._git.object_store[sha]
7045.2.13 by Jelmer Vernooij
Fix some workingtree_4 tests.
326
            if o.type_name == b"commit":
0.200.1533 by Jelmer Vernooij
Improve gather_stats.
327
                revs.append(o.id)
328
        result['revisions'] = len(revs)
329
        return result
330
0.252.46 by Jelmer Vernooij
Generate refs/bzr/* if not set yet.
331
    def _iter_revision_ids(self):
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
332
        mapping = self.get_mapping()
0.252.21 by Jelmer Vernooij
Fix GitRepository.all_revision_ids() to find all revisions.
333
        for sha in self._git.object_store:
334
            o = self._git.object_store[sha]
335
            if not isinstance(o, Commit):
336
                continue
7464.3.2 by Jelmer Vernooij
Drop reverse roundtripping support.
337
            revid = mapping.revision_id_foreign_to_bzr(o.id)
7464.3.1 by Jelmer Vernooij
Drop roundtripping support in git repositories.
338
            yield o.id, revid
0.252.46 by Jelmer Vernooij
Generate refs/bzr/* if not set yet.
339
340
    def all_revision_ids(self):
0.200.1727 by Jelmer Vernooij
Change all_revision_ids type to list.
341
        ret = set()
7464.3.1 by Jelmer Vernooij
Drop roundtripping support in git repositories.
342
        for git_sha, revid in self._iter_revision_ids():
343
            ret.add(revid)
0.200.1727 by Jelmer Vernooij
Change all_revision_ids type to list.
344
        return list(ret)
0.200.74 by Jelmer Vernooij
Implement Repository.all_revision_ids().
345
0.200.1552 by Jelmer Vernooij
Claim to support nested trees.
346
    def _get_parents(self, revid, no_alternates=False):
0.200.1756 by Jelmer Vernooij
Initial work on annotate support.
347
        if type(revid) != bytes:
0.200.1328 by Jelmer Vernooij
More test fixes.
348
            raise ValueError
349
        try:
0.200.1343 by Jelmer Vernooij
Update docstrings.
350
            (hexsha, mapping) = self.lookup_bzr_revision_id(revid)
0.200.1328 by Jelmer Vernooij
More test fixes.
351
        except errors.NoSuchRevision:
352
            return None
0.200.1552 by Jelmer Vernooij
Claim to support nested trees.
353
        # FIXME: Honor no_alternates setting
0.200.1328 by Jelmer Vernooij
More test fixes.
354
        try:
0.200.1553 by Jelmer Vernooij
Avoid using nonexistant method.
355
            commit = self._git.object_store[hexsha]
0.200.1328 by Jelmer Vernooij
More test fixes.
356
        except KeyError:
357
            return None
6965.1.1 by Jelmer Vernooij
Add basic support for horizoned history.
358
        ret = []
359
        for p in commit.parents:
360
            try:
361
                ret.append(self.lookup_foreign_revision_id(p, mapping))
362
            except KeyError:
363
                ret.append(mapping.revision_id_foreign_to_bzr(p))
364
        return ret
0.200.1328 by Jelmer Vernooij
More test fixes.
365
0.200.1552 by Jelmer Vernooij
Claim to support nested trees.
366
    def _get_parent_map_no_fallbacks(self, revids):
367
        return self.get_parent_map(revids, no_alternates=True)
368
369
    def get_parent_map(self, revids, no_alternates=False):
0.200.131 by Jelmer Vernooij
Fix all tests but two, use rich roots by default.
370
        parent_map = {}
371
        for revision_id in revids:
7143.15.2 by Jelmer Vernooij
Run autopep8.
372
            parents = self._get_parents(
373
                revision_id, no_alternates=no_alternates)
0.285.5 by Jelmer Vernooij
Fix import.
374
            if revision_id == _mod_revision.NULL_REVISION:
0.200.1329 by Jelmer Vernooij
Fix more tests.
375
                parent_map[revision_id] = ()
376
                continue
0.200.1328 by Jelmer Vernooij
More test fixes.
377
            if parents is None:
378
                continue
0.200.1324 by Jelmer Vernooij
More work on roundtripping support.
379
            if len(parents) == 0:
0.285.5 by Jelmer Vernooij
Fix import.
380
                parents = [_mod_revision.NULL_REVISION]
0.200.1094 by Jelmer Vernooij
Fix test_get_no_parents.
381
            parent_map[revision_id] = tuple(parents)
0.200.131 by Jelmer Vernooij
Fix all tests but two, use rich roots by default.
382
        return parent_map
383
0.200.1281 by Jelmer Vernooij
Provide Repository.get_known_graph_ancestry.
384
    def get_known_graph_ancestry(self, revision_ids):
385
        """Return the known graph for a set of revision ids and their ancestors.
386
        """
387
        pending = set(revision_ids)
388
        parent_map = {}
389
        while pending:
0.200.1328 by Jelmer Vernooij
More test fixes.
390
            this_parent_map = {}
391
            for revid in pending:
0.285.5 by Jelmer Vernooij
Fix import.
392
                if revid == _mod_revision.NULL_REVISION:
0.200.1328 by Jelmer Vernooij
More test fixes.
393
                    continue
394
                parents = self._get_parents(revid)
395
                if parents is not None:
396
                    this_parent_map[revid] = parents
0.200.1281 by Jelmer Vernooij
Provide Repository.get_known_graph_ancestry.
397
            parent_map.update(this_parent_map)
398
            pending = set()
7479.2.1 by Jelmer Vernooij
Drop python2 support.
399
            for values in this_parent_map.values():
7045.4.4 by Jelmer Vernooij
Fix more git tests.
400
                pending.update(values)
0.200.1281 by Jelmer Vernooij
Provide Repository.get_known_graph_ancestry.
401
            pending = pending.difference(parent_map)
402
        return _mod_graph.KnownGraph(parent_map)
403
0.200.43 by David Allouche
Ultra-experimental support for "bzr pull". No test. No sanity.
404
    def get_signature_text(self, revision_id):
0.386.1 by Jelmer Vernooij
Support signing commits.
405
        git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
406
        try:
407
            commit = self._git.object_store[git_commit_id]
408
        except KeyError:
409
            raise errors.NoSuchRevision(self, revision_id)
410
        if commit.gpgsig is None:
411
            raise errors.NoSuchRevision(self, revision_id)
412
        return commit.gpgsig
0.200.43 by David Allouche
Ultra-experimental support for "bzr pull". No test. No sanity.
413
0.200.1244 by Jelmer Vernooij
Implement GitRepository.check.
414
    def check(self, revision_ids=None, callback_refs=None, check_repo=True):
415
        result = GitCheck(self, check_repo=check_repo)
416
        result.check(callback_refs)
417
        return result
418
0.257.1 by Jelmer Vernooij
use transport repo objects even for local access.
419
    def pack(self, hint=None, clean_obsolete_packs=False):
420
        self._git.object_store.pack_loose_objects()
421
0.200.650 by Jelmer Vernooij
Use standard names for lookup functions.
422
    def lookup_foreign_revision_id(self, foreign_revid, mapping=None):
0.200.124 by Jelmer Vernooij
Add lookup_revision_id stub.
423
        """Lookup a revision id.
0.200.676 by Jelmer Vernooij
Avoid iterating over all keys in the tdb database.
424
0.200.1508 by Jelmer Vernooij
Add docstring, use peel_sha.
425
        :param foreign_revid: Foreign revision id to look up
426
        :param mapping: Mapping to use (use default mapping if not specified)
427
        :raise KeyError: If foreign revision was not found
428
        :return: bzr revision id
0.200.124 by Jelmer Vernooij
Add lookup_revision_id stub.
429
        """
7018.3.2 by Jelmer Vernooij
Fix some git tests.
430
        if not isinstance(foreign_revid, bytes):
0.361.1 by Jelmer Vernooij
Don't use assert.
431
            raise TypeError(foreign_revid)
0.200.649 by Jelmer Vernooij
Make GitRevisions VF implementation behave as the interface expects.
432
        if mapping is None:
433
            mapping = self.get_mapping()
0.200.914 by Jelmer Vernooij
Fix tests.
434
        if foreign_revid == ZERO_SHA:
0.285.5 by Jelmer Vernooij
Fix import.
435
            return _mod_revision.NULL_REVISION
0.200.1508 by Jelmer Vernooij
Add docstring, use peel_sha.
436
        commit = self._git.object_store.peel_sha(foreign_revid)
0.200.1403 by Jelmer Vernooij
Cope with tags pointing at tree objects when cloning local git repositories.
437
        if not isinstance(commit, Commit):
438
            raise NotCommitError(commit.id)
7268.1.2 by Jelmer Vernooij
Allow access to native git repositories, ignoring unknown hg fields.
439
        revid = mapping.get_revision_id(commit)
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
440
        # FIXME: check testament before doing this?
7268.1.2 by Jelmer Vernooij
Allow access to native git repositories, ignoring unknown hg fields.
441
        return revid
0.200.124 by Jelmer Vernooij
Add lookup_revision_id stub.
442
0.200.60 by Jelmer Vernooij
Support signature functions.
443
    def has_signature_for_revision_id(self, revision_id):
0.200.1343 by Jelmer Vernooij
Update docstrings.
444
        """Check whether a GPG signature is present for this revision.
445
446
        This is never the case for Git repositories.
447
        """
0.386.2 by Jelmer Vernooij
Support verifying signatures.
448
        try:
449
            self.get_signature_text(revision_id)
450
        except errors.NoSuchRevision:
451
            return False
452
        else:
453
            return True
454
455
    def verify_revision_signature(self, revision_id, gpg_strategy):
456
        """Verify the signature on a revision.
457
458
        :param revision_id: the revision to verify
459
        :gpg_strategy: the GPGStrategy object to used
460
461
        :return: gpg.SIGNATURE_VALID or a failed SIGNATURE_ value
462
        """
463
        from breezy import gpg
464
        with self.lock_read():
465
            git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
466
            try:
467
                commit = self._git.object_store[git_commit_id]
468
            except KeyError:
469
                raise errors.NoSuchRevision(self, revision_id)
470
471
            if commit.gpgsig is None:
472
                return gpg.SIGNATURE_NOT_SIGNED, None
473
474
            without_sig = Commit.from_string(commit.as_raw_string())
475
            without_sig.gpgsig = None
476
7143.15.2 by Jelmer Vernooij
Run autopep8.
477
            (result, key, plain_text) = gpg_strategy.verify(
478
                without_sig.as_raw_string(), commit.gpgsig)
0.386.3 by Jelmer Vernooij
use new API.
479
            return (result, key)
0.200.60 by Jelmer Vernooij
Support signature functions.
480
0.200.913 by Jelmer Vernooij
Fix tests.
481
    def lookup_bzr_revision_id(self, bzr_revid, mapping=None):
0.200.1343 by Jelmer Vernooij
Update docstrings.
482
        """Lookup a bzr revision id in a Git repository.
483
484
        :param bzr_revid: Bazaar revision id
485
        :param mapping: Optional mapping to use
486
        :return: Tuple with git commit id, mapping that was used and supplement
487
            details
488
        """
0.200.105 by Jelmer Vernooij
Add common function for finding git commit by bzr revid.
489
        try:
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
490
            (git_sha, mapping) = mapping_registry.revision_id_bzr_to_foreign(
491
                bzr_revid)
0.200.105 by Jelmer Vernooij
Add common function for finding git commit by bzr revid.
492
        except errors.InvalidRevisionId:
7464.3.1 by Jelmer Vernooij
Drop roundtripping support in git repositories.
493
            raise errors.NoSuchRevision(self, bzr_revid)
0.200.1343 by Jelmer Vernooij
Update docstrings.
494
        else:
495
            return (git_sha, mapping)
0.200.105 by Jelmer Vernooij
Add common function for finding git commit by bzr revid.
496
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
497
    def get_revision(self, revision_id):
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
498
        if not isinstance(revision_id, bytes):
0.200.1101 by Jelmer Vernooij
Raise InvalidRevisionId on invalid type being specified to Repository.get_revision.
499
            raise errors.InvalidRevisionId(revision_id, self)
0.200.650 by Jelmer Vernooij
Use standard names for lookup functions.
500
        git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
0.200.147 by Jelmer Vernooij
Merge new dulwich; fetching objects from local repository works now; they aren't converted yet though.
501
        try:
0.200.1552 by Jelmer Vernooij
Claim to support nested trees.
502
            commit = self._git.object_store[git_commit_id]
0.200.147 by Jelmer Vernooij
Merge new dulwich; fetching objects from local repository works now; they aren't converted yet though.
503
        except KeyError:
504
            raise errors.NoSuchRevision(self, revision_id)
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
505
        revision, roundtrip_revid, verifiers = mapping.import_commit(
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
506
            commit, self.lookup_foreign_revision_id, strict=False)
0.361.1 by Jelmer Vernooij
Don't use assert.
507
        if revision is None:
508
            raise AssertionError
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
509
        # FIXME: check verifiers ?
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
510
        if roundtrip_revid:
511
            revision.revision_id = roundtrip_revid
0.200.43 by David Allouche
Ultra-experimental support for "bzr pull". No test. No sanity.
512
        return revision
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
513
514
    def has_revision(self, revision_id):
0.200.1119 by Jelmer Vernooij
Refactor repository initialization.
515
        """See Repository.has_revision."""
0.285.5 by Jelmer Vernooij
Fix import.
516
        if revision_id == _mod_revision.NULL_REVISION:
0.200.1122 by Jelmer Vernooij
has_revision(null:) should always return True.
517
            return True
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
518
        try:
0.200.902 by Jelmer Vernooij
Fix Repository.has_revision{s,}.
519
            git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
0.200.130 by Jelmer Vernooij
Make most tree inspection tests succeed.
520
        except errors.NoSuchRevision:
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
521
            return False
0.200.902 by Jelmer Vernooij
Fix Repository.has_revision{s,}.
522
        return (git_commit_id in self._git)
523
524
    def has_revisions(self, revision_ids):
0.200.1119 by Jelmer Vernooij
Refactor repository initialization.
525
        """See Repository.has_revisions."""
0.200.913 by Jelmer Vernooij
Fix tests.
526
        return set(filter(self.has_revision, revision_ids))
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
527
0.200.1657 by Jelmer Vernooij
Implement iter_revisions.
528
    def iter_revisions(self, revision_ids):
0.200.1119 by Jelmer Vernooij
Refactor repository initialization.
529
        """See Repository.get_revisions."""
0.200.1657 by Jelmer Vernooij
Implement iter_revisions.
530
        for revid in revision_ids:
531
            try:
532
                rev = self.get_revision(revid)
533
            except errors.NoSuchRevision:
534
                rev = None
535
            yield (revid, rev)
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
536
537
    def revision_trees(self, revids):
0.200.1119 by Jelmer Vernooij
Refactor repository initialization.
538
        """See Repository.revision_trees."""
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
539
        for revid in revids:
540
            yield self.revision_tree(revid)
541
542
    def revision_tree(self, revision_id):
0.200.1119 by Jelmer Vernooij
Refactor repository initialization.
543
        """See Repository.revision_tree."""
0.287.6 by Jelmer Vernooij
Fix some more tests.
544
        if revision_id is None:
545
            raise ValueError('invalid revision id %s' % revision_id)
0.200.195 by Jelmer Vernooij
Return mapping in revision_id_bzr_to_foreign() as required by the interface.
546
        return GitRevisionTree(self, revision_id)
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
547
0.200.108 by Jelmer Vernooij
Support bzr init --git.
548
    def set_make_working_trees(self, trees):
0.287.6 by Jelmer Vernooij
Fix some more tests.
549
        raise errors.UnsupportedOperation(self.set_make_working_trees, self)
0.200.108 by Jelmer Vernooij
Support bzr init --git.
550
0.200.276 by Jelmer Vernooij
Improve formatting.
551
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
7143.15.2 by Jelmer Vernooij
Run autopep8.
552
                      progress=None, limit=None):
0.286.6 by Jelmer Vernooij
Pass through limit argument.
553
        return self._git.fetch_objects(determine_wants, graph_walker, progress,
7143.15.2 by Jelmer Vernooij
Run autopep8.
554
                                       limit=limit)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
555
0.200.43 by David Allouche
Ultra-experimental support for "bzr pull". No test. No sanity.
556
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
557
class GitRepositoryFormat(repository.RepositoryFormat):
0.200.429 by Jelmer Vernooij
get remote dpush to a point where we now what to send.
558
    """Git repository format."""
0.203.1 by Aaron Bentley
Make checkouts work
559
0.200.1294 by Jelmer Vernooij
Mark as not supporting versioned directories.
560
    supports_versioned_directories = False
0.429.2 by Jelmer Vernooij
Some more work on submodule support.
561
    supports_tree_reference = True
0.200.133 by Jelmer Vernooij
Unmark as deprecated.
562
    rich_root_data = True
0.200.1105 by Jelmer Vernooij
Don't claim to support leaving locks.
563
    supports_leaving_lock = False
0.200.1106 by Jelmer Vernooij
Claim to support fast deltas.
564
    fast_deltas = True
0.200.1123 by Jelmer Vernooij
Set more repository format flags.
565
    supports_funky_characters = True
0.200.1560 by Jelmer Vernooij
stacking is not supported.
566
    supports_external_lookups = False
0.200.1135 by Jelmer Vernooij
Set supports_full_versioned_files=False.
567
    supports_full_versioned_files = False
0.200.1162 by Jelmer Vernooij
Set RepositoryFormat.supports_revision_signatures.
568
    supports_revision_signatures = False
0.200.1383 by Jelmer Vernooij
Claim to not support nested repositories.
569
    supports_nesting_repositories = False
0.200.1166 by Jelmer Vernooij
Set GitRepositoryFormat.revision_graph_can_have_wrong_parents.
570
    revision_graph_can_have_wrong_parents = False
0.200.1493 by Jelmer Vernooij
Test fixes.
571
    supports_unreferenced_revisions = True
0.200.1665 by Jelmer Vernooij
Rename _matchingbzrdir to _matchingcnotroldir.
572
    supports_setting_revision_ids = False
0.200.1698 by Jelmer Vernooij
Update xfail.
573
    supports_storing_branch_nick = False
574
    supports_overriding_transport = False
0.200.1746 by Jelmer Vernooij
Mark as not supporting custom revision properties.
575
    supports_custom_revision_properties = False
0.396.1 by Jelmer Vernooij
Mark as not support per file revision recording.
576
    records_per_file_revision = False
0.200.71 by Jelmer Vernooij
Implement GitRepositoryFormat.get_format_description.
577
0.200.1083 by Jelmer Vernooij
Register repository format.
578
    @property
0.200.1665 by Jelmer Vernooij
Rename _matchingbzrdir to _matchingcnotroldir.
579
    def _matchingcontroldir(self):
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
580
        from .dir import LocalGitControlDirFormat
0.200.1083 by Jelmer Vernooij
Register repository format.
581
        return LocalGitControlDirFormat()
582
0.200.71 by Jelmer Vernooij
Implement GitRepositoryFormat.get_format_description.
583
    def get_format_description(self):
584
        return "Git Repository"
0.200.133 by Jelmer Vernooij
Unmark as deprecated.
585
0.200.1084 by Jelmer Vernooij
Support 'initializing' repositories in control directories.
586
    def initialize(self, controldir, shared=False, _internal=False):
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
587
        from .dir import GitDir
0.200.1084 by Jelmer Vernooij
Support 'initializing' repositories in control directories.
588
        if not isinstance(controldir, GitDir):
589
            raise errors.UninitializableFormat(self)
590
        return controldir.open_repository()
0.200.133 by Jelmer Vernooij
Unmark as deprecated.
591
592
    def check_conversion_target(self, target_repo_format):
593
        return target_repo_format.rich_root_data
0.200.536 by Jelmer Vernooij
Implement network name.
594
0.200.658 by Jelmer Vernooij
Provide right infrastructure for foreign repository tests from bzrlib.
595
    def get_foreign_tests_repository_factory(self):
0.200.1654 by Jelmer Vernooij
Fix test import.
596
        from .tests.test_repository import (
0.200.713 by Jelmer Vernooij
Improve formatting.
597
            ForeignTestsRepositoryFactory,
598
            )
0.200.658 by Jelmer Vernooij
Provide right infrastructure for foreign repository tests from bzrlib.
599
        return ForeignTestsRepositoryFactory()
600
0.200.536 by Jelmer Vernooij
Implement network name.
601
    def network_name(self):
6973.7.8 by Jelmer Vernooij
Fix more tests.
602
        return b"git"
6989.2.6 by Jelmer Vernooij
Run tests against brz-git interrepositories.
603
604
605
def get_extra_interrepo_test_combinations():
6986.2.2 by Jelmer Vernooij
Merge trunk.
606
    from ..bzr.groupcompress_repo import RepositoryFormat2a
6989.2.6 by Jelmer Vernooij
Run tests against brz-git interrepositories.
607
    from . import interrepo
608
    return [
7143.15.2 by Jelmer Vernooij
Run autopep8.
609
        (interrepo.InterLocalGitNonGitRepository,
610
         GitRepositoryFormat(), RepositoryFormat2a()),
611
        (interrepo.InterLocalGitLocalGitRepository,
612
         GitRepositoryFormat(), GitRepositoryFormat()),
613
        (interrepo.InterToLocalGitRepository,
614
         RepositoryFormat2a(), GitRepositoryFormat()),
6989.2.6 by Jelmer Vernooij
Run tests against brz-git interrepositories.
615
        ]