113
113
"""See InterRepository.copy_content."""
114
114
self.fetch(revision_id, pb, find_ghosts=False)
116
def fetch_refs(self, update_refs, lossy):
117
"""Fetch possibly roundtripped revisions into the target repository
120
:param update_refs: Generate refs to fetch. Receives dictionary
121
with old refs (git shas), returns dictionary of new names to
116
def dfetch_refs(self, update_refs):
117
"""Fetch non-roundtripped revisions into the target repository.
119
:param update_refs: Generate refs to fetch. Receives dictionary
120
with old names to old git shas. Should return a dictionary
121
of new names to Bazaar revision ids.
122
:return: revision id map, old refs dictionary and new refs dictionary
124
raise NotImplementedError(self.dfetch_refs)
126
def fetch_refs(self, update_refs):
127
"""Fetch possibly roundtripped revisions into the target repository.
129
:param update_refs: Generate refs to fetch. Receives dictionary
130
with old refs (git shas), returns dictionary of new names to
123
:param lossy: Whether to roundtrip
124
132
:return: old refs, new refs
126
134
raise NotImplementedError(self.fetch_refs)
196
185
with Git SHA, Bazaar revid as values.
200
for k in self.target._git.refs.allkeys():
201
v = self.target._git.refs.read_ref(k)
188
refs = self.target._git.get_refs()
189
for k, v in refs.iteritems():
203
for (kind, type_data) in self.source_store.lookup_git_sha(v):
204
if kind == "commit" and self.source.has_revision(type_data[0]):
191
(kind, type_data) = self.source_store.lookup_git_sha(v)
211
199
bzr_refs[k] = (v, revid)
214
def fetch_refs(self, update_refs, lossy):
215
self.source_store.lock_read()
217
old_refs = self._get_target_bzr_refs()
218
new_refs = update_refs(old_refs)
219
revidmap = self.fetch_objects(new_refs.values(), roundtrip=not lossy)
202
def fetch_refs(self, update_refs):
203
self.source.lock_read()
205
old_refs = self._get_target_bzr_refs()
206
new_refs = update_refs(old_refs)
207
self.fetch(mapped_refs=new_refs.values())
210
return old_refs, new_refs
212
def dfetch_refs(self, update_refs):
213
self.source.lock_read()
215
old_refs = self._get_target_bzr_refs()
216
new_refs = update_refs(old_refs)
217
revidmap, gitidmap = self.dfetch(new_refs.values())
220
218
for name, (gitid, revid) in new_refs.iteritems():
221
219
if gitid is None:
223
gitid = revidmap[revid][0]
221
gitid = gitidmap[revid]
225
223
gitid = self.source_store._lookup_revision_sha1(revid)
226
assert len(gitid) == 40
227
self.target_refs[name] = gitid
224
self.target._git.refs[name] = gitid
225
new_refs[name] = (gitid, self.source_store.lookup_git_sha(gitid)[1][0])
229
self.source_store.unlock()
230
228
return revidmap, old_refs, new_refs
232
def fetch_objects(self, revs, roundtrip):
233
todo = list(self.missing_revisions(revs))
235
pb = ui.ui_factory.nested_progress_bar()
237
object_generator = self._get_missing_objects_iterator(pb)
238
for (old_revid, git_sha) in object_generator.import_revisions(
239
todo, roundtrip=roundtrip):
241
self.mapping.revision_id_bzr_to_foreign(old_revid)
242
except errors.InvalidRevisionId:
243
self.target_refs[self.mapping.revid_as_refname(old_revid)] = git_sha
245
new_revid = self.mapping.revision_id_foreign_to_bzr(git_sha)
247
new_revid = old_revid
248
revidmap[old_revid] = (git_sha, new_revid)
249
self.target_store.add_objects(object_generator)
254
230
def _get_missing_objects_iterator(self, pb):
255
231
return MissingObjectsIterator(self.source_store, self.source, pb)
257
233
def dfetch(self, stop_revisions):
258
234
"""Import the gist of the ancestry of a particular revision."""
237
self.source.lock_read()
239
todo = list(self.missing_revisions(stop_revisions))
240
pb = ui.ui_factory.nested_progress_bar()
242
object_generator = self._get_missing_objects_iterator(pb)
243
for old_bzr_revid, git_commit in object_generator.import_revisions(
244
todo, roundtrip=False):
245
new_bzr_revid = self.mapping.revision_id_foreign_to_bzr(git_commit)
246
revidmap[old_bzr_revid] = new_bzr_revid
247
gitidmap[old_bzr_revid] = git_commit
248
self.target_store.add_objects(object_generator)
253
return revidmap, gitidmap
260
255
def fetch(self, revision_id=None, pb=None, find_ghosts=False,
261
256
fetch_spec=None, mapped_refs=None):
262
if not self.mapping.roundtripping:
263
raise NoPushSupport()
264
self.source_store.lock_read()
257
if mapped_refs is not None:
258
stop_revisions = mapped_refs
259
elif revision_id is not None:
260
stop_revisions = [(None, revision_id)]
261
elif fetch_spec is not None:
262
stop_revisions = [(None, revid) for revid in fetch_spec.heads]
264
stop_revisions = [(None, revid) for revid in self.source.all_revision_ids()]
265
self.source.lock_read()
266
if mapped_refs is not None:
267
stop_revisions = mapped_refs
268
elif revision_id is not None:
269
stop_revisions = [(None, revision_id)]
270
elif fetch_spec is not None:
271
stop_revisions = [(None, revid) for revid in fetch_spec.heads]
273
stop_revisions = [(None, revid) for revid in self.source.all_revision_ids()]
274
self.fetch_objects(stop_revisions, roundtrip=True)
267
todo = list(self.missing_revisions(stop_revisions))
268
pb = ui.ui_factory.nested_progress_bar()
270
object_generator = self._get_missing_objects_iterator(pb)
271
for (revid, git_sha) in object_generator.import_revisions(
272
todo, roundtrip=True):
274
self.mapping.revision_id_bzr_to_foreign(revid)
275
except errors.InvalidRevisionId:
276
self.target_refs[self.mapping.revid_as_refname(revid)] = git_sha
277
self.target_store.add_objects(object_generator)
276
self.source_store.unlock()
279
284
def is_compatible(source, target):
285
290
class InterToRemoteGitRepository(InterToGitRepository):
287
def fetch_refs(self, update_refs, lossy):
292
def dfetch_refs(self, update_refs):
288
293
"""Import the gist of the ancestry of a particular revision."""
290
raise NoPushSupport()
291
unpeel_map = UnpeelMap.from_repository(self.source)
293
295
def determine_wants(old_refs):
295
self.old_refs = dict([(k, (v, None)) for (k, v) in old_refs.iteritems()])
297
self.old_refs = old_refs
296
298
self.new_refs = update_refs(self.old_refs)
297
299
for name, (gitid, revid) in self.new_refs.iteritems():
298
300
if gitid is None:
299
git_sha = self.source_store._lookup_revision_sha1(revid)
300
ret[name] = unpeel_map.re_unpeel_tag(git_sha, old_refs.get(name))
301
ret[name] = self.source_store._lookup_revision_sha1(revid)
302
303
ret[name] = gitid
304
self.source_store.lock_read()
305
self.source.lock_read()
306
307
new_refs = self.target.send_pack(determine_wants,
307
308
self.source_store.generate_lossy_pack_contents)
309
self.source_store.unlock()
311
311
return revidmap, self.old_refs, self.new_refs
313
def fetch_refs(self, update_refs):
314
raise NoPushSupport()
314
317
def is_compatible(source, target):
315
318
"""Be compatible with GitRepository."""