Ejemplo n.º 1
0
    def change(self, tag, value):
        """
        Changes the value of all instances of the tag.

        tag does not contain the terminal ": ". It is case insensitive.
        """
        if not self.f.writable():
            raise exc.KSException("Modification of read-only Patch")

        if len(self.get(tag)):
            self.modified = True
            start = "%s: " % (tag.lower(), )

            def change_value(line):
                if line.lower().startswith(start):
                    return "%s%s\n" % (
                        line[:len(start)],
                        value.strip(),
                    )
                else:
                    return line

            self.head = [change_value(line) for line in self.head]
        else:
            raise KeyError("Tag \"%s\" not found" % (tag, ))
Ejemplo n.º 2
0
    def remove(self, tag):
        """
        Removes all instances of the tag.

        tag does not contain the terminal ": ". It is case insensitive.
        """
        if not self.f.writable():
            raise exc.KSException("Modification of read-only Patch")

        if len(self.get(tag)):
            self.modified = True
            start = "%s: " % (tag.lower(),)
            self.head = [line
                         for line in self.head
                         if not line.lower().startswith(start)]
Ejemplo n.º 3
0
    def from_patch(self, index, name, current_head, move_upstream):
        """
        This is where we decide a patch line's fate in the sorted series.conf
        The following factors determine how a patch is sorted:
        * commit found in index
        * patch's series.conf current_head is indexed (ie. the local repo
          fetches from that remote)
        * patch appears to have moved downstream/didn't move/upstream
        * patch's tag is good ("Git-repo:" == current_head.url)
        * patches may be moved upstream between subsystem sections
        """
        self.name = name
        if not os.path.exists(name):
            raise exc.KSError("Could not find patch \"%s\"" % (name, ))

        with Patch(open(name, mode="rb")) as patch:
            commit_tags = patch.get("Git-commit")
            repo_tags = patch.get("Git-repo")

        if not commit_tags:
            self.dest_head = git_sort.oot
            return

        class BadTag(Exception):
            pass

        def get_commit(value):
            if not value:
                raise BadTag(value)
            tag = series_conf.firstword(value)
            if not self.commit_match.match(tag):
                raise BadTag(tag)
            return tag

        try:
            self.revs = [get_commit(value) for value in commit_tags]
        except BadTag as e:
            raise exc.KSError("Git-commit tag \"%s\" in patch \"%s\" is not a "
                              "valid revision." % (
                                  e.args[0],
                                  name,
                              ))
        rev = self.revs[0]

        if len(repo_tags) > 1:
            raise exc.KSError("Multiple Git-repo tags found. Patch \"%s\" is "
                              "tagged improperly." % (name, ))
        elif repo_tags:
            repo = git_sort.RepoURL(repo_tags[0])
        elif commit_tags:
            repo = git_sort.remotes[0].repo_url
        self.new_url = None

        try:
            ic = index.lookup(rev)
        except git_sort.GSKeyError:  # commit not found
            if current_head not in index.repo_heads:  # repo not indexed
                if repo == current_head.repo_url:  # good tag
                    self.dest_head = current_head
                else:  # bad tag
                    raise exc.KSError(
                        "There is a problem with patch \"%s\". "
                        "The Git-repo tag is incorrect or the patch is in the "
                        "wrong section of series.conf and (the Git-commit tag "
                        "is incorrect or the relevant remote is outdated or "
                        "not available locally) or an entry for this "
                        "repository is missing from \"remotes\". In the last "
                        "case, please edit \"remotes\" in "
                        "\"scripts/git_sort/git_sort.py\" and commit the "
                        "result. Manual intervention is required." % (name, ))
            else:  # repo is indexed
                if repo == current_head.repo_url:  # good tag
                    raise exc.KSError(
                        "There is a problem with patch \"%s\". "
                        "Commit \"%s\" not found in git-sort index. "
                        "The remote fetching from \"%s\" needs to be fetched "
                        "or the Git-commit tag is incorrect or the patch is "
                        "in the wrong section of series.conf. Manual "
                        "intervention is required." % (
                            name,
                            rev,
                            current_head.repo_url,
                        ))
                else:  # bad tag
                    raise exc.KSError(
                        "There is a problem with patch \"%s\". "
                        "The Git-repo tag is incorrect or the patch is in the "
                        "wrong section of series.conf. Manual intervention is "
                        "required." % (name, ))
        else:  # commit found
            msg_bad_tag = "There is a problem with patch \"%s\". " \
                    "The Git-repo tag is incorrect or the patch is in " \
                    "the wrong section of series.conf. Manual " \
                    "intervention is required." % (name,)
            if current_head not in index.repo_heads:  # repo not indexed
                if ic.head > current_head:  # patch moved downstream
                    if repo == current_head.repo_url:  # good tag
                        self.dest_head = current_head
                    else:  # bad tag
                        raise exc.KSError(msg_bad_tag)
                elif ic.head == current_head:  # patch didn't move
                    raise exc.KSException(
                        "Head \"%s\" is not available locally but commit "
                        "\"%s\" found in patch \"%s\" was found in that head."
                        % (
                            ic.head,
                            rev,
                            name,
                        ))
                elif ic.head < current_head:  # patch moved upstream
                    if move_upstream:  # move patches between subsystem sections
                        self.dest_head = ic.head
                        self.dest = ic
                        if repo != ic.head.repo_url:  # bad tag
                            self.new_url = ic.head.repo_url
                    else:  # do not move patches between subsystem sections
                        if repo == current_head.repo_url:  # good tag
                            self.dest_head = current_head
                        else:  # bad tag
                            raise exc.KSError(msg_bad_tag)
            else:  # repo is indexed
                if ic.head > current_head:  # patch moved downstream
                    if repo == current_head.repo_url:  # good tag
                        raise exc.KSError(
                            "There is a problem with patch \"%s\". "
                            "The patch is in the wrong section of series.conf "
                            "or the remote fetching from \"%s\" needs to be "
                            "fetched or the relative order of \"%s\" and "
                            "\"%s\" in \"remotes\" is incorrect. Manual "
                            "intervention is required." % (
                                name,
                                current_head.repo_url,
                                ic.head,
                                current_head,
                            ))
                    else:  # bad tag
                        raise exc.KSError(
                            "There is a problem with patch \"%s\". "
                            "The patch is in the wrong section of series.conf "
                            "or the remote fetching from \"%s\" needs to be "
                            "fetched. Manual intervention is required." % (
                                name,
                                current_head.repo_url,
                            ))
                elif ic.head == current_head:  # patch didn't move
                    self.dest_head = ic.head
                    self.dest = ic
                    if repo != ic.head.repo_url:  # bad tag
                        self.new_url = ic.head.repo_url
                elif ic.head < current_head:  # patch moved upstream
                    if move_upstream:  # move patches between subsystem sections
                        self.dest_head = ic.head
                        self.dest = ic
                        if repo != ic.head.repo_url:  # bad tag
                            self.new_url = ic.head.repo_url
                    else:  # do not move patches between subsystem sections
                        if repo == current_head.repo_url:  # good tag
                            self.dest_head = current_head
                            self.dest = ic
                        else:  # bad tag
                            raise exc.KSError(msg_bad_tag)