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