def _resolve_tags_ancestry(self, tag_revmetas, graph, last_revid): """Resolve a name -> revmeta dictionary using the ancestry of a branch. :param tag_revmetas: Dictionary mapping names to revmeta objects :param graph: Graph object :param last_revid: Branch last revid :return: Dictionary mapping unicode tag names to revision ids """ ret = {} reverse_tag_revmetas = reverse_dict(tag_revmetas) foreign_revid_map = {} for revmeta in reverse_tag_revmetas: foreign_revid_map[revmeta.metarev.get_foreign_revid()] = revmeta for revid, _ in graph.iter_ancestry([last_revid]): if len(reverse_tag_revmetas) == 0: # No more tag revmetas to resolve, just return immediately return ret try: foreign_revid, m = mapping_registry.parse_revision_id(revid) except bzr_errors.InvalidRevisionId: continue if not foreign_revid in foreign_revid_map: continue revmeta = foreign_revid_map[foreign_revid] for name in reverse_tag_revmetas[revmeta]: ret[name] = (revmeta, m, revid) del reverse_tag_revmetas[revmeta] ret.update( _resolve_reverse_tags_fallback(self.branch, reverse_tag_revmetas)) return ret
def extract_svn_foreign_revid(rev): try: foreign_revid = rev.foreign_revid except AttributeError: from breezy.plugins.svn.mapping import mapping_registry foreign_revid, mapping = \ mapping_registry.parse_revision_id(rev.revision_id) return foreign_revid else: from breezy.plugins.svn.mapping import foreign_vcs_svn if rev.mapping.vcs == foreign_vcs_svn: return foreign_revid else: raise InvalidRevisionId(rev.revision_id, None)
def keyword_rev(revid, rev, relpath, revmeta): """last revno that changed this file""" # See if c.revision() can be traced back to a subversion revision # Revision comes directly from a foreign repository if revmeta is not None: return str(revmeta.revnum) if revid is None: return None # Revision was once imported from a foreign repository try: foreign_revid, mapping = mapping_registry.parse_revision_id(revid) except InvalidRevisionId: pass else: return str(foreign_revid[2]) # If we can't find the actual svn revision, just return the bzr revid return revid
def _match_on_foreign(self, branch): ret = set() try: revnum = self._get_revnum() except ValueError: raise InvalidRevisionSpec(self.user_spec, branch) branch.lock_read() try: graph = branch.repository.get_graph() for revid, _ in graph.iter_ancestry([branch.last_revision()]): try: (found_uuid, found_branch_path, found_revnum), found_mapping = \ mapping_registry.parse_revision_id(revid) if found_revnum == revnum: return self._create_revinfo(branch, revid) ret.add(revid) except InvalidRevisionId: continue raise InvalidRevisionSpec(self.user_spec, branch) finally: branch.unlock()
def test_v1(self): self.assertEqual((("uuid", "trunk", 1), BzrSvnMappingv1(TrunkLayout())), mapping_registry.parse_revision_id("svn-v1:1@uuid-trunk"))
def test_v3_undefined(self): self.assertEqual((("uuid", "trunk", 1), BzrSvnMappingv3(TrunkBranchingScheme())), mapping_registry.parse_revision_id("svn-v3-undefined:uuid:trunk:1"))
def test_v4(self): self.assertEqual((("uuid", "trunk", 1), BzrSvnMappingv4()), mapping_registry.parse_revision_id("svn-v4:uuid:trunk:1"))