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