Beispiel #1
0
    def get_original_mapping(self, foreign_revid):
        """See RevisionInfoCache.get_original_mapping."""

        self.mutter("get-original-mapping %r", foreign_revid)
        ret = self.db[b"original-mapping/%d %s" % (
            foreign_revid[2], foreign_revid[1].encode('utf-8'))]
        if ret == "":
            return None
        return mapping_registry.parse_mapping_name("svn-" + ret)
Beispiel #2
0
    def get_original_mapping(self, foreign_revid):
        """See RevisionInfoCache.get_original_mapping."""

        row = self.execute("select original_mapping from original_mapping where path = ? and revnum = ?", (foreign_revid[1], foreign_revid[2])).fetchone()
        if row is None:
            raise KeyError(foreign_revid)
        if row[0] is None:
            return None
        else:
            return mapping_registry.parse_mapping_name("svn-" + row[0].encode("utf-8"))
Beispiel #3
0
    def bisect_fileprop_revid_revnum(self, revid, branch_path, min_revnum,
                                     max_revnum):
        """Find out what the actual revnum was that corresponds to a revid.

        :param revid: Revision id to search for
        :param branch_path: Branch path at which to start searching
        :param min_revnum: Last revnum to check
        :param max_revnum: First revnum to check
        :return: Tuple with foreign revision id and mapping
        """
        assert min_revnum <= max_revnum
        # Find the branch property between min_revnum and max_revnum that
        # added revid
        for revmeta in self.repos._revmeta_provider.iter_reverse_branch_changes(
                branch_path, max_revnum, min_revnum):
            for propname, (
                    oldpropvalue,
                    propvalue) in revmeta.get_changed_fileprops().iteritems():
                if not propname.startswith(SVN_PROP_BZR_REVISION_ID):
                    continue
                try:
                    new_lines = find_new_lines(oldpropvalue, propvalue)
                    if len(new_lines) != 1:
                        continue
                except ValueError:
                    # Don't warn about encountering an invalid property,
                    # that will already have happened earlier
                    continue
                try:
                    (entry_revno,
                     entry_revid) = parse_revid_property(new_lines[0])
                except InvalidPropertyValue:
                    # Don't warn about encountering an invalid property,
                    # that will already have happened earlier
                    continue
                if entry_revid == revid:
                    mapping_name = propname[len(SVN_PROP_BZR_REVISION_ID):]
                    mapping = mapping_registry.parse_mapping_name("svn-" +
                                                                  mapping_name)
                    assert mapping.is_branch_or_tag(
                        revmeta.metarev.branch_path)
                    return (revmeta.metarev.get_foreign_revid(), mapping)
        raise InvalidBzrSvnRevision(revid)
Beispiel #4
0
    def discover_fileprop_revids(self,
                                 layout,
                                 from_revnum,
                                 to_revnum,
                                 project=None,
                                 pb=None):
        assert from_revnum >= to_revnum
        for revmeta in self.find_branch_tips(layout, from_revnum, to_revnum,
                                             project):
            if pb is not None:
                pb.update("finding fileprop revids",
                          from_revnum - revmeta.metarev.revnum,
                          from_revnum - to_revnum)
            # Look at their bzr:revision-id-vX
            revids = set()
            try:
                if revmeta.consider_bzr_fileprops():
                    for revid, bzr_revno, mapping_name in revmeta.get_roundtrip_ancestor_revids(
                    ):
                        revids.add(((bzr_revno, revid), mapping_name))
            except subvertpy.SubversionException as e:
                msg, num = e.args
                if num in (subvertpy.ERR_FS_NOT_DIRECTORY,
                           subvertpy.ERR_RA_DAV_FORBIDDEN):
                    continue
                raise

            # If there are any new entries that are not yet in the cache,
            # add them
            for ((entry_revno, entry_revid), mapping_name) in revids:
                try:
                    mapping = mapping_registry.parse_mapping_name("svn-" +
                                                                  mapping_name)
                except KeyError:
                    pass
                else:
                    yield (entry_revid, revmeta.metarev.branch_path, 0,
                           revmeta.metarev.revnum, mapping)
Beispiel #5
0
    def get_branch_revnum(self, revid, layout, project=None):
        # Check the record out of the cache, if it exists
        try:
            (branch_path, min_revnum, max_revnum, \
                    mapping) = self.cache.lookup_revid(revid)
            assert isinstance(branch_path, text_type)
            assert type(mapping) is str
            # Entry already complete?
            assert min_revnum <= max_revnum
            if min_revnum == max_revnum:
                return ((self.actual.repos.uuid, branch_path, min_revnum),
                        mapping_registry.parse_mapping_name("svn-" + mapping))
        except NoSuchRevision as e:
            last_revnum = self._get_last_revnum()
            last_checked = self._get_last_checked(layout, project)
            if last_checked > last_revnum:
                warn_uuid_reuse(self.actual.repos.uuid, self.actual.repos.base)
            if last_revnum == last_checked:
                # All revision ids in this repository for the current
                # layout have already been discovered. No need to
                # check again.
                raise e
            found = None
            fileprops_to_revnum = last_revnum
            with ui.ui_factory.nested_progress_bar() as pb:
                for entry_revid, branch, revnum, mapping in self.actual.discover_revprop_revids(
                        last_revnum, last_checked, pb=pb):
                    fileprops_to_revnum = min(fileprops_to_revnum, revnum)
                    if entry_revid == revid:
                        found = (branch, revnum, revnum, mapping)
                    self.remember_entry(entry_revid, branch, revnum, revnum,
                                        mapping.name)

            if fileprops_to_revnum > last_checked:
                with ui.ui_factory.nested_progress_bar() as pb:
                    for entry_revid, branch, min_revno, max_revno, mapping in self.actual.discover_fileprop_revids(
                            layout, fileprops_to_revnum, last_checked, project,
                            pb):
                        min_revno = max(last_checked, min_revno)
                        if entry_revid == revid:
                            found = (branch, min_revno, max_revno, mapping)
                        self.remember_entry(entry_revid, branch, min_revno,
                                            max_revno, mapping.name)

            # We've added all the revision ids for this layout in the
            # repository, so no need to check again unless new revisions got
            # added
            self.cache.set_last_revnum_checked(repr((layout, project)),
                                               last_revnum)
            if found is None:
                raise e
            (branch_path, min_revnum, max_revnum, mapping) = found
            if min_revnum == max_revnum:
                return (self.actual.repos.uuid, branch_path,
                        min_revnum), mapping
            assert min_revnum <= max_revnum
            assert isinstance(branch_path, text_type)

        ((uuid, branch_path, revnum),
         mapping) = self.actual.bisect_fileprop_revid_revnum(
             revid, branch_path, min_revnum, max_revnum)
        assert isinstance(branch_path, text_type)
        self.remember_entry(revid, branch_path, revnum, revnum, mapping.name)
        return (uuid, branch_path, revnum), mapping