1
# Copyright (C) 2009-2018 Jelmer Vernooij <jelmer@jelmer.uk>
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Push implementation that simply prints message saying push is not supported."""
19
from __future__ import absolute_import
22
class MissingObjectsIterator(object):
23
"""Iterate over git objects that are missing from a target repository.
27
def __init__(self, store, source, pb=None):
28
"""Create a new missing objects iterator.
32
self._object_store = store
36
def import_revisions(self, revids, lossy):
37
"""Import a set of revisions into this git repository.
39
:param revids: Revision ids of revisions to import
40
:param lossy: Whether to not roundtrip bzr metadata
42
for i, revid in enumerate(revids):
44
self.pb.update("pushing revisions", i, len(revids))
45
git_commit = self.import_revision(revid, lossy)
46
yield (revid, git_commit)
48
def import_revision(self, revid, lossy):
49
"""Import a revision into this Git repository.
51
:param revid: Revision id of the revision
52
:param roundtrip: Whether to roundtrip bzr metadata
54
tree = self._object_store.tree_cache.revision_tree(revid)
55
rev = self.source.get_revision(revid)
57
for path, obj, ie in self._object_store._revision_to_objects(rev, tree, lossy):
58
if obj.type_name == "commit":
60
self._pending.append((obj, path))
62
raise AssertionError("no commit object generated for revision %s" %
67
return len(self._pending)
70
return iter(self._pending)
73
class ObjectStoreParentsProvider(object):
75
def __init__(self, store):
78
def get_parent_map(self, shas):
85
parents = self._store[sha].parents
92
def remote_divergence(old_sha, new_sha, store):
95
if not isinstance(old_sha, bytes):
96
raise TypeError(old_sha)
97
if not isinstance(new_sha, bytes):
98
raise TypeError(new_sha)
99
from breezy.graph import Graph
100
graph = Graph(ObjectStoreParentsProvider(store))
101
return not graph.is_ancestor(old_sha, new_sha)