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