/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to push.py

Simplify push handling.

Show diffs side-by-side

added added

removed removed

Lines of Context:
113
113
        """See InterRepository.copy_content."""
114
114
        self.fetch(revision_id, pb, find_ghosts=False)
115
115
 
116
 
    def dfetch_refs(self, update_refs):
117
 
        """Fetch non-roundtripped revisions into the target repository.
118
 
 
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
123
 
        """
124
 
        raise NotImplementedError(self.dfetch_refs)
125
 
 
126
 
    def fetch_refs(self, update_refs):
127
 
        """Fetch possibly roundtripped revisions into the target repository.
 
116
    def fetch_refs(self, update_refs, lossy):
 
117
        """Fetch possibly roundtripped revisions into the target repository
 
118
        and update refs.
128
119
 
129
120
        :param update_refs: Generate refs to fetch. Receives dictionary
130
121
            with old refs (git shas), returns dictionary of new names to
131
122
            git shas.
 
123
        :param lossy: Whether to roundtrip
132
124
        :return: old refs, new refs
133
125
        """
134
126
        raise NotImplementedError(self.fetch_refs)
219
211
            bzr_refs[k] = (v, revid)
220
212
        return bzr_refs
221
213
 
222
 
    def fetch_refs(self, update_refs):
223
 
        self.source_store.lock_read()
224
 
        try:
225
 
            old_refs = self._get_target_bzr_refs()
226
 
            new_refs = update_refs(old_refs)
227
 
            self.fetch(mapped_refs=new_refs.values())
228
 
        finally:
229
 
            self.source_store.unlock()
230
 
        return old_refs, new_refs
231
 
 
232
 
    def dfetch_refs(self, update_refs):
233
 
        self.source_store.lock_read()
234
 
        try:
235
 
            old_refs = self._get_target_bzr_refs()
236
 
            new_refs = update_refs(old_refs)
237
 
            gitidmap = {}
238
 
            revidmap = {}
239
 
            todo = list(self.missing_revisions(new_refs.values()))
240
 
            pb = ui.ui_factory.nested_progress_bar()
241
 
            try:
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
 
                    assert type(old_bzr_revid) is str
247
 
                    assert type(new_bzr_revid) is str
248
 
                    assert type(git_commit) is str
249
 
                    revidmap[old_bzr_revid] = new_bzr_revid
250
 
                    gitidmap[old_bzr_revid] = git_commit
251
 
                self.target_store.add_objects(object_generator)
252
 
            finally:
253
 
                pb.finished()
 
214
    def fetch_refs(self, update_refs, lossy):
 
215
        self.source_store.lock_read()
 
216
        try:
 
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)
254
220
            for name, (gitid, revid) in new_refs.iteritems():
255
221
                if gitid is None:
256
222
                    try:
257
 
                        gitid = gitidmap[revid]
 
223
                        gitid = revidmap[revid][0]
258
224
                    except KeyError:
259
225
                        gitid = self.source_store._lookup_revision_sha1(revid)
 
226
                assert len(gitid) == 40
260
227
                self.target_refs[name] = gitid
261
228
        finally:
262
229
            self.source_store.unlock()
263
230
        return revidmap, old_refs, new_refs
264
231
 
 
232
    def fetch_objects(self, revs, roundtrip):
 
233
        todo = list(self.missing_revisions(revs))
 
234
        revidmap = {}
 
235
        pb = ui.ui_factory.nested_progress_bar()
 
236
        try:
 
237
            object_generator = self._get_missing_objects_iterator(pb)
 
238
            for (old_revid, git_sha) in object_generator.import_revisions(
 
239
                todo, roundtrip=roundtrip):
 
240
                try:
 
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
 
244
                if not roundtrip:
 
245
                    new_revid = self.mapping.revision_id_foreign_to_bzr(git_sha)
 
246
                else:
 
247
                    new_revid = old_revid
 
248
                revidmap[old_revid] = (git_sha, new_revid)
 
249
            self.target_store.add_objects(object_generator)
 
250
            return revidmap
 
251
        finally:
 
252
            pb.finished()
 
253
 
265
254
    def _get_missing_objects_iterator(self, pb):
266
255
        return MissingObjectsIterator(self.source_store, self.source, pb)
267
256
 
282
271
                stop_revisions = [(None, revid) for revid in fetch_spec.heads]
283
272
            else:
284
273
                stop_revisions = [(None, revid) for revid in self.source.all_revision_ids()]
285
 
            todo = list(self.missing_revisions(stop_revisions))
286
 
            pb = ui.ui_factory.nested_progress_bar()
287
 
            try:
288
 
                object_generator = self._get_missing_objects_iterator(pb)
289
 
                for (revid, git_sha) in object_generator.import_revisions(
290
 
                    todo, roundtrip=True):
291
 
                    try:
292
 
                        self.mapping.revision_id_bzr_to_foreign(revid)
293
 
                    except errors.InvalidRevisionId:
294
 
                        self.target_refs[self.mapping.revid_as_refname(revid)] = git_sha
295
 
                self.target_store.add_objects(object_generator)
296
 
            finally:
297
 
                pb.finished()
 
274
            self.fetch_objects(stop_revisions, roundtrip=True)
298
275
        finally:
299
276
            self.source_store.unlock()
300
277
 
307
284
 
308
285
class InterToRemoteGitRepository(InterToGitRepository):
309
286
 
310
 
    def dfetch_refs(self, update_refs):
 
287
    def fetch_refs(self, update_refs, lossy):
311
288
        """Import the gist of the ancestry of a particular revision."""
 
289
        if not lossy:
 
290
            raise NoPushSupport()
312
291
        unpeel_map = UnpeelMap.from_repository(self.source)
313
292
        revidmap = {}
314
293
        def determine_wants(old_refs):
328
307
                    self.source_store.generate_lossy_pack_contents)
329
308
        finally:
330
309
            self.source_store.unlock()
 
310
        # FIXME: revidmap?
331
311
        return revidmap, self.old_refs, self.new_refs
332
312
 
333
 
    def fetch_refs(self, update_refs):
334
 
        raise NoPushSupport()
335
 
 
336
313
    @staticmethod
337
314
    def is_compatible(source, target):
338
315
        """Be compatible with GitRepository."""