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