/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.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
27
    )
0.200.1186 by Jelmer Vernooij
Cope with InventoryRevisionTree.
28
try:
29
    from bzrlib.revisiontree import InventoryRevisionTree
30
except ImportError: # bzr < 2.4
31
    from bzrlib.revisiontree import RevisionTree as InventoryRevisionTree
0.200.115 by Jelmer Vernooij
Pass mapping object.
32
from bzrlib.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.387 by Jelmer Vernooij
Initial work on supporting commit in git trees.
36
from bzrlib.plugins.git.commit import (
37
    GitCommitBuilder,
38
    )
0.200.1403 by Jelmer Vernooij
Cope with tags pointing at tree objects when cloning local git repositories.
39
from bzrlib.plugins.git.errors import (
40
    NotCommitError,
41
    )
0.200.1283 by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision().
42
from bzrlib.plugins.git.filegraph import (
43
    GitFileLastChangeScanner,
44
    GitFileParentProvider,
45
    )
0.200.256 by Jelmer Vernooij
Add tests for import_revision_gist.
46
from bzrlib.plugins.git.mapping import (
47
    default_mapping,
0.200.1263 by Jelmer Vernooij
Fix foreign_vcs_git.
48
    foreign_vcs_git,
0.200.256 by Jelmer Vernooij
Add tests for import_revision_gist.
49
    mapping_registry,
50
    )
0.200.617 by Jelmer Vernooij
Add custom InterTree for use between git revision trees.
51
from bzrlib.plugins.git.tree import (
52
    GitRevisionTree,
53
    )
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
54
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.1080 by Jelmer Vernooij
Fix handling of annotated tags when cloning from local repo.
58
    Tag,
0.200.1153 by Jelmer Vernooij
Import ZERO_SHA from dulwich.objects.
59
    ZERO_SHA,
0.252.21 by Jelmer Vernooij
Fix GitRepository.all_revision_ids() to find all revisions.
60
    )
0.200.1233 by Jelmer Vernooij
Implement Repository.iter_files_bytes.
61
from dulwich.object_store import (
62
    tree_lookup_path,
63
    )
0.252.21 by Jelmer Vernooij
Fix GitRepository.all_revision_ids() to find all revisions.
64
65
0.200.1246 by Jelmer Vernooij
Provide GitRepository.reconcile.
66
class RepoReconciler(object):
67
    """Reconciler that reconciles a repository.
68
69
    """
70
71
    def __init__(self, repo, other=None, thorough=False):
72
        """Construct a RepoReconciler.
73
74
        :param thorough: perform a thorough check which may take longer but
75
                         will correct non-data loss issues such as incorrect
76
                         cached data.
77
        """
78
        self.repo = repo
79
80
    def reconcile(self):
81
        """Perform reconciliation.
82
83
        After reconciliation the following attributes document found issues:
84
        inconsistent_parents: The number of revisions in the repository whose
85
                              ancestry was being reported incorrectly.
86
        garbage_inventories: The number of inventory objects without revisions
87
                             that were garbage collected.
88
        """
89
90
0.200.1244 by Jelmer Vernooij
Implement GitRepository.check.
91
class GitCheck(check.Check):
92
93
    def __init__(self, repository, check_repo=True):
94
        self.repository = repository
95
        self.checked_rev_cnt = 0
96
97
    def check(self, callback_refs=None, check_repo=True):
98
        if callback_refs is None:
99
            callback_refs = {}
100
        self.repository.lock_read()
101
        self.repository.unlock()
102
103
    def report_results(self, verbose):
104
        pass
105
106
0.200.115 by Jelmer Vernooij
Pass mapping object.
107
class GitRepository(ForeignRepository):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
108
    """An adapter to git repositories for bzr."""
109
0.200.41 by David Allouche
Define _serializer = None in GitRepository.
110
    _serializer = None
0.200.1263 by Jelmer Vernooij
Fix foreign_vcs_git.
111
    vcs = foreign_vcs_git
0.200.1086 by Jelmer Vernooij
Provide chk_bytes attribute.
112
    chk_bytes = None
0.200.41 by David Allouche
Define _serializer = None in GitRepository.
113
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
114
    def __init__(self, gitdir, lockfiles):
0.200.1307 by Jelmer Vernooij
Formatting fixes, specify path to a couple more functions.
115
        super(GitRepository, self).__init__(GitRepositoryFormat(),
116
            gitdir, lockfiles)
0.200.1389 by Jelmer Vernooij
Some more tag fixes.
117
        self._transport = lockfiles._transport
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
118
        from bzrlib.plugins.git import fetch, push
0.200.676 by Jelmer Vernooij
Avoid iterating over all keys in the tdb database.
119
        for optimiser in [fetch.InterRemoteGitNonGitRepository,
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
120
                          fetch.InterLocalGitNonGitRepository,
0.200.456 by Jelmer Vernooij
Fix git -> git fetching.
121
                          fetch.InterGitGitRepository,
0.200.425 by Jelmer Vernooij
Split out push to remote git repositories.
122
                          push.InterToLocalGitRepository,
123
                          push.InterToRemoteGitRepository]:
0.200.276 by Jelmer Vernooij
Improve formatting.
124
            repository.InterRepository.register_optimiser(optimiser)
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
125
0.200.1231 by Jelmer Vernooij
Implement GitRepository.add_fallback_repository.
126
    def add_fallback_repository(self, basis_url):
0.200.1307 by Jelmer Vernooij
Formatting fixes, specify path to a couple more functions.
127
        raise errors.UnstackableRepositoryFormat(self._format,
128
            self.control_transport.base)
0.200.1231 by Jelmer Vernooij
Implement GitRepository.add_fallback_repository.
129
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
130
    def is_shared(self):
0.200.886 by Jelmer Vernooij
Git repositories are not shared.
131
        return False
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
132
0.200.1246 by Jelmer Vernooij
Provide GitRepository.reconcile.
133
    def reconcile(self, other=None, thorough=False):
134
        """Reconcile this repository."""
135
        reconciler = RepoReconciler(self, thorough=thorough)
136
        reconciler.reconcile()
137
        return reconciler
138
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
139
    def supports_rich_root(self):
140
        return True
141
0.200.1111 by Jelmer Vernooij
Drop support for Bazaar < 2.3.
142
    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.
143
        # This class isn't deprecated
144
        pass
145
146
    def get_mapping(self):
147
        return default_mapping
148
0.200.147 by Jelmer Vernooij
Merge new dulwich; fetching objects from local repository works now; they aren't converted yet though.
149
    def make_working_trees(self):
0.200.1033 by Jelmer Vernooij
Don't claim to support working trees for bare repositories.
150
        return not self._git.bare
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
151
0.200.557 by Jelmer Vernooij
Implement GitRepository.revision_graph_can_have_wrong_parents().
152
    def revision_graph_can_have_wrong_parents(self):
153
        return False
154
0.200.425 by Jelmer Vernooij
Split out push to remote git repositories.
155
    def dfetch(self, source, stop_revision):
156
        interrepo = repository.InterRepository.get(source, self)
157
        return interrepo.dfetch(stop_revision)
158
0.200.1158 by Jelmer Vernooij
Implement stub Repositor.add_signature_text.
159
    def add_signature_text(self, revid, signature):
160
        raise errors.UnsupportedOperation(self.add_signature_text, self)
161
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
162
163
class LocalGitRepository(GitRepository):
0.200.276 by Jelmer Vernooij
Improve formatting.
164
    """Git repository on the file system."""
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
165
166
    def __init__(self, gitdir, lockfiles):
167
        GitRepository.__init__(self, gitdir, lockfiles)
0.200.61 by Jelmer Vernooij
Fix tests.
168
        self.base = gitdir.root_transport.base
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
169
        self._git = gitdir._git
0.200.1283 by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision().
170
        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.
171
0.200.1224 by Jelmer Vernooij
provide explicit GitRepository.get_commit_builder.
172
    def get_commit_builder(self, branch, parents, config, timestamp=None,
173
                           timezone=None, committer=None, revprops=None,
174
                           revision_id=None, lossy=False):
175
        """Obtain a CommitBuilder for this repository.
176
177
        :param branch: Branch to commit to.
178
        :param parents: Revision ids of the parents of the new revision.
179
        :param config: Configuration to use.
180
        :param timestamp: Optional timestamp recorded for commit.
181
        :param timezone: Optional timezone for timestamp.
182
        :param committer: Optional committer to set for commit.
183
        :param revprops: Optional dictionary of revision properties.
184
        :param revision_id: Optional revision id.
185
        :param lossy: Whether to discard data that can not be natively
186
            represented, when pushing to a foreign VCS
187
        """
0.200.1229 by Jelmer Vernooij
Provide CommitBuilder.any_changes.
188
        self.start_write_group()
0.200.1224 by Jelmer Vernooij
provide explicit GitRepository.get_commit_builder.
189
        return GitCommitBuilder(self, parents, config,
190
            timestamp, timezone, committer, revprops, revision_id,
191
            lossy)
192
0.200.1283 by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision().
193
    def get_file_graph(self):
0.200.1307 by Jelmer Vernooij
Formatting fixes, specify path to a couple more functions.
194
        return _mod_graph.Graph(GitFileParentProvider(
195
            self._file_change_scanner))
0.200.1283 by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision().
196
0.200.1233 by Jelmer Vernooij
Implement Repository.iter_files_bytes.
197
    def iter_files_bytes(self, desired_files):
198
        """Iterate through file versions.
199
200
        Files will not necessarily be returned in the order they occur in
201
        desired_files.  No specific order is guaranteed.
202
203
        Yields pairs of identifier, bytes_iterator.  identifier is an opaque
204
        value supplied by the caller as part of desired_files.  It should
205
        uniquely identify the file version in the caller's context.  (Examples:
206
        an index number or a TreeTransform trans_id.)
207
208
        bytes_iterator is an iterable of bytestrings for the file.  The
209
        kind of iterable and length of the bytestrings are unspecified, but for
210
        this implementation, it is a list of bytes produced by
211
        VersionedFile.get_record_stream().
212
213
        :param desired_files: a list of (file_id, revision_id, identifier)
214
            triples
215
        """
216
        per_revision = {}
217
        for (file_id, revision_id, identifier) in desired_files:
0.200.1307 by Jelmer Vernooij
Formatting fixes, specify path to a couple more functions.
218
            per_revision.setdefault(revision_id, []).append(
219
                (file_id, identifier))
0.200.1233 by Jelmer Vernooij
Implement Repository.iter_files_bytes.
220
        for revid, files in per_revision.iteritems():
221
            (commit_id, mapping) = self.lookup_bzr_revision_id(revid)
222
            try:
223
                commit = self._git.object_store[commit_id]
224
            except KeyError:
225
                raise errors.RevisionNotPresent(revid, self)
226
            root_tree = commit.tree
227
            for fileid, identifier in files:
228
                path = mapping.parse_file_id(fileid)
229
                try:
230
                    obj = tree_lookup_path(
231
                        self._git.object_store.__getitem__, root_tree, path)
232
                    if isinstance(obj, tuple):
233
                        (mode, item_id) = obj
234
                        obj = self._git.object_store[item_id]
235
                except KeyError:
236
                    raise errors.RevisionNotPresent((fileid, revid), self)
237
                else:
238
                    if obj.type_name == "tree":
239
                        yield (identifier, [])
240
                    elif obj.type_name == "blob":
241
                        yield (identifier, obj.chunked)
242
                    else:
243
                        raise AssertionError("file text resolved to %r" % obj)
244
0.252.46 by Jelmer Vernooij
Generate refs/bzr/* if not set yet.
245
    def _iter_revision_ids(self):
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
246
        mapping = self.get_mapping()
0.252.21 by Jelmer Vernooij
Fix GitRepository.all_revision_ids() to find all revisions.
247
        for sha in self._git.object_store:
248
            o = self._git.object_store[sha]
249
            if not isinstance(o, Commit):
250
                continue
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
251
            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.
252
                mapping.revision_id_foreign_to_bzr)
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
253
            yield o.id, rev.revision_id, roundtrip_revid
0.252.46 by Jelmer Vernooij
Generate refs/bzr/* if not set yet.
254
255
    def all_revision_ids(self):
256
        ret = set([])
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
257
        for git_sha, revid, roundtrip_revid in self._iter_revision_ids():
258
            if roundtrip_revid:
259
                ret.add(roundtrip_revid)
0.200.1325 by Jelmer Vernooij
More test fixes.
260
            else:
261
                ret.add(revid)
0.200.74 by Jelmer Vernooij
Implement Repository.all_revision_ids().
262
        return ret
263
0.200.1328 by Jelmer Vernooij
More test fixes.
264
    def _get_parents(self, revid):
265
        if type(revid) != str:
266
            raise ValueError
267
        try:
0.200.1343 by Jelmer Vernooij
Update docstrings.
268
            (hexsha, mapping) = self.lookup_bzr_revision_id(revid)
0.200.1328 by Jelmer Vernooij
More test fixes.
269
        except errors.NoSuchRevision:
270
            return None
271
        try:
272
            commit = self._git[hexsha]
273
        except KeyError:
274
            return None
275
        return [
276
            self.lookup_foreign_revision_id(p, mapping)
277
            for p in commit.parents]
278
0.200.131 by Jelmer Vernooij
Fix all tests but two, use rich roots by default.
279
    def get_parent_map(self, revids):
280
        parent_map = {}
281
        for revision_id in revids:
0.200.1328 by Jelmer Vernooij
More test fixes.
282
            parents = self._get_parents(revision_id)
0.200.1329 by Jelmer Vernooij
Fix more tests.
283
            if revision_id == revision.NULL_REVISION:
284
                parent_map[revision_id] = ()
285
                continue
0.200.1328 by Jelmer Vernooij
More test fixes.
286
            if parents is None:
287
                continue
0.200.1324 by Jelmer Vernooij
More work on roundtripping support.
288
            if len(parents) == 0:
0.200.1094 by Jelmer Vernooij
Fix test_get_no_parents.
289
                parents = [revision.NULL_REVISION]
290
            parent_map[revision_id] = tuple(parents)
0.200.131 by Jelmer Vernooij
Fix all tests but two, use rich roots by default.
291
        return parent_map
292
0.200.1281 by Jelmer Vernooij
Provide Repository.get_known_graph_ancestry.
293
    def get_known_graph_ancestry(self, revision_ids):
294
        """Return the known graph for a set of revision ids and their ancestors.
295
        """
296
        pending = set(revision_ids)
297
        parent_map = {}
298
        while pending:
0.200.1328 by Jelmer Vernooij
More test fixes.
299
            this_parent_map = {}
300
            for revid in pending:
301
                if revid == revision.NULL_REVISION:
302
                    continue
303
                parents = self._get_parents(revid)
304
                if parents is not None:
305
                    this_parent_map[revid] = parents
0.200.1281 by Jelmer Vernooij
Provide Repository.get_known_graph_ancestry.
306
            parent_map.update(this_parent_map)
307
            pending = set()
308
            map(pending.update, this_parent_map.itervalues())
309
            pending = pending.difference(parent_map)
310
        return _mod_graph.KnownGraph(parent_map)
311
0.200.43 by David Allouche
Ultra-experimental support for "bzr pull". No test. No sanity.
312
    def get_signature_text(self, revision_id):
313
        raise errors.NoSuchRevision(self, revision_id)
314
0.200.1244 by Jelmer Vernooij
Implement GitRepository.check.
315
    def check(self, revision_ids=None, callback_refs=None, check_repo=True):
316
        result = GitCheck(self, check_repo=check_repo)
317
        result.check(callback_refs)
318
        return result
319
0.257.1 by Jelmer Vernooij
use transport repo objects even for local access.
320
    def pack(self, hint=None, clean_obsolete_packs=False):
321
        self._git.object_store.pack_loose_objects()
322
0.200.650 by Jelmer Vernooij
Use standard names for lookup functions.
323
    def lookup_foreign_revision_id(self, foreign_revid, mapping=None):
0.200.124 by Jelmer Vernooij
Add lookup_revision_id stub.
324
        """Lookup a revision id.
0.200.676 by Jelmer Vernooij
Avoid iterating over all keys in the tdb database.
325
0.200.124 by Jelmer Vernooij
Add lookup_revision_id stub.
326
        """
0.200.1033 by Jelmer Vernooij
Don't claim to support working trees for bare repositories.
327
        assert type(foreign_revid) is str
0.200.649 by Jelmer Vernooij
Make GitRevisions VF implementation behave as the interface expects.
328
        if mapping is None:
329
            mapping = self.get_mapping()
0.200.914 by Jelmer Vernooij
Fix tests.
330
        if foreign_revid == ZERO_SHA:
331
            return revision.NULL_REVISION
0.200.1268 by Jelmer Vernooij
Look in object store directly when something can't be a ref.
332
        commit = self._git.object_store[foreign_revid]
0.200.1080 by Jelmer Vernooij
Fix handling of annotated tags when cloning from local repo.
333
        while isinstance(commit, Tag):
334
            commit = self._git[commit.object[1]]
0.200.1403 by Jelmer Vernooij
Cope with tags pointing at tree objects when cloning local git repositories.
335
        if not isinstance(commit, Commit):
336
            raise NotCommitError(commit.id)
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
337
        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.
338
            mapping.revision_id_foreign_to_bzr)
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
339
        # FIXME: check testament before doing this?
340
        if roundtrip_revid:
341
            return roundtrip_revid
342
        else:
343
            return rev.revision_id
0.200.124 by Jelmer Vernooij
Add lookup_revision_id stub.
344
0.200.60 by Jelmer Vernooij
Support signature functions.
345
    def has_signature_for_revision_id(self, revision_id):
0.200.1343 by Jelmer Vernooij
Update docstrings.
346
        """Check whether a GPG signature is present for this revision.
347
348
        This is never the case for Git repositories.
349
        """
0.200.60 by Jelmer Vernooij
Support signature functions.
350
        return False
351
0.200.913 by Jelmer Vernooij
Fix tests.
352
    def lookup_bzr_revision_id(self, bzr_revid, mapping=None):
0.200.1343 by Jelmer Vernooij
Update docstrings.
353
        """Lookup a bzr revision id in a Git repository.
354
355
        :param bzr_revid: Bazaar revision id
356
        :param mapping: Optional mapping to use
357
        :return: Tuple with git commit id, mapping that was used and supplement
358
            details
359
        """
0.200.105 by Jelmer Vernooij
Add common function for finding git commit by bzr revid.
360
        try:
0.200.1343 by Jelmer Vernooij
Update docstrings.
361
            (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.
362
        except errors.InvalidRevisionId:
0.200.913 by Jelmer Vernooij
Fix tests.
363
            if mapping is None:
364
                mapping = self.get_mapping()
0.252.6 by Jelmer Vernooij
Roundtripping support for revision ids works.
365
            try:
0.200.1307 by Jelmer Vernooij
Formatting fixes, specify path to a couple more functions.
366
                return (self._git.refs[mapping.revid_as_refname(bzr_revid)],
367
                        mapping)
0.252.6 by Jelmer Vernooij
Roundtripping support for revision ids works.
368
            except KeyError:
0.252.46 by Jelmer Vernooij
Generate refs/bzr/* if not set yet.
369
                # Update refs from Git commit objects
370
                # FIXME: Hitting this a lot will be very inefficient...
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
371
                for git_sha, revid, roundtrip_revid in self._iter_revision_ids():
372
                    if not roundtrip_revid:
373
                        continue
0.200.1022 by Jelmer Vernooij
Fix formatting.
374
                    refname = mapping.revid_as_refname(roundtrip_revid)
375
                    self._git.refs[refname] = git_sha
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
376
                    if roundtrip_revid == bzr_revid:
0.200.913 by Jelmer Vernooij
Fix tests.
377
                        return git_sha, mapping
378
                raise errors.NoSuchRevision(self, bzr_revid)
0.200.1343 by Jelmer Vernooij
Update docstrings.
379
        else:
380
            return (git_sha, mapping)
0.200.105 by Jelmer Vernooij
Add common function for finding git commit by bzr revid.
381
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
382
    def get_revision(self, revision_id):
0.200.1101 by Jelmer Vernooij
Raise InvalidRevisionId on invalid type being specified to Repository.get_revision.
383
        if not isinstance(revision_id, str):
384
            raise errors.InvalidRevisionId(revision_id, self)
0.200.650 by Jelmer Vernooij
Use standard names for lookup functions.
385
        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.
386
        try:
0.200.832 by Jelmer Vernooij
Update to newer version of Dulwich, saner branch names.
387
            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.
388
        except KeyError:
389
            raise errors.NoSuchRevision(self, revision_id)
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
390
        revision, roundtrip_revid, verifiers = mapping.import_commit(
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
391
            commit, self.lookup_foreign_revision_id)
0.200.131 by Jelmer Vernooij
Fix all tests but two, use rich roots by default.
392
        assert revision is not None
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
393
        # FIXME: check verifiers ?
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
394
        if roundtrip_revid:
395
            revision.revision_id = roundtrip_revid
0.200.43 by David Allouche
Ultra-experimental support for "bzr pull". No test. No sanity.
396
        return revision
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
397
398
    def has_revision(self, revision_id):
0.200.1119 by Jelmer Vernooij
Refactor repository initialization.
399
        """See Repository.has_revision."""
0.200.1122 by Jelmer Vernooij
has_revision(null:) should always return True.
400
        if revision_id == revision.NULL_REVISION:
401
            return True
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
402
        try:
0.200.902 by Jelmer Vernooij
Fix Repository.has_revision{s,}.
403
            git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
0.200.130 by Jelmer Vernooij
Make most tree inspection tests succeed.
404
        except errors.NoSuchRevision:
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
405
            return False
0.200.902 by Jelmer Vernooij
Fix Repository.has_revision{s,}.
406
        return (git_commit_id in self._git)
407
408
    def has_revisions(self, revision_ids):
0.200.1119 by Jelmer Vernooij
Refactor repository initialization.
409
        """See Repository.has_revisions."""
0.200.913 by Jelmer Vernooij
Fix tests.
410
        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.
411
0.200.131 by Jelmer Vernooij
Fix all tests but two, use rich roots by default.
412
    def get_revisions(self, revids):
0.200.1119 by Jelmer Vernooij
Refactor repository initialization.
413
        """See Repository.get_revisions."""
0.200.134 by Jelmer Vernooij
Fix get_revisions().
414
        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.
415
416
    def revision_trees(self, revids):
0.200.1119 by Jelmer Vernooij
Refactor repository initialization.
417
        """See Repository.revision_trees."""
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
418
        for revid in revids:
419
            yield self.revision_tree(revid)
420
421
    def revision_tree(self, revision_id):
0.200.1119 by Jelmer Vernooij
Refactor repository initialization.
422
        """See Repository.revision_tree."""
0.200.57 by Jelmer Vernooij
Fix more tests.
423
        revision_id = revision.ensure_null(revision_id)
424
        if revision_id == revision.NULL_REVISION:
425
            inv = inventory.Inventory(root_id=None)
426
            inv.revision_id = revision_id
0.200.1186 by Jelmer Vernooij
Cope with InventoryRevisionTree.
427
            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.
428
        return GitRevisionTree(self, revision_id)
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
429
430
    def get_inventory(self, revision_id):
0.264.4 by Jelmer Vernooij
No longer implement Repository.get_inventory.
431
        raise NotImplementedError(self.get_inventory)
0.200.43 by David Allouche
Ultra-experimental support for "bzr pull". No test. No sanity.
432
0.200.108 by Jelmer Vernooij
Support bzr init --git.
433
    def set_make_working_trees(self, trees):
0.200.1321 by Jelmer Vernooij
More fixes for compatibility with bzr.dev testsuite.
434
        raise errors.UnsupportedOperation(self.set_make_working_trees, self)
0.200.1216 by Jelmer Vernooij
Add note about set_make_working_trees.
435
        # TODO: Set bare= in the configuration bug=777065
0.200.108 by Jelmer Vernooij
Support bzr init --git.
436
0.200.276 by Jelmer Vernooij
Improve formatting.
437
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
438
        progress=None):
0.200.146 by Jelmer Vernooij
Merge dulwich.
439
        return self._git.fetch_objects(determine_wants, graph_walker, progress)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
440
0.200.43 by David Allouche
Ultra-experimental support for "bzr pull". No test. No sanity.
441
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
442
class GitRepositoryFormat(repository.RepositoryFormat):
0.200.429 by Jelmer Vernooij
get remote dpush to a point where we now what to send.
443
    """Git repository format."""
0.203.1 by Aaron Bentley
Make checkouts work
444
0.200.1294 by Jelmer Vernooij
Mark as not supporting versioned directories.
445
    supports_versioned_directories = False
0.203.1 by Aaron Bentley
Make checkouts work
446
    supports_tree_reference = False
0.200.133 by Jelmer Vernooij
Unmark as deprecated.
447
    rich_root_data = True
0.200.1105 by Jelmer Vernooij
Don't claim to support leaving locks.
448
    supports_leaving_lock = False
0.200.1106 by Jelmer Vernooij
Claim to support fast deltas.
449
    fast_deltas = True
0.200.1123 by Jelmer Vernooij
Set more repository format flags.
450
    supports_funky_characters = True
0.200.1134 by Jelmer Vernooij
Set RepositoryFormat.supports_external_lookups.
451
    supports_external_lookups = False
0.200.1135 by Jelmer Vernooij
Set supports_full_versioned_files=False.
452
    supports_full_versioned_files = False
0.200.1162 by Jelmer Vernooij
Set RepositoryFormat.supports_revision_signatures.
453
    supports_revision_signatures = False
0.200.1383 by Jelmer Vernooij
Claim to not support nested repositories.
454
    supports_nesting_repositories = False
0.200.1166 by Jelmer Vernooij
Set GitRepositoryFormat.revision_graph_can_have_wrong_parents.
455
    revision_graph_can_have_wrong_parents = False
0.200.71 by Jelmer Vernooij
Implement GitRepositoryFormat.get_format_description.
456
0.200.1083 by Jelmer Vernooij
Register repository format.
457
    @property
458
    def _matchingbzrdir(self):
459
        from bzrlib.plugins.git.dir import LocalGitControlDirFormat
460
        return LocalGitControlDirFormat()
461
0.200.71 by Jelmer Vernooij
Implement GitRepositoryFormat.get_format_description.
462
    def get_format_description(self):
463
        return "Git Repository"
0.200.133 by Jelmer Vernooij
Unmark as deprecated.
464
0.200.1084 by Jelmer Vernooij
Support 'initializing' repositories in control directories.
465
    def initialize(self, controldir, shared=False, _internal=False):
466
        from bzrlib.plugins.git.dir import GitDir
467
        if not isinstance(controldir, GitDir):
468
            raise errors.UninitializableFormat(self)
469
        return controldir.open_repository()
0.200.133 by Jelmer Vernooij
Unmark as deprecated.
470
471
    def check_conversion_target(self, target_repo_format):
472
        return target_repo_format.rich_root_data
0.200.536 by Jelmer Vernooij
Implement network name.
473
0.200.658 by Jelmer Vernooij
Provide right infrastructure for foreign repository tests from bzrlib.
474
    def get_foreign_tests_repository_factory(self):
0.200.713 by Jelmer Vernooij
Improve formatting.
475
        from bzrlib.plugins.git.tests.test_repository import (
476
            ForeignTestsRepositoryFactory,
477
            )
0.200.658 by Jelmer Vernooij
Provide right infrastructure for foreign repository tests from bzrlib.
478
        return ForeignTestsRepositoryFactory()
479
0.200.536 by Jelmer Vernooij
Implement network name.
480
    def network_name(self):
481
        return "git"