1
# Copyright (C) 2009 Jelmer Vernooij <jelmer@samba.org>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Push implementation that simply prints message saying push is not supported."""
22
from bzrlib.repository import (
26
from bzrlib.plugins.git.errors import (
29
from bzrlib.plugins.git.mapping import (
30
inventory_to_tree_and_blobs,
33
from bzrlib.plugins.git.repository import (
38
class InterToGitRepository(InterRepository):
39
"""InterRepository that copies into a Git repository."""
41
_matching_repo_format = GitRepositoryFormat()
44
def _get_repo_format_to_test():
47
def copy_content(self, revision_id=None, pb=None):
48
"""See InterRepository.copy_content."""
49
self.fetch(revision_id, pb, find_ghosts=False)
51
def fetch(self, revision_id=None, pb=None, find_ghosts=False,
55
def import_revision_gist(self, revid, parent_lookup):
56
"""Import the gist of a revision into this Git repository.
60
rev = self.source.get_revision(revid)
61
for sha, object, path in inventory_to_tree_and_blobs(
62
self.source.get_inventory(revid), self.source.texts, None):
65
objects.append((object, path))
66
commit = revision_to_commit(rev, tree_sha, parent_lookup)
67
objects.append((commit, None))
68
self.target._git.object_store.add_objects(objects)
69
return commit.sha().hexdigest()
71
def missing_revisions(self, stop_revision=None, ghosts=False):
72
if stop_revision is not None:
73
ancestry = [x for x in self.source.get_ancestry(stop_revision) if x is not None]
75
ancestry = self.source.all_revision_ids()
77
graph = self.source.get_graph()
78
for revid in graph.iter_topo_order(ancestry):
79
if not self.target.has_revision(revid):
85
def dfetch(self, stop_revision=None, fetch_ghosts=False):
86
"""Import the gist of the ancestry of a particular revision."""
89
def parent_lookup(revid):
91
return gitidmap[revid]
93
return self.target.lookup_git_revid(revid)[0]
94
mapping = self.target.get_mapping()
95
self.source.lock_write()
97
todo = self.missing_revisions(stop_revision, ghosts=fetch_ghosts)
98
pb = ui.ui_factory.nested_progress_bar()
100
for i, revid in enumerate(todo):
101
pb.update("pushing revisions", i, len(todo))
102
git_commit = self.import_revision_gist(revid, parent_lookup)
103
gitidmap[revid] = git_commit
104
git_revid = mapping.revision_id_foreign_to_bzr(git_commit)
105
revidmap[revid] = git_revid
109
self.source.fetch(self.target,
110
revision_id=revidmap[stop_revision])
116
def is_compatible(source, target):
117
"""Be compatible with GitRepository."""
118
return (not isinstance(source, GitRepository) and
119
isinstance(target, GitRepository))