def _unpack_changesets(self, chunkiter, mapping, pb, limit=None): def lookup_foreign_revid(foreign_revid): lookup_foreign_revid = getattr(self.source, "lookup_foreign_revision_id", None) if lookup_foreign_revid is not None: return lookup_foreign_revid(foreign_revid, mapping) return mapping.revision_id_foreign_to_bzr(foreign_revid) def get_hg_revision(hgid): revid = lookup_foreign_revid(hgid) return self._target_overlay.get_changeset_text_by_revid(revid) for i, (fulltext, hgkey, hgparents, csid) in enumerate( unpack_chunk_iter(chunkiter, get_hg_revision)): pb.update("fetching changesets", i) if limit is not None and i >= limit: continue (manifest, user, (time, timezone), files, desc, extra) = \ parse_changeset(fulltext) key = mapping.revision_id_foreign_to_bzr(hgkey) parent_ids = as_bzr_parents(hgparents, lookup_foreign_revid) rev, fileids = mapping.import_revision(key, parent_ids, hgkey, manifest, user, (time, timezone), desc, extra) self._files[rev.revision_id] = files self._manifest2rev_map[manifest].add(rev.revision_id) self._revisions[rev.revision_id] = rev
def get_revision(self, revision_id): if not type(revision_id) is str: raise errors.InvalidRevisionId(revision_id, self) hgrevid, mapping = self.lookup_bzr_revision_id(revision_id) assert mapping is not None hgchange = self._hgrepo.changelog.read(hgrevid) hgparents = self._hgrepo.changelog.parents(hgrevid) parent_ids = as_bzr_parents(hgparents, self.lookup_foreign_revision_id) return mapping.import_revision(revision_id, parent_ids, hgrevid, hgchange[0], hgchange[1].decode("utf-8"), hgchange[2], hgchange[4].decode("utf-8"), hgchange[5])[0]
def get_parent_map(self, revids): ret = {} for revid in revids: if revid == NULL_REVISION: ret[revid] = () continue hgrevid, mapping = self.lookup_bzr_revision_id(revid) # FIXME: what about extra (roundtripped) parents? hgparents = self._hgrepo.changelog.parents(hgrevid) bzrparents = as_bzr_parents(hgparents, self.lookup_foreign_revision_id) if bzrparents == (): ret[revid] = (NULL_REVISION, ) else: ret[revid] = bzrparents return ret
def test_second_null(self): m = {"a" * 20: "reva"} self.assertEquals(("reva",), as_bzr_parents(("a" * 20, nullid), m.__getitem__))
def test_first_null(self): m = {"a" * 20: "reva"} self.assertEquals((NULL_REVISION, "reva"), as_bzr_parents((nullid, "a" * 20), m.__getitem__))
def test_empty(self): self.assertEquals((), as_bzr_parents((nullid, nullid), None))