1
# Copyright (C) 2008 Canonical Ltd
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
from bzrlib.errors import InvalidRevisionId
18
from bzrlib.repository import InterRepository
19
from bzrlib.trace import info
21
from bzrlib.plugins.git.repository import LocalGitRepository, GitRepository, GitFormat
22
from bzrlib.plugins.git.remote import RemoteGitRepository
24
from cStringIO import StringIO
27
class BzrFetchGraphWalker(object):
29
def __init__(self, repository, mapping):
30
self.repository = repository
31
self.mapping = mapping
33
self.heads = set(repository.all_revision_ids())
37
revid = self.mapping.revision_id_foreign_to_bzr(sha)
40
def remove(self, revid):
43
self.heads.remove(revid)
44
if revid in self.parents:
45
for p in self.parents[revid]:
50
ret = self.heads.pop()
51
ps = self.repository.get_parent_map([ret])[ret]
52
self.parents[ret] = ps
53
self.heads.update([p for p in ps if not p in self.done])
56
return self.mapping.revision_id_bzr_to_foreign(ret)
57
except InvalidRevisionId:
62
def import_git_object(repo, object):
63
raise NotImplementedError(import_git_object)
66
class InterGitRepository(InterRepository):
68
_matching_repo_format = GitFormat()
71
def _get_repo_format_to_test():
74
def copy_content(self, revision_id=None, pb=None):
75
"""See InterRepository.copy_content."""
76
self.fetch(revision_id, pb, find_ghosts=False)
78
def fetch(self, revision_id=None, pb=None, find_ghosts=False,
81
mapping = self.source.get_mapping()
84
pb.note("git: %s" % text)
86
info("git: %s" % text)
87
def determine_wants(heads):
88
if revision_id is None:
91
ret = [mapping.revision_id_bzr_to_foreign(revision_id)]
92
return [rev for rev in ret if not self.target.has_revision(mapping.revision_id_foreign_to_bzr(rev))]
93
graph_walker = BzrFetchGraphWalker(self.target, mapping)
94
self.target.lock_write()
96
for o in self.source.fetch_objects(determine_wants, graph_walker, progress):
102
def is_compatible(source, target):
103
"""Be compatible with GitRepository."""
104
# FIXME: Also check target uses VersionedFile
105
return isinstance(source, LocalGitRepository) and target.supports_rich_root()