/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
1
# Copyright (C) 2007 Canonical Ltd
0.200.252 by Jelmer Vernooij
Clarify history, copyright.
2
# Copyright (C) 2008-2009 Jelmer Vernooij <jelmer@samba.org>
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
"""An adapter between a Git Repository and a Bazaar Branch"""
19
20
from bzrlib 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.38 by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster.
24
    inventory,
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
25
    repository,
0.200.29 by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes.
26
    revision,
0.200.1411 by Jelmer Vernooij
Fix control files.
27
    transactions,
0.200.1427 by Jelmer Vernooij
fix 2.3 and 2.4 compatibility.
28
    version_info as bzrlib_version,
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
29
    )
0.200.1411 by Jelmer Vernooij
Fix control files.
30
from bzrlib.decorators import only_raises
0.200.1186 by Jelmer Vernooij
Cope with InventoryRevisionTree.
31
try:
32
    from bzrlib.revisiontree import InventoryRevisionTree
33
except ImportError: # bzr < 2.4
34
    from bzrlib.revisiontree import RevisionTree as InventoryRevisionTree
0.200.115 by Jelmer Vernooij
Pass mapping object.
35
from bzrlib.foreign import (
0.200.292 by Jelmer Vernooij
Fix formatting.
36
    ForeignRepository,
37
    )
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
38
0.200.387 by Jelmer Vernooij
Initial work on supporting commit in git trees.
39
from bzrlib.plugins.git.commit import (
40
    GitCommitBuilder,
41
    )
0.200.1403 by Jelmer Vernooij
Cope with tags pointing at tree objects when cloning local git repositories.
42
from bzrlib.plugins.git.errors import (
43
    NotCommitError,
44
    )
0.200.1283 by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision().
45
from bzrlib.plugins.git.filegraph import (
46
    GitFileLastChangeScanner,
47
    GitFileParentProvider,
48
    )
0.200.256 by Jelmer Vernooij
Add tests for import_revision_gist.
49
from bzrlib.plugins.git.mapping import (
50
    default_mapping,
0.200.1263 by Jelmer Vernooij
Fix foreign_vcs_git.
51
    foreign_vcs_git,
0.200.256 by Jelmer Vernooij
Add tests for import_revision_gist.
52
    mapping_registry,
53
    )
0.200.617 by Jelmer Vernooij
Add custom InterTree for use between git revision trees.
54
from bzrlib.plugins.git.tree import (
55
    GitRevisionTree,
56
    )
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
57
58
0.252.21 by Jelmer Vernooij
Fix GitRepository.all_revision_ids() to find all revisions.
59
from dulwich.objects import (
60
    Commit,
0.200.1080 by Jelmer Vernooij
Fix handling of annotated tags when cloning from local repo.
61
    Tag,
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.1246 by Jelmer Vernooij
Provide GitRepository.reconcile.
69
class RepoReconciler(object):
70
    """Reconciler that reconciles a repository.
71
72
    """
73
74
    def __init__(self, repo, other=None, thorough=False):
75
        """Construct a RepoReconciler.
76
77
        :param thorough: perform a thorough check which may take longer but
78
                         will correct non-data loss issues such as incorrect
79
                         cached data.
80
        """
81
        self.repo = repo
82
83
    def reconcile(self):
84
        """Perform reconciliation.
85
86
        After reconciliation the following attributes document found issues:
87
        inconsistent_parents: The number of revisions in the repository whose
88
                              ancestry was being reported incorrectly.
89
        garbage_inventories: The number of inventory objects without revisions
90
                             that were garbage collected.
91
        """
92
93
0.200.1244 by Jelmer Vernooij
Implement GitRepository.check.
94
class GitCheck(check.Check):
95
96
    def __init__(self, repository, check_repo=True):
97
        self.repository = repository
98
        self.checked_rev_cnt = 0
99
100
    def check(self, callback_refs=None, check_repo=True):
101
        if callback_refs is None:
102
            callback_refs = {}
103
        self.repository.lock_read()
104
        self.repository.unlock()
105
106
    def report_results(self, verbose):
107
        pass
108
109
0.200.115 by Jelmer Vernooij
Pass mapping object.
110
class GitRepository(ForeignRepository):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
111
    """An adapter to git repositories for bzr."""
112
0.200.41 by David Allouche
Define _serializer = None in GitRepository.
113
    _serializer = None
0.200.1263 by Jelmer Vernooij
Fix foreign_vcs_git.
114
    vcs = foreign_vcs_git
0.200.1086 by Jelmer Vernooij
Provide chk_bytes attribute.
115
    chk_bytes = None
0.200.41 by David Allouche
Define _serializer = None in GitRepository.
116
0.200.1411 by Jelmer Vernooij
Fix control files.
117
    def __init__(self, gitdir):
0.200.1427 by Jelmer Vernooij
fix 2.3 and 2.4 compatibility.
118
        if bzrlib_version >= (2, 5):
119
            control_files = None
120
        else:
121
            class DummyControlFiles(object):
122
                def __init__(self):
123
                    self._transport = gitdir.root_transport
124
            control_files = DummyControlFiles()
0.200.1307 by Jelmer Vernooij
Formatting fixes, specify path to a couple more functions.
125
        super(GitRepository, self).__init__(GitRepositoryFormat(),
0.200.1427 by Jelmer Vernooij
fix 2.3 and 2.4 compatibility.
126
            gitdir, control_files)
0.200.1411 by Jelmer Vernooij
Fix control files.
127
        self._transport = gitdir.root_transport
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
128
        from bzrlib.plugins.git import fetch, push
0.200.676 by Jelmer Vernooij
Avoid iterating over all keys in the tdb database.
129
        for optimiser in [fetch.InterRemoteGitNonGitRepository,
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
130
                          fetch.InterLocalGitNonGitRepository,
0.200.456 by Jelmer Vernooij
Fix git -> git fetching.
131
                          fetch.InterGitGitRepository,
0.200.425 by Jelmer Vernooij
Split out push to remote git repositories.
132
                          push.InterToLocalGitRepository,
133
                          push.InterToRemoteGitRepository]:
0.200.276 by Jelmer Vernooij
Improve formatting.
134
            repository.InterRepository.register_optimiser(optimiser)
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,
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:
151
            assert self._lock_mode == 'w'
152
            self._lock_count += 1
153
        else:
154
            self._lock_mode = 'w'
155
            self._lock_count = 1
156
        return GitRepositoryLock(self)
157
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:
166
            assert self._lock_mode in ('r', 'w')
167
            self._lock_count += 1
168
        else:
169
            self._lock_mode = 'r'
170
            self._lock_count = 1
171
        return self
172
173
    @only_raises(errors.LockNotHeld, errors.LockBroken)
174
    def unlock(self):
175
        if self._lock_count == 0:
176
            raise errors.LockNotHeld(self)
177
        if self._lock_count == 1 and self._lock_mode == 'w':
178
            if self._write_group is not None:
179
                self.abort_write_group()
180
                self._lock_count -= 1
181
                self._lock_mode = None
182
                raise errors.BzrError(
183
                    'Must end write groups before releasing write locks.')
184
        self._lock_count -= 1
185
        if self._lock_count == 0:
186
            self._lock_mode = None
187
188
    def is_write_locked(self):
189
        return (self._lock_mode == 'w')
190
191
    def is_locked(self):
192
        return (self._lock_mode is not None)
193
194
    def get_transaction(self):
195
        """See Repository.get_transaction()."""
196
        if self._write_group is None:
197
            return transactions.PassThroughTransaction()
198
        else:
199
            return self._write_group
200
0.200.1246 by Jelmer Vernooij
Provide GitRepository.reconcile.
201
    def reconcile(self, other=None, thorough=False):
202
        """Reconcile this repository."""
203
        reconciler = RepoReconciler(self, thorough=thorough)
204
        reconciler.reconcile()
205
        return reconciler
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
0.200.1111 by Jelmer Vernooij
Drop support for Bazaar < 2.3.
210
    def _warn_if_deprecated(self, branch=None): # for bzr < 2.4
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
211
        # This class isn't deprecated
212
        pass
213
214
    def get_mapping(self):
215
        return default_mapping
216
0.200.147 by Jelmer Vernooij
Merge new dulwich; fetching objects from local repository works now; they aren't converted yet though.
217
    def make_working_trees(self):
0.200.1033 by Jelmer Vernooij
Don't claim to support working trees for bare repositories.
218
        return not self._git.bare
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
219
0.200.557 by Jelmer Vernooij
Implement GitRepository.revision_graph_can_have_wrong_parents().
220
    def revision_graph_can_have_wrong_parents(self):
221
        return False
222
0.200.1158 by Jelmer Vernooij
Implement stub Repositor.add_signature_text.
223
    def add_signature_text(self, revid, signature):
224
        raise errors.UnsupportedOperation(self.add_signature_text, self)
225
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
226
0.200.1411 by Jelmer Vernooij
Fix control files.
227
class GitRepositoryLock(object):
228
    """Subversion lock."""
229
230
    def __init__(self, repository):
231
        self.repository_token = None
232
        self.repository = repository
233
234
    def unlock(self):
235
        self.repository.unlock()
236
237
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
238
class LocalGitRepository(GitRepository):
0.200.276 by Jelmer Vernooij
Improve formatting.
239
    """Git repository on the file system."""
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
240
0.200.1411 by Jelmer Vernooij
Fix control files.
241
    def __init__(self, gitdir):
242
        GitRepository.__init__(self, gitdir)
0.200.61 by Jelmer Vernooij
Fix tests.
243
        self.base = gitdir.root_transport.base
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
244
        self._git = gitdir._git
0.200.1283 by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision().
245
        self._file_change_scanner = GitFileLastChangeScanner(self)
0.200.45 by David Allouche
More performance hacking, introduce sqlite cache, escape characters in commits that break serializers.
246
0.200.1224 by Jelmer Vernooij
provide explicit GitRepository.get_commit_builder.
247
    def get_commit_builder(self, branch, parents, config, timestamp=None,
248
                           timezone=None, committer=None, revprops=None,
249
                           revision_id=None, lossy=False):
250
        """Obtain a CommitBuilder for this repository.
251
252
        :param branch: Branch to commit to.
253
        :param parents: Revision ids of the parents of the new revision.
254
        :param config: Configuration to use.
255
        :param timestamp: Optional timestamp recorded for commit.
256
        :param timezone: Optional timezone for timestamp.
257
        :param committer: Optional committer to set for commit.
258
        :param revprops: Optional dictionary of revision properties.
259
        :param revision_id: Optional revision id.
260
        :param lossy: Whether to discard data that can not be natively
261
            represented, when pushing to a foreign VCS
262
        """
0.200.1229 by Jelmer Vernooij
Provide CommitBuilder.any_changes.
263
        self.start_write_group()
0.200.1224 by Jelmer Vernooij
provide explicit GitRepository.get_commit_builder.
264
        return GitCommitBuilder(self, parents, config,
265
            timestamp, timezone, committer, revprops, revision_id,
266
            lossy)
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))
0.200.1233 by Jelmer Vernooij
Implement Repository.iter_files_bytes.
295
        for revid, files in per_revision.iteritems():
296
            (commit_id, mapping) = self.lookup_bzr_revision_id(revid)
297
            try:
298
                commit = self._git.object_store[commit_id]
299
            except KeyError:
300
                raise errors.RevisionNotPresent(revid, self)
301
            root_tree = commit.tree
302
            for fileid, identifier in files:
303
                path = mapping.parse_file_id(fileid)
304
                try:
305
                    obj = tree_lookup_path(
306
                        self._git.object_store.__getitem__, root_tree, path)
307
                    if isinstance(obj, tuple):
308
                        (mode, item_id) = obj
309
                        obj = self._git.object_store[item_id]
310
                except KeyError:
311
                    raise errors.RevisionNotPresent((fileid, revid), self)
312
                else:
313
                    if obj.type_name == "tree":
314
                        yield (identifier, [])
315
                    elif obj.type_name == "blob":
316
                        yield (identifier, obj.chunked)
317
                    else:
318
                        raise AssertionError("file text resolved to %r" % obj)
319
0.252.46 by Jelmer Vernooij
Generate refs/bzr/* if not set yet.
320
    def _iter_revision_ids(self):
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
321
        mapping = self.get_mapping()
0.252.21 by Jelmer Vernooij
Fix GitRepository.all_revision_ids() to find all revisions.
322
        for sha in self._git.object_store:
323
            o = self._git.object_store[sha]
324
            if not isinstance(o, Commit):
325
                continue
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
326
            rev, roundtrip_revid, verifiers = mapping.import_commit(o,
0.261.6 by Jelmer Vernooij
Use mapping.revision_id_foreign_to_bzr to find parents everywhere.
327
                mapping.revision_id_foreign_to_bzr)
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
328
            yield o.id, rev.revision_id, roundtrip_revid
0.252.46 by Jelmer Vernooij
Generate refs/bzr/* if not set yet.
329
330
    def all_revision_ids(self):
331
        ret = set([])
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
332
        for git_sha, revid, roundtrip_revid in self._iter_revision_ids():
333
            if roundtrip_revid:
334
                ret.add(roundtrip_revid)
0.200.1325 by Jelmer Vernooij
More test fixes.
335
            else:
336
                ret.add(revid)
0.200.74 by Jelmer Vernooij
Implement Repository.all_revision_ids().
337
        return ret
338
0.200.1328 by Jelmer Vernooij
More test fixes.
339
    def _get_parents(self, revid):
340
        if type(revid) != str:
341
            raise ValueError
342
        try:
0.200.1343 by Jelmer Vernooij
Update docstrings.
343
            (hexsha, mapping) = self.lookup_bzr_revision_id(revid)
0.200.1328 by Jelmer Vernooij
More test fixes.
344
        except errors.NoSuchRevision:
345
            return None
346
        try:
347
            commit = self._git[hexsha]
348
        except KeyError:
349
            return None
350
        return [
351
            self.lookup_foreign_revision_id(p, mapping)
352
            for p in commit.parents]
353
0.200.131 by Jelmer Vernooij
Fix all tests but two, use rich roots by default.
354
    def get_parent_map(self, revids):
355
        parent_map = {}
356
        for revision_id in revids:
0.200.1328 by Jelmer Vernooij
More test fixes.
357
            parents = self._get_parents(revision_id)
0.200.1329 by Jelmer Vernooij
Fix more tests.
358
            if revision_id == revision.NULL_REVISION:
359
                parent_map[revision_id] = ()
360
                continue
0.200.1328 by Jelmer Vernooij
More test fixes.
361
            if parents is None:
362
                continue
0.200.1324 by Jelmer Vernooij
More work on roundtripping support.
363
            if len(parents) == 0:
0.200.1094 by Jelmer Vernooij
Fix test_get_no_parents.
364
                parents = [revision.NULL_REVISION]
365
            parent_map[revision_id] = tuple(parents)
0.200.131 by Jelmer Vernooij
Fix all tests but two, use rich roots by default.
366
        return parent_map
367
0.200.1281 by Jelmer Vernooij
Provide Repository.get_known_graph_ancestry.
368
    def get_known_graph_ancestry(self, revision_ids):
369
        """Return the known graph for a set of revision ids and their ancestors.
370
        """
371
        pending = set(revision_ids)
372
        parent_map = {}
373
        while pending:
0.200.1328 by Jelmer Vernooij
More test fixes.
374
            this_parent_map = {}
375
            for revid in pending:
376
                if revid == revision.NULL_REVISION:
377
                    continue
378
                parents = self._get_parents(revid)
379
                if parents is not None:
380
                    this_parent_map[revid] = parents
0.200.1281 by Jelmer Vernooij
Provide Repository.get_known_graph_ancestry.
381
            parent_map.update(this_parent_map)
382
            pending = set()
383
            map(pending.update, this_parent_map.itervalues())
384
            pending = pending.difference(parent_map)
385
        return _mod_graph.KnownGraph(parent_map)
386
0.200.43 by David Allouche
Ultra-experimental support for "bzr pull". No test. No sanity.
387
    def get_signature_text(self, revision_id):
388
        raise errors.NoSuchRevision(self, revision_id)
389
0.200.1244 by Jelmer Vernooij
Implement GitRepository.check.
390
    def check(self, revision_ids=None, callback_refs=None, check_repo=True):
391
        result = GitCheck(self, check_repo=check_repo)
392
        result.check(callback_refs)
393
        return result
394
0.257.1 by Jelmer Vernooij
use transport repo objects even for local access.
395
    def pack(self, hint=None, clean_obsolete_packs=False):
396
        self._git.object_store.pack_loose_objects()
397
0.200.650 by Jelmer Vernooij
Use standard names for lookup functions.
398
    def lookup_foreign_revision_id(self, foreign_revid, mapping=None):
0.200.124 by Jelmer Vernooij
Add lookup_revision_id stub.
399
        """Lookup a revision id.
0.200.676 by Jelmer Vernooij
Avoid iterating over all keys in the tdb database.
400
0.200.124 by Jelmer Vernooij
Add lookup_revision_id stub.
401
        """
0.200.1033 by Jelmer Vernooij
Don't claim to support working trees for bare repositories.
402
        assert type(foreign_revid) is str
0.200.649 by Jelmer Vernooij
Make GitRevisions VF implementation behave as the interface expects.
403
        if mapping is None:
404
            mapping = self.get_mapping()
0.200.914 by Jelmer Vernooij
Fix tests.
405
        if foreign_revid == ZERO_SHA:
406
            return revision.NULL_REVISION
0.200.1268 by Jelmer Vernooij
Look in object store directly when something can't be a ref.
407
        commit = self._git.object_store[foreign_revid]
0.200.1080 by Jelmer Vernooij
Fix handling of annotated tags when cloning from local repo.
408
        while isinstance(commit, Tag):
409
            commit = self._git[commit.object[1]]
0.200.1403 by Jelmer Vernooij
Cope with tags pointing at tree objects when cloning local git repositories.
410
        if not isinstance(commit, Commit):
411
            raise NotCommitError(commit.id)
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
412
        rev, roundtrip_revid, verifiers = mapping.import_commit(commit,
0.261.6 by Jelmer Vernooij
Use mapping.revision_id_foreign_to_bzr to find parents everywhere.
413
            mapping.revision_id_foreign_to_bzr)
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
414
        # FIXME: check testament before doing this?
415
        if roundtrip_revid:
416
            return roundtrip_revid
417
        else:
418
            return rev.revision_id
0.200.124 by Jelmer Vernooij
Add lookup_revision_id stub.
419
0.200.60 by Jelmer Vernooij
Support signature functions.
420
    def has_signature_for_revision_id(self, revision_id):
0.200.1343 by Jelmer Vernooij
Update docstrings.
421
        """Check whether a GPG signature is present for this revision.
422
423
        This is never the case for Git repositories.
424
        """
0.200.60 by Jelmer Vernooij
Support signature functions.
425
        return False
426
0.200.913 by Jelmer Vernooij
Fix tests.
427
    def lookup_bzr_revision_id(self, bzr_revid, mapping=None):
0.200.1343 by Jelmer Vernooij
Update docstrings.
428
        """Lookup a bzr revision id in a Git repository.
429
430
        :param bzr_revid: Bazaar revision id
431
        :param mapping: Optional mapping to use
432
        :return: Tuple with git commit id, mapping that was used and supplement
433
            details
434
        """
0.200.105 by Jelmer Vernooij
Add common function for finding git commit by bzr revid.
435
        try:
0.200.1343 by Jelmer Vernooij
Update docstrings.
436
            (git_sha, mapping) = mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
0.200.105 by Jelmer Vernooij
Add common function for finding git commit by bzr revid.
437
        except errors.InvalidRevisionId:
0.200.913 by Jelmer Vernooij
Fix tests.
438
            if mapping is None:
439
                mapping = self.get_mapping()
0.252.6 by Jelmer Vernooij
Roundtripping support for revision ids works.
440
            try:
0.200.1307 by Jelmer Vernooij
Formatting fixes, specify path to a couple more functions.
441
                return (self._git.refs[mapping.revid_as_refname(bzr_revid)],
442
                        mapping)
0.252.6 by Jelmer Vernooij
Roundtripping support for revision ids works.
443
            except KeyError:
0.252.46 by Jelmer Vernooij
Generate refs/bzr/* if not set yet.
444
                # Update refs from Git commit objects
445
                # FIXME: Hitting this a lot will be very inefficient...
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
446
                for git_sha, revid, roundtrip_revid in self._iter_revision_ids():
447
                    if not roundtrip_revid:
448
                        continue
0.200.1022 by Jelmer Vernooij
Fix formatting.
449
                    refname = mapping.revid_as_refname(roundtrip_revid)
450
                    self._git.refs[refname] = git_sha
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
451
                    if roundtrip_revid == bzr_revid:
0.200.913 by Jelmer Vernooij
Fix tests.
452
                        return git_sha, mapping
453
                raise errors.NoSuchRevision(self, bzr_revid)
0.200.1343 by Jelmer Vernooij
Update docstrings.
454
        else:
455
            return (git_sha, mapping)
0.200.105 by Jelmer Vernooij
Add common function for finding git commit by bzr revid.
456
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
457
    def get_revision(self, revision_id):
0.200.1101 by Jelmer Vernooij
Raise InvalidRevisionId on invalid type being specified to Repository.get_revision.
458
        if not isinstance(revision_id, str):
459
            raise errors.InvalidRevisionId(revision_id, self)
0.200.650 by Jelmer Vernooij
Use standard names for lookup functions.
460
        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.
461
        try:
0.200.832 by Jelmer Vernooij
Update to newer version of Dulwich, saner branch names.
462
            commit = self._git[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.
463
        except KeyError:
464
            raise errors.NoSuchRevision(self, revision_id)
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
465
        revision, roundtrip_revid, verifiers = mapping.import_commit(
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
466
            commit, self.lookup_foreign_revision_id)
0.200.131 by Jelmer Vernooij
Fix all tests but two, use rich roots by default.
467
        assert revision is not None
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
468
        # FIXME: check verifiers ?
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
469
        if roundtrip_revid:
470
            revision.revision_id = roundtrip_revid
0.200.43 by David Allouche
Ultra-experimental support for "bzr pull". No test. No sanity.
471
        return revision
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
472
473
    def has_revision(self, revision_id):
0.200.1119 by Jelmer Vernooij
Refactor repository initialization.
474
        """See Repository.has_revision."""
0.200.1122 by Jelmer Vernooij
has_revision(null:) should always return True.
475
        if revision_id == revision.NULL_REVISION:
476
            return True
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
477
        try:
0.200.902 by Jelmer Vernooij
Fix Repository.has_revision{s,}.
478
            git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
0.200.130 by Jelmer Vernooij
Make most tree inspection tests succeed.
479
        except errors.NoSuchRevision:
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
480
            return False
0.200.902 by Jelmer Vernooij
Fix Repository.has_revision{s,}.
481
        return (git_commit_id in self._git)
482
483
    def has_revisions(self, revision_ids):
0.200.1119 by Jelmer Vernooij
Refactor repository initialization.
484
        """See Repository.has_revisions."""
0.200.913 by Jelmer Vernooij
Fix tests.
485
        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.
486
0.200.131 by Jelmer Vernooij
Fix all tests but two, use rich roots by default.
487
    def get_revisions(self, revids):
0.200.1119 by Jelmer Vernooij
Refactor repository initialization.
488
        """See Repository.get_revisions."""
0.200.134 by Jelmer Vernooij
Fix get_revisions().
489
        return [self.get_revision(r) for r in revids]
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
490
491
    def revision_trees(self, revids):
0.200.1119 by Jelmer Vernooij
Refactor repository initialization.
492
        """See Repository.revision_trees."""
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
493
        for revid in revids:
494
            yield self.revision_tree(revid)
495
496
    def revision_tree(self, revision_id):
0.200.1119 by Jelmer Vernooij
Refactor repository initialization.
497
        """See Repository.revision_tree."""
0.200.57 by Jelmer Vernooij
Fix more tests.
498
        revision_id = revision.ensure_null(revision_id)
499
        if revision_id == revision.NULL_REVISION:
500
            inv = inventory.Inventory(root_id=None)
501
            inv.revision_id = revision_id
0.200.1186 by Jelmer Vernooij
Cope with InventoryRevisionTree.
502
            return InventoryRevisionTree(self, inv, revision_id)
0.200.195 by Jelmer Vernooij
Return mapping in revision_id_bzr_to_foreign() as required by the interface.
503
        return GitRevisionTree(self, revision_id)
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
504
505
    def get_inventory(self, revision_id):
0.264.4 by Jelmer Vernooij
No longer implement Repository.get_inventory.
506
        raise NotImplementedError(self.get_inventory)
0.200.43 by David Allouche
Ultra-experimental support for "bzr pull". No test. No sanity.
507
0.200.108 by Jelmer Vernooij
Support bzr init --git.
508
    def set_make_working_trees(self, trees):
0.200.1321 by Jelmer Vernooij
More fixes for compatibility with bzr.dev testsuite.
509
        raise errors.UnsupportedOperation(self.set_make_working_trees, self)
0.200.1216 by Jelmer Vernooij
Add note about set_make_working_trees.
510
        # TODO: Set bare= in the configuration bug=777065
0.200.108 by Jelmer Vernooij
Support bzr init --git.
511
0.200.276 by Jelmer Vernooij
Improve formatting.
512
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
513
        progress=None):
0.200.146 by Jelmer Vernooij
Merge dulwich.
514
        return self._git.fetch_objects(determine_wants, graph_walker, progress)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
515
0.200.43 by David Allouche
Ultra-experimental support for "bzr pull". No test. No sanity.
516
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
517
class GitRepositoryFormat(repository.RepositoryFormat):
0.200.429 by Jelmer Vernooij
get remote dpush to a point where we now what to send.
518
    """Git repository format."""
0.203.1 by Aaron Bentley
Make checkouts work
519
0.200.1294 by Jelmer Vernooij
Mark as not supporting versioned directories.
520
    supports_versioned_directories = False
0.203.1 by Aaron Bentley
Make checkouts work
521
    supports_tree_reference = False
0.200.133 by Jelmer Vernooij
Unmark as deprecated.
522
    rich_root_data = True
0.200.1105 by Jelmer Vernooij
Don't claim to support leaving locks.
523
    supports_leaving_lock = False
0.200.1106 by Jelmer Vernooij
Claim to support fast deltas.
524
    fast_deltas = True
0.200.1123 by Jelmer Vernooij
Set more repository format flags.
525
    supports_funky_characters = True
0.200.1134 by Jelmer Vernooij
Set RepositoryFormat.supports_external_lookups.
526
    supports_external_lookups = False
0.200.1135 by Jelmer Vernooij
Set supports_full_versioned_files=False.
527
    supports_full_versioned_files = False
0.200.1162 by Jelmer Vernooij
Set RepositoryFormat.supports_revision_signatures.
528
    supports_revision_signatures = False
0.200.1383 by Jelmer Vernooij
Claim to not support nested repositories.
529
    supports_nesting_repositories = False
0.200.1166 by Jelmer Vernooij
Set GitRepositoryFormat.revision_graph_can_have_wrong_parents.
530
    revision_graph_can_have_wrong_parents = False
0.200.71 by Jelmer Vernooij
Implement GitRepositoryFormat.get_format_description.
531
0.200.1083 by Jelmer Vernooij
Register repository format.
532
    @property
533
    def _matchingbzrdir(self):
534
        from bzrlib.plugins.git.dir import LocalGitControlDirFormat
535
        return LocalGitControlDirFormat()
536
0.200.71 by Jelmer Vernooij
Implement GitRepositoryFormat.get_format_description.
537
    def get_format_description(self):
538
        return "Git Repository"
0.200.133 by Jelmer Vernooij
Unmark as deprecated.
539
0.200.1084 by Jelmer Vernooij
Support 'initializing' repositories in control directories.
540
    def initialize(self, controldir, shared=False, _internal=False):
541
        from bzrlib.plugins.git.dir import GitDir
542
        if not isinstance(controldir, GitDir):
543
            raise errors.UninitializableFormat(self)
544
        return controldir.open_repository()
0.200.133 by Jelmer Vernooij
Unmark as deprecated.
545
546
    def check_conversion_target(self, target_repo_format):
547
        return target_repo_format.rich_root_data
0.200.536 by Jelmer Vernooij
Implement network name.
548
0.200.658 by Jelmer Vernooij
Provide right infrastructure for foreign repository tests from bzrlib.
549
    def get_foreign_tests_repository_factory(self):
0.200.713 by Jelmer Vernooij
Improve formatting.
550
        from bzrlib.plugins.git.tests.test_repository import (
551
            ForeignTestsRepositoryFactory,
552
            )
0.200.658 by Jelmer Vernooij
Provide right infrastructure for foreign repository tests from bzrlib.
553
        return ForeignTestsRepositoryFactory()
554
0.200.536 by Jelmer Vernooij
Implement network name.
555
    def network_name(self):
556
        return "git"