113
116
def dfetch_refs(self, update_refs):
114
117
"""Fetch non-roundtripped revisions into the target repository.
116
:param update_refs: Generate refs to fetch. Receives dictionary
119
:param update_refs: Generate refs to fetch. Receives dictionary
117
120
with old names to old git shas. Should return a dictionary
118
121
of new names to Bazaar revision ids.
119
122
:return: revision id map, old refs dictionary and new refs dictionary
123
126
def fetch_refs(self, update_refs):
124
127
"""Fetch possibly roundtripped revisions into the target repository.
126
:param update_refs: Generate refs to fetch. Receives dictionary
127
with old refs (git shas), returns dictionary of new names to
129
:param update_refs: Generate refs to fetch. Receives dictionary
130
with old refs (git shas), returns dictionary of new names to
129
132
:return: old refs, new refs
139
142
self.target_store = self.target._git.object_store
140
143
self.target_refs = self.target._git.refs
142
def _revision_needs_fetching(self, sha_id, revid):
145
def _revision_needs_fetching(self, revid):
143
146
if revid == NULL_REVISION:
147
sha_id = self.source_store._lookup_revision_sha1(revid)
149
sha_id = self.source_store._lookup_revision_sha1(revid)
151
raise errors.NoSuchRevision(self.source, revid)
151
153
return (sha_id not in self.target_store)
152
154
except errors.NoSuchRevision:
156
158
def missing_revisions(self, stop_revisions):
157
159
"""Find the revisions that are missing from the target repository.
159
:param stop_revisions: Revisions to check for (tuples with
161
:param stop_revisions: Revisions to check for
161
162
:return: sequence of missing revisions, in topological order
162
163
:raise: NoSuchRevision if the stop_revisions are not present in
168
for (sha1, revid) in stop_revisions:
169
if sha1 is not None and revid is not None:
170
revid_sha_map[revid] = sha1
171
elif sha1 is not None:
172
stop_sha1s.append(sha1)
174
assert revid is not None
175
stop_revids.append(revid)
177
167
graph = self.source.get_graph()
178
168
pb = ui.ui_factory.nested_progress_bar()
180
for revid, _ in graph.iter_ancestry(stop_revids):
170
for revid, _ in graph.iter_ancestry(stop_revisions):
181
171
assert type(revid) is str
182
172
pb.update("determining revisions to fetch", len(missing))
183
sha1 = revid_sha_map.get(revid)
184
if self._revision_needs_fetching(sha1, revid):
173
if self._revision_needs_fetching(revid):
185
174
missing.append(revid)
188
for sha1 in stop_sha1s:
190
(kind, (revid, tree_sha, verifiers)) = self.source_store.lookup_git_sha(sha1)
194
missing.append(revid)
195
revid_sha_map[revid] = sha1
196
177
return graph.iter_topo_order(missing)
198
179
def _get_target_bzr_refs(self):
205
186
refs = self.target._git.get_refs()
206
187
for k, v in refs.iteritems():
208
(kind, type_data) = self.source_store.lookup_git_sha(v)
189
(kind, (revid, treesha)) = self.source_store.lookup_git_sha(v)
216
192
bzr_refs[k] = (v, revid)
222
198
old_refs = self._get_target_bzr_refs()
223
199
new_refs = update_refs(old_refs)
224
self.fetch(mapped_refs=new_refs.values())
200
# FIXME: Keep track of already looked up revid<->sha mappings
201
fetch_spec = PendingAncestryResult(
202
[revid for sha, revid in new_refs.values()], self.source)
203
self.fetch(fetch_spec=fetch_spec)
226
205
self.source.unlock()
227
206
return old_refs, new_refs
254
233
self.source.lock_read()
256
todo = list(self.missing_revisions(stop_revisions))
235
todo = list(self.missing_revisions([revid for sha, revid in stop_revisions]))
257
236
pb = ui.ui_factory.nested_progress_bar()
259
238
object_generator = self._get_missing_objects_iterator(pb)
270
249
return revidmap, gitidmap
272
251
def fetch(self, revision_id=None, pb=None, find_ghosts=False,
273
fetch_spec=None, mapped_refs=None):
274
if mapped_refs is not None:
275
stop_revisions = mapped_refs
276
elif revision_id is not None:
277
stop_revisions = [(None, revision_id)]
253
if revision_id is not None:
254
stop_revisions = [revision_id]
278
255
elif fetch_spec is not None:
279
stop_revisions = [(None, revid) for revid in fetch_spec.heads]
256
stop_revisions = fetch_spec.heads
281
stop_revisions = [(None, revid) for revid in self.source.all_revision_ids()]
258
stop_revisions = self.source.all_revision_ids()
282
259
self.source.lock_read()
284
261
todo = list(self.missing_revisions(stop_revisions))