122
121
raise AssertionError("Unknown blob kind, perms=%r." % (mode,))
125
def import_git_objects(repo, mapping, num_objects, object_iter, pb=None):
124
def import_git_objects(repo, mapping, object_iter, pb=None):
126
125
"""Import a set of git objects into a bzr repository.
128
127
:param repo: Bazaar repository
129
128
:param mapping: Mapping to use
130
:param num_objects: Number of objects.
131
129
:param object_iter: Iterator over Git objects.
133
131
# TODO: a more (memory-)efficient implementation of this
135
133
for i, o in enumerate(object_iter):
136
134
if pb is not None:
137
pb.update("fetching objects", i, num_objects)
135
pb.update("fetching objects", i)
138
136
objects[o.id] = o
163
161
return objects[sha]
164
162
return reconstruct_git_object(repo, mapping, sha)
165
163
parent_invs = [repo.get_inventory(r) for r in rev.parent_ids]
166
import_git_tree(repo, mapping, "", root_tree, inv, parent_invs,
164
import_git_tree(repo, mapping, "", root_tree, inv, parent_invs, lookup_object)
168
165
repo.add_revision(rev.revision_id, rev, inv)
221
218
self.target.start_write_group()
223
(num_objects, objects_iter) = \
224
self.source.fetch_objects(determine_wants,
225
graph_walker, progress)
226
import_git_objects(self.target, mapping, num_objects,
220
import_git_objects(self.target, mapping,
221
iter(self.source.fetch_objects(determine_wants, graph_walker,
229
224
self.target.commit_write_group()
238
233
"""Be compatible with GitRepository."""
239
234
# FIXME: Also check target uses VersionedFile
240
235
return (isinstance(source, GitRepository) and
241
target.supports_rich_root() and
242
not isinstance(target, GitRepository))
245
class InterGitRepository(InterRepository):
247
_matching_repo_format = GitFormat()
250
def _get_repo_format_to_test():
253
def copy_content(self, revision_id=None, pb=None):
254
"""See InterRepository.copy_content."""
255
self.fetch(revision_id, pb, find_ghosts=False)
257
def fetch(self, revision_id=None, pb=None, find_ghosts=False,
260
mapping = self.source.get_mapping()
262
info("git: %s", text)
264
if revision_id is None:
265
determine_wants = lambda x: [y for y in x.values() if not y in r.object_store]
267
args = [mapping.revision_id_bzr_to_foreign(revision_id)]
268
determine_wants = lambda x: [y for y in args if not y in r.object_store]
270
graphwalker = SimpleFetchGraphWalker(r.heads().values(), r.get_parents)
271
f, commit = r.object_store.add_pack()
273
self.source._git.fetch_pack(path, determine_wants, graphwalker, f.write, progress)
281
def is_compatible(source, target):
282
"""Be compatible with GitRepository."""
283
return (isinstance(source, GitRepository) and
284
isinstance(target, GitRepository))
236
target.supports_rich_root())