/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.1670 by Jelmer Vernooij
Fix compatibility with newer versions of bzr.
26
    lock,
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
27
    repository,
0.285.5 by Jelmer Vernooij
Fix import.
28
    revision as _mod_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.1646 by Jelmer Vernooij
Rename bzrlib to breezy.
31
    version_info as breezy_version,
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
32
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
33
from ...decorators import only_raises
34
from ...foreign import (
0.200.292 by Jelmer Vernooij
Fix formatting.
35
    ForeignRepository,
36
    )
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
37
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
38
from .commit import (
0.200.387 by Jelmer Vernooij
Initial work on supporting commit in git trees.
39
    GitCommitBuilder,
40
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
41
from .filegraph import (
0.200.1283 by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision().
42
    GitFileLastChangeScanner,
43
    GitFileParentProvider,
44
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
45
from .mapping import (
0.200.256 by Jelmer Vernooij
Add tests for import_revision_gist.
46
    default_mapping,
0.200.1263 by Jelmer Vernooij
Fix foreign_vcs_git.
47
    foreign_vcs_git,
0.200.256 by Jelmer Vernooij
Add tests for import_revision_gist.
48
    mapping_registry,
49
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
50
from .tree import (
0.200.617 by Jelmer Vernooij
Add custom InterTree for use between git revision trees.
51
    GitRevisionTree,
52
    )
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
53
54
0.200.1636 by Jelmer Vernooij
Some formatting fixes.
55
from dulwich.errors import (
56
    NotCommitError,
57
    )
0.252.21 by Jelmer Vernooij
Fix GitRepository.all_revision_ids() to find all revisions.
58
from dulwich.objects import (
59
    Commit,
0.200.1153 by Jelmer Vernooij
Import ZERO_SHA from dulwich.objects.
60
    ZERO_SHA,
0.252.21 by Jelmer Vernooij
Fix GitRepository.all_revision_ids() to find all revisions.
61
    )
0.200.1233 by Jelmer Vernooij
Implement Repository.iter_files_bytes.
62
from dulwich.object_store import (
63
    tree_lookup_path,
64
    )
0.252.21 by Jelmer Vernooij
Fix GitRepository.all_revision_ids() to find all revisions.
65
66
0.200.1246 by Jelmer Vernooij
Provide GitRepository.reconcile.
67
class RepoReconciler(object):
68
    """Reconciler that reconciles a repository.
69
70
    """
71
72
    def __init__(self, repo, other=None, thorough=False):
73
        """Construct a RepoReconciler.
74
75
        :param thorough: perform a thorough check which may take longer but
76
                         will correct non-data loss issues such as incorrect
77
                         cached data.
78
        """
79
        self.repo = repo
80
81
    def reconcile(self):
82
        """Perform reconciliation.
83
84
        After reconciliation the following attributes document found issues:
85
        inconsistent_parents: The number of revisions in the repository whose
86
                              ancestry was being reported incorrectly.
87
        garbage_inventories: The number of inventory objects without revisions
88
                             that were garbage collected.
89
        """
90
91
0.200.1244 by Jelmer Vernooij
Implement GitRepository.check.
92
class GitCheck(check.Check):
93
94
    def __init__(self, repository, check_repo=True):
95
        self.repository = repository
96
        self.checked_rev_cnt = 0
97
98
    def check(self, callback_refs=None, check_repo=True):
99
        if callback_refs is None:
100
            callback_refs = {}
0.200.1680 by Jelmer Vernooij
Fix repo locks.
101
        with self.repository.lock_read():
0.200.1670 by Jelmer Vernooij
Fix compatibility with newer versions of bzr.
102
            # TODO(jelmer): Check some things
103
            pass
0.200.1244 by Jelmer Vernooij
Implement GitRepository.check.
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
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
115
    from . import fetch, push
0.200.1447 by Jelmer Vernooij
Load optimisers at most once.
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
0.200.1680 by Jelmer Vernooij
Fix repo locks.
159
        return repository.RepositoryWriteLockResult(self.unlock, None)
0.200.1411 by Jelmer Vernooij
Fix control files.
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
0.200.1670 by Jelmer Vernooij
Fix compatibility with newer versions of bzr.
177
        return lock.LogicalLockResult(self.unlock)
0.200.1411 by Jelmer Vernooij
Fix control files.
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
232
class LocalGitRepository(GitRepository):
0.200.276 by Jelmer Vernooij
Improve formatting.
233
    """Git repository on the file system."""
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
234
0.200.1411 by Jelmer Vernooij
Fix control files.
235
    def __init__(self, gitdir):
236
        GitRepository.__init__(self, gitdir)
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
237
        self._git = gitdir._git
0.200.1283 by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision().
238
        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.
239
0.200.1224 by Jelmer Vernooij
provide explicit GitRepository.get_commit_builder.
240
    def get_commit_builder(self, branch, parents, config, timestamp=None,
241
                           timezone=None, committer=None, revprops=None,
242
                           revision_id=None, lossy=False):
243
        """Obtain a CommitBuilder for this repository.
244
245
        :param branch: Branch to commit to.
246
        :param parents: Revision ids of the parents of the new revision.
247
        :param config: Configuration to use.
248
        :param timestamp: Optional timestamp recorded for commit.
249
        :param timezone: Optional timezone for timestamp.
250
        :param committer: Optional committer to set for commit.
251
        :param revprops: Optional dictionary of revision properties.
252
        :param revision_id: Optional revision id.
253
        :param lossy: Whether to discard data that can not be natively
254
            represented, when pushing to a foreign VCS
255
        """
0.200.1229 by Jelmer Vernooij
Provide CommitBuilder.any_changes.
256
        self.start_write_group()
0.200.1224 by Jelmer Vernooij
provide explicit GitRepository.get_commit_builder.
257
        return GitCommitBuilder(self, parents, config,
258
            timestamp, timezone, committer, revprops, revision_id,
259
            lossy)
260
0.200.1283 by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision().
261
    def get_file_graph(self):
0.200.1307 by Jelmer Vernooij
Formatting fixes, specify path to a couple more functions.
262
        return _mod_graph.Graph(GitFileParentProvider(
263
            self._file_change_scanner))
0.200.1283 by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision().
264
0.200.1233 by Jelmer Vernooij
Implement Repository.iter_files_bytes.
265
    def iter_files_bytes(self, desired_files):
266
        """Iterate through file versions.
267
268
        Files will not necessarily be returned in the order they occur in
269
        desired_files.  No specific order is guaranteed.
270
271
        Yields pairs of identifier, bytes_iterator.  identifier is an opaque
272
        value supplied by the caller as part of desired_files.  It should
273
        uniquely identify the file version in the caller's context.  (Examples:
274
        an index number or a TreeTransform trans_id.)
275
276
        bytes_iterator is an iterable of bytestrings for the file.  The
277
        kind of iterable and length of the bytestrings are unspecified, but for
278
        this implementation, it is a list of bytes produced by
279
        VersionedFile.get_record_stream().
280
281
        :param desired_files: a list of (file_id, revision_id, identifier)
282
            triples
283
        """
284
        per_revision = {}
285
        for (file_id, revision_id, identifier) in desired_files:
0.200.1307 by Jelmer Vernooij
Formatting fixes, specify path to a couple more functions.
286
            per_revision.setdefault(revision_id, []).append(
287
                (file_id, identifier))
0.200.1233 by Jelmer Vernooij
Implement Repository.iter_files_bytes.
288
        for revid, files in per_revision.iteritems():
0.200.1745 by Jelmer Vernooij
Fix iter_files_bytes.
289
            try:
290
                (commit_id, mapping) = self.lookup_bzr_revision_id(revid)
291
            except errors.NoSuchRevision:
292
                raise errors.RevisionNotPresent(revid, self)
0.200.1233 by Jelmer Vernooij
Implement Repository.iter_files_bytes.
293
            try:
294
                commit = self._git.object_store[commit_id]
295
            except KeyError:
296
                raise errors.RevisionNotPresent(revid, self)
297
            root_tree = commit.tree
298
            for fileid, identifier in files:
0.200.1715 by Jelmer Vernooij
Fix some more tests.
299
                try:
300
                    path = mapping.parse_file_id(fileid)
301
                except ValueError:
302
                    raise errors.RevisionNotPresent((fileid, revid), self)
0.200.1233 by Jelmer Vernooij
Implement Repository.iter_files_bytes.
303
                try:
304
                    obj = tree_lookup_path(
305
                        self._git.object_store.__getitem__, root_tree, path)
306
                    if isinstance(obj, tuple):
307
                        (mode, item_id) = obj
308
                        obj = self._git.object_store[item_id]
309
                except KeyError:
310
                    raise errors.RevisionNotPresent((fileid, revid), self)
311
                else:
312
                    if obj.type_name == "tree":
313
                        yield (identifier, [])
314
                    elif obj.type_name == "blob":
315
                        yield (identifier, obj.chunked)
316
                    else:
317
                        raise AssertionError("file text resolved to %r" % obj)
318
0.200.1533 by Jelmer Vernooij
Improve gather_stats.
319
    def gather_stats(self, revid=None, committers=None):
320
        """See Repository.gather_stats()."""
321
        result = super(LocalGitRepository, self).gather_stats(revid, committers)
322
        revs = []
323
        for sha in self._git.object_store:
324
            o = self._git.object_store[sha]
325
            if o.type_name == "commit":
326
                revs.append(o.id)
327
        result['revisions'] = len(revs)
328
        return result
329
0.252.46 by Jelmer Vernooij
Generate refs/bzr/* if not set yet.
330
    def _iter_revision_ids(self):
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
331
        mapping = self.get_mapping()
0.252.21 by Jelmer Vernooij
Fix GitRepository.all_revision_ids() to find all revisions.
332
        for sha in self._git.object_store:
333
            o = self._git.object_store[sha]
334
            if not isinstance(o, Commit):
335
                continue
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
336
            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.
337
                mapping.revision_id_foreign_to_bzr)
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
338
            yield o.id, rev.revision_id, roundtrip_revid
0.252.46 by Jelmer Vernooij
Generate refs/bzr/* if not set yet.
339
340
    def all_revision_ids(self):
0.200.1727 by Jelmer Vernooij
Change all_revision_ids type to list.
341
        ret = set()
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
342
        for git_sha, revid, roundtrip_revid in self._iter_revision_ids():
343
            if roundtrip_revid:
344
                ret.add(roundtrip_revid)
0.200.1325 by Jelmer Vernooij
More test fixes.
345
            else:
346
                ret.add(revid)
0.200.1727 by Jelmer Vernooij
Change all_revision_ids type to list.
347
        return list(ret)
0.200.74 by Jelmer Vernooij
Implement Repository.all_revision_ids().
348
0.200.1552 by Jelmer Vernooij
Claim to support nested trees.
349
    def _get_parents(self, revid, no_alternates=False):
0.200.1328 by Jelmer Vernooij
More test fixes.
350
        if type(revid) != str:
351
            raise ValueError
352
        try:
0.200.1343 by Jelmer Vernooij
Update docstrings.
353
            (hexsha, mapping) = self.lookup_bzr_revision_id(revid)
0.200.1328 by Jelmer Vernooij
More test fixes.
354
        except errors.NoSuchRevision:
355
            return None
0.200.1552 by Jelmer Vernooij
Claim to support nested trees.
356
        # FIXME: Honor no_alternates setting
0.200.1328 by Jelmer Vernooij
More test fixes.
357
        try:
0.200.1553 by Jelmer Vernooij
Avoid using nonexistant method.
358
            commit = self._git.object_store[hexsha]
0.200.1328 by Jelmer Vernooij
More test fixes.
359
        except KeyError:
360
            return None
361
        return [
362
            self.lookup_foreign_revision_id(p, mapping)
363
            for p in commit.parents]
364
0.200.1552 by Jelmer Vernooij
Claim to support nested trees.
365
    def _get_parent_map_no_fallbacks(self, revids):
366
        return self.get_parent_map(revids, no_alternates=True)
367
368
    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.
369
        parent_map = {}
370
        for revision_id in revids:
0.200.1552 by Jelmer Vernooij
Claim to support nested trees.
371
            parents = self._get_parents(revision_id, no_alternates=no_alternates)
0.285.5 by Jelmer Vernooij
Fix import.
372
            if revision_id == _mod_revision.NULL_REVISION:
0.200.1329 by Jelmer Vernooij
Fix more tests.
373
                parent_map[revision_id] = ()
374
                continue
0.200.1328 by Jelmer Vernooij
More test fixes.
375
            if parents is None:
376
                continue
0.200.1324 by Jelmer Vernooij
More work on roundtripping support.
377
            if len(parents) == 0:
0.285.5 by Jelmer Vernooij
Fix import.
378
                parents = [_mod_revision.NULL_REVISION]
0.200.1094 by Jelmer Vernooij
Fix test_get_no_parents.
379
            parent_map[revision_id] = tuple(parents)
0.200.131 by Jelmer Vernooij
Fix all tests but two, use rich roots by default.
380
        return parent_map
381
0.200.1281 by Jelmer Vernooij
Provide Repository.get_known_graph_ancestry.
382
    def get_known_graph_ancestry(self, revision_ids):
383
        """Return the known graph for a set of revision ids and their ancestors.
384
        """
385
        pending = set(revision_ids)
386
        parent_map = {}
387
        while pending:
0.200.1328 by Jelmer Vernooij
More test fixes.
388
            this_parent_map = {}
389
            for revid in pending:
0.285.5 by Jelmer Vernooij
Fix import.
390
                if revid == _mod_revision.NULL_REVISION:
0.200.1328 by Jelmer Vernooij
More test fixes.
391
                    continue
392
                parents = self._get_parents(revid)
393
                if parents is not None:
394
                    this_parent_map[revid] = parents
0.200.1281 by Jelmer Vernooij
Provide Repository.get_known_graph_ancestry.
395
            parent_map.update(this_parent_map)
396
            pending = set()
397
            map(pending.update, this_parent_map.itervalues())
398
            pending = pending.difference(parent_map)
399
        return _mod_graph.KnownGraph(parent_map)
400
0.200.43 by David Allouche
Ultra-experimental support for "bzr pull". No test. No sanity.
401
    def get_signature_text(self, revision_id):
402
        raise errors.NoSuchRevision(self, revision_id)
403
0.200.1244 by Jelmer Vernooij
Implement GitRepository.check.
404
    def check(self, revision_ids=None, callback_refs=None, check_repo=True):
405
        result = GitCheck(self, check_repo=check_repo)
406
        result.check(callback_refs)
407
        return result
408
0.257.1 by Jelmer Vernooij
use transport repo objects even for local access.
409
    def pack(self, hint=None, clean_obsolete_packs=False):
410
        self._git.object_store.pack_loose_objects()
411
0.200.650 by Jelmer Vernooij
Use standard names for lookup functions.
412
    def lookup_foreign_revision_id(self, foreign_revid, mapping=None):
0.200.124 by Jelmer Vernooij
Add lookup_revision_id stub.
413
        """Lookup a revision id.
0.200.676 by Jelmer Vernooij
Avoid iterating over all keys in the tdb database.
414
0.200.1508 by Jelmer Vernooij
Add docstring, use peel_sha.
415
        :param foreign_revid: Foreign revision id to look up
416
        :param mapping: Mapping to use (use default mapping if not specified)
417
        :raise KeyError: If foreign revision was not found
418
        :return: bzr revision id
0.200.124 by Jelmer Vernooij
Add lookup_revision_id stub.
419
        """
0.200.1033 by Jelmer Vernooij
Don't claim to support working trees for bare repositories.
420
        assert type(foreign_revid) is str
0.200.649 by Jelmer Vernooij
Make GitRevisions VF implementation behave as the interface expects.
421
        if mapping is None:
422
            mapping = self.get_mapping()
0.200.914 by Jelmer Vernooij
Fix tests.
423
        if foreign_revid == ZERO_SHA:
0.285.5 by Jelmer Vernooij
Fix import.
424
            return _mod_revision.NULL_REVISION
0.200.1508 by Jelmer Vernooij
Add docstring, use peel_sha.
425
        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.
426
        if not isinstance(commit, Commit):
427
            raise NotCommitError(commit.id)
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
428
        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.
429
            mapping.revision_id_foreign_to_bzr)
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
430
        # FIXME: check testament before doing this?
431
        if roundtrip_revid:
432
            return roundtrip_revid
433
        else:
434
            return rev.revision_id
0.200.124 by Jelmer Vernooij
Add lookup_revision_id stub.
435
0.200.60 by Jelmer Vernooij
Support signature functions.
436
    def has_signature_for_revision_id(self, revision_id):
0.200.1343 by Jelmer Vernooij
Update docstrings.
437
        """Check whether a GPG signature is present for this revision.
438
439
        This is never the case for Git repositories.
440
        """
0.200.60 by Jelmer Vernooij
Support signature functions.
441
        return False
442
0.200.913 by Jelmer Vernooij
Fix tests.
443
    def lookup_bzr_revision_id(self, bzr_revid, mapping=None):
0.200.1343 by Jelmer Vernooij
Update docstrings.
444
        """Lookup a bzr revision id in a Git repository.
445
446
        :param bzr_revid: Bazaar revision id
447
        :param mapping: Optional mapping to use
448
        :return: Tuple with git commit id, mapping that was used and supplement
449
            details
450
        """
0.200.105 by Jelmer Vernooij
Add common function for finding git commit by bzr revid.
451
        try:
0.200.1343 by Jelmer Vernooij
Update docstrings.
452
            (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.
453
        except errors.InvalidRevisionId:
0.200.913 by Jelmer Vernooij
Fix tests.
454
            if mapping is None:
455
                mapping = self.get_mapping()
0.252.6 by Jelmer Vernooij
Roundtripping support for revision ids works.
456
            try:
0.200.1307 by Jelmer Vernooij
Formatting fixes, specify path to a couple more functions.
457
                return (self._git.refs[mapping.revid_as_refname(bzr_revid)],
458
                        mapping)
0.252.6 by Jelmer Vernooij
Roundtripping support for revision ids works.
459
            except KeyError:
0.252.46 by Jelmer Vernooij
Generate refs/bzr/* if not set yet.
460
                # Update refs from Git commit objects
461
                # FIXME: Hitting this a lot will be very inefficient...
0.200.1601 by Jelmer Vernooij
remove compatibility code for bzr < 2.5.
462
                pb = ui.ui_factory.nested_progress_bar()
463
                try:
464
                    for i, (git_sha, revid, roundtrip_revid) in enumerate(self._iter_revision_ids()):
465
                        if not roundtrip_revid:
466
                            continue
467
                        pb.update("resolving revision id", i)
468
                        refname = mapping.revid_as_refname(roundtrip_revid)
469
                        self._git.refs[refname] = git_sha
470
                        if roundtrip_revid == bzr_revid:
471
                            return git_sha, mapping
472
                finally:
473
                    pb.finished()
0.200.913 by Jelmer Vernooij
Fix tests.
474
                raise errors.NoSuchRevision(self, bzr_revid)
0.200.1343 by Jelmer Vernooij
Update docstrings.
475
        else:
476
            return (git_sha, mapping)
0.200.105 by Jelmer Vernooij
Add common function for finding git commit by bzr revid.
477
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
478
    def get_revision(self, revision_id):
0.200.1101 by Jelmer Vernooij
Raise InvalidRevisionId on invalid type being specified to Repository.get_revision.
479
        if not isinstance(revision_id, str):
480
            raise errors.InvalidRevisionId(revision_id, self)
0.200.650 by Jelmer Vernooij
Use standard names for lookup functions.
481
        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.
482
        try:
0.200.1552 by Jelmer Vernooij
Claim to support nested trees.
483
            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.
484
        except KeyError:
485
            raise errors.NoSuchRevision(self, revision_id)
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
486
        revision, roundtrip_revid, verifiers = mapping.import_commit(
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
487
            commit, self.lookup_foreign_revision_id)
0.200.131 by Jelmer Vernooij
Fix all tests but two, use rich roots by default.
488
        assert revision is not None
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
489
        # FIXME: check verifiers ?
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
490
        if roundtrip_revid:
491
            revision.revision_id = roundtrip_revid
0.200.43 by David Allouche
Ultra-experimental support for "bzr pull". No test. No sanity.
492
        return revision
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
493
494
    def has_revision(self, revision_id):
0.200.1119 by Jelmer Vernooij
Refactor repository initialization.
495
        """See Repository.has_revision."""
0.285.5 by Jelmer Vernooij
Fix import.
496
        if revision_id == _mod_revision.NULL_REVISION:
0.200.1122 by Jelmer Vernooij
has_revision(null:) should always return True.
497
            return True
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
498
        try:
0.200.902 by Jelmer Vernooij
Fix Repository.has_revision{s,}.
499
            git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
0.200.130 by Jelmer Vernooij
Make most tree inspection tests succeed.
500
        except errors.NoSuchRevision:
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
501
            return False
0.200.902 by Jelmer Vernooij
Fix Repository.has_revision{s,}.
502
        return (git_commit_id in self._git)
503
504
    def has_revisions(self, revision_ids):
0.200.1119 by Jelmer Vernooij
Refactor repository initialization.
505
        """See Repository.has_revisions."""
0.200.913 by Jelmer Vernooij
Fix tests.
506
        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.
507
0.200.1657 by Jelmer Vernooij
Implement iter_revisions.
508
    def iter_revisions(self, revision_ids):
0.200.1119 by Jelmer Vernooij
Refactor repository initialization.
509
        """See Repository.get_revisions."""
0.200.1657 by Jelmer Vernooij
Implement iter_revisions.
510
        for revid in revision_ids:
511
            try:
512
                rev = self.get_revision(revid)
513
            except errors.NoSuchRevision:
514
                rev = None
515
            yield (revid, rev)
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.287.6 by Jelmer Vernooij
Fix some more tests.
524
        if revision_id is None:
525
            raise ValueError('invalid revision id %s' % revision_id)
0.200.195 by Jelmer Vernooij
Return mapping in revision_id_bzr_to_foreign() as required by the interface.
526
        return GitRevisionTree(self, revision_id)
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
527
0.285.4 by Jelmer Vernooij
Add get_deltas_for_revisoins implementation.
528
    def get_deltas_for_revisions(self, revisions, specific_fileids=None):
529
        """Produce a generator of revision deltas.
530
531
        Note that the input is a sequence of REVISIONS, not revision_ids.
532
        Trees will be held in memory until the generator exits.
533
        Each delta is relative to the revision's lefthand predecessor.
534
535
        :param specific_fileids: if not None, the result is filtered
536
          so that only those file-ids, their parents and their
537
          children are included.
538
        """
539
        # Get the revision-ids of interest
540
        required_trees = set()
541
        for revision in revisions:
542
            required_trees.add(revision.revision_id)
543
            required_trees.update(revision.parent_ids[:1])
544
0.200.1743 by Jelmer Vernooij
Fix some revision delta filtering.
545
        trees = dict((t.get_revision_id(), t) for
546
            t in self.revision_trees(required_trees))
0.285.4 by Jelmer Vernooij
Add get_deltas_for_revisoins implementation.
547
548
        # Calculate the deltas
549
        for revision in revisions:
550
            if not revision.parent_ids:
551
                old_tree = self.revision_tree(_mod_revision.NULL_REVISION)
552
            else:
553
                old_tree = trees[revision.parent_ids[0]]
0.200.1743 by Jelmer Vernooij
Fix some revision delta filtering.
554
            new_tree = trees[revision.revision_id]
555
            if specific_fileids is not None:
556
                specific_files = [new_tree.id2path(fid) for fid in specific_fileids]
557
            else:
558
                specific_files = None
559
            yield new_tree.changes_from(old_tree, specific_files=specific_files)
0.285.4 by Jelmer Vernooij
Add get_deltas_for_revisoins implementation.
560
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
561
    def get_inventory(self, revision_id):
0.264.4 by Jelmer Vernooij
No longer implement Repository.get_inventory.
562
        raise NotImplementedError(self.get_inventory)
0.200.43 by David Allouche
Ultra-experimental support for "bzr pull". No test. No sanity.
563
0.200.108 by Jelmer Vernooij
Support bzr init --git.
564
    def set_make_working_trees(self, trees):
0.287.6 by Jelmer Vernooij
Fix some more tests.
565
        raise errors.UnsupportedOperation(self.set_make_working_trees, self)
0.200.108 by Jelmer Vernooij
Support bzr init --git.
566
0.200.276 by Jelmer Vernooij
Improve formatting.
567
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
0.286.6 by Jelmer Vernooij
Pass through limit argument.
568
        progress=None, limit=None):
569
        return self._git.fetch_objects(determine_wants, graph_walker, progress,
570
            limit=limit)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
571
0.200.43 by David Allouche
Ultra-experimental support for "bzr pull". No test. No sanity.
572
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
573
class GitRepositoryFormat(repository.RepositoryFormat):
0.200.429 by Jelmer Vernooij
get remote dpush to a point where we now what to send.
574
    """Git repository format."""
0.203.1 by Aaron Bentley
Make checkouts work
575
0.200.1294 by Jelmer Vernooij
Mark as not supporting versioned directories.
576
    supports_versioned_directories = False
0.203.1 by Aaron Bentley
Make checkouts work
577
    supports_tree_reference = False
0.200.133 by Jelmer Vernooij
Unmark as deprecated.
578
    rich_root_data = True
0.200.1105 by Jelmer Vernooij
Don't claim to support leaving locks.
579
    supports_leaving_lock = False
0.200.1106 by Jelmer Vernooij
Claim to support fast deltas.
580
    fast_deltas = True
0.200.1123 by Jelmer Vernooij
Set more repository format flags.
581
    supports_funky_characters = True
0.200.1560 by Jelmer Vernooij
stacking is not supported.
582
    supports_external_lookups = False
0.200.1135 by Jelmer Vernooij
Set supports_full_versioned_files=False.
583
    supports_full_versioned_files = False
0.200.1162 by Jelmer Vernooij
Set RepositoryFormat.supports_revision_signatures.
584
    supports_revision_signatures = False
0.200.1383 by Jelmer Vernooij
Claim to not support nested repositories.
585
    supports_nesting_repositories = False
0.200.1166 by Jelmer Vernooij
Set GitRepositoryFormat.revision_graph_can_have_wrong_parents.
586
    revision_graph_can_have_wrong_parents = False
0.200.1493 by Jelmer Vernooij
Test fixes.
587
    supports_unreferenced_revisions = True
0.200.1665 by Jelmer Vernooij
Rename _matchingbzrdir to _matchingcnotroldir.
588
    supports_setting_revision_ids = False
0.200.1698 by Jelmer Vernooij
Update xfail.
589
    supports_storing_branch_nick = False
590
    supports_overriding_transport = False
0.200.1746 by Jelmer Vernooij
Mark as not supporting custom revision properties.
591
    supports_custom_revision_properties = False
0.200.71 by Jelmer Vernooij
Implement GitRepositoryFormat.get_format_description.
592
0.200.1083 by Jelmer Vernooij
Register repository format.
593
    @property
0.200.1665 by Jelmer Vernooij
Rename _matchingbzrdir to _matchingcnotroldir.
594
    def _matchingcontroldir(self):
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
595
        from .dir import LocalGitControlDirFormat
0.200.1083 by Jelmer Vernooij
Register repository format.
596
        return LocalGitControlDirFormat()
597
0.200.71 by Jelmer Vernooij
Implement GitRepositoryFormat.get_format_description.
598
    def get_format_description(self):
599
        return "Git Repository"
0.200.133 by Jelmer Vernooij
Unmark as deprecated.
600
0.200.1084 by Jelmer Vernooij
Support 'initializing' repositories in control directories.
601
    def initialize(self, controldir, shared=False, _internal=False):
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
602
        from .dir import GitDir
0.200.1084 by Jelmer Vernooij
Support 'initializing' repositories in control directories.
603
        if not isinstance(controldir, GitDir):
604
            raise errors.UninitializableFormat(self)
605
        return controldir.open_repository()
0.200.133 by Jelmer Vernooij
Unmark as deprecated.
606
607
    def check_conversion_target(self, target_repo_format):
608
        return target_repo_format.rich_root_data
0.200.536 by Jelmer Vernooij
Implement network name.
609
0.200.658 by Jelmer Vernooij
Provide right infrastructure for foreign repository tests from bzrlib.
610
    def get_foreign_tests_repository_factory(self):
0.200.1654 by Jelmer Vernooij
Fix test import.
611
        from .tests.test_repository import (
0.200.713 by Jelmer Vernooij
Improve formatting.
612
            ForeignTestsRepositoryFactory,
613
            )
0.200.658 by Jelmer Vernooij
Provide right infrastructure for foreign repository tests from bzrlib.
614
        return ForeignTestsRepositoryFactory()
615
0.200.536 by Jelmer Vernooij
Implement network name.
616
    def network_name(self):
617
        return "git"