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."""
23
from bzrlib.repository import (
26
from bzrlib.revision import (
30
from bzrlib.plugins.git.errors import (
33
from bzrlib.plugins.git.object_store import (
36
from bzrlib.plugins.git.repository import (
41
from bzrlib.plugins.git.remote import (
46
class MissingObjectsIterator(object):
47
"""Iterate over git objects that are missing from a target repository.
51
def __init__(self, store, source, pb=None):
52
"""Create a new missing objects iterator.
56
self._object_store = store
60
def import_revisions(self, revids):
61
for i, revid in enumerate(revids):
63
self.pb.update("pushing revisions", i, len(revids))
64
git_commit = self.import_revision(revid)
65
yield (revid, git_commit)
67
def import_revision(self, revid):
68
"""Import the gist of a revision into this Git repository.
71
inv = self._object_store.parent_invs_cache.get_inventory(revid)
72
rev = self.source.get_revision(revid)
74
for path, obj in self._object_store._revision_to_objects(rev, inv):
75
if obj._type == "commit":
77
self._pending.append((obj, path))
81
return len(self._pending)
84
return iter(self._pending)
87
class InterToGitRepository(InterRepository):
88
"""InterRepository that copies into a Git repository."""
90
_matching_repo_format = GitRepositoryFormat()
92
def __init__(self, source, target):
93
super(InterToGitRepository, self).__init__(source, target)
94
self.mapping = self.target.get_mapping()
95
self.source_store = BazaarObjectStore(self.source, self.mapping)
98
def _get_repo_format_to_test():
101
def copy_content(self, revision_id=None, pb=None):
102
"""See InterRepository.copy_content."""
103
self.fetch(revision_id, pb, find_ghosts=False)
105
def fetch(self, revision_id=None, pb=None, find_ghosts=False,
107
raise NoPushSupport()
110
class InterToLocalGitRepository(InterToGitRepository):
112
def missing_revisions(self, stop_revisions, check_revid):
114
pb = ui.ui_factory.nested_progress_bar()
116
graph = self.source.get_graph()
117
for revid, _ in graph.iter_ancestry(stop_revisions):
118
pb.update("determining revisions to fetch", len(missing))
119
if not check_revid(revid):
120
missing.append(revid)
121
return graph.iter_topo_order(missing)
125
def dfetch_refs(self, refs):
127
revidmap, gitidmap = self.dfetch(refs.values())
128
for name, revid in refs.iteritems():
129
if revid in gitidmap:
130
gitid = gitidmap[revid]
132
gitid = self.source_store._lookup_revision_sha1(revid)
133
self.target._git.refs[name] = gitid
134
new_refs[name] = gitid
135
return revidmap, new_refs
137
def dfetch(self, stop_revisions):
138
"""Import the gist of the ancestry of a particular revision."""
141
self.source.lock_read()
143
target_store = self.target._git.object_store
144
def check_revid(revid):
145
if revid == NULL_REVISION:
148
return (self.source_store._lookup_revision_sha1(revid) in target_store)
149
except errors.NoSuchRevision:
152
todo = list(self.missing_revisions(stop_revisions, check_revid))
153
pb = ui.ui_factory.nested_progress_bar()
155
object_generator = MissingObjectsIterator(self.source_store, self.source, pb)
156
for old_bzr_revid, git_commit in object_generator.import_revisions(
158
new_bzr_revid = self.mapping.revision_id_foreign_to_bzr(git_commit)
159
revidmap[old_bzr_revid] = new_bzr_revid
160
gitidmap[old_bzr_revid] = git_commit
161
target_store.add_objects(object_generator)
166
return revidmap, gitidmap
169
def is_compatible(source, target):
170
"""Be compatible with GitRepository."""
171
return (not isinstance(source, GitRepository) and
172
isinstance(target, LocalGitRepository))
175
class InterToRemoteGitRepository(InterToGitRepository):
177
def dfetch_refs(self, new_refs):
178
"""Import the gist of the ancestry of a particular revision."""
180
def determine_wants(refs):
182
for name, revid in new_refs.iteritems():
183
ret[name] = self.source_store._lookup_revision_sha1(revid)
185
self.source.lock_read()
187
new_refs = self.target.send_pack(determine_wants,
188
self.source_store.generate_pack_contents)
191
return revidmap, new_refs
194
def is_compatible(source, target):
195
"""Be compatible with GitRepository."""
196
return (not isinstance(source, GitRepository) and
197
isinstance(target, RemoteGitRepository))