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