# Path: pypasta/Util.py
# def get_first_upstream(repo, cluster, commit):
#     upstream = cluster.get_upstream(commit)
#     if not upstream:
#         return None
#     return min(upstream, key=lambda x: repo[x].committer.date)


from functools import partial
from .Util import get_first_upstream


class PatchComposition:
    def __init__(self, backports, forwardports, none):
        """
        :param backports: Patches, that are classified as backports
        :param forwardports: Patches, that are classified as forwardports
        :param none: Remaining patches
        """
        self.backports = backports
        self.forwardports = forwardports
        self.none = none

    @staticmethod
    def is_forwardport(repo, cluster, date_selector, commit):
        """
        Given a commit hash on the patch stack, is_forwardport returns True,
        if the commit is a forward port, False, if it is a backport and None if
        it has no upstream candidate
        :param repo: Repository
        :param cluster: patch groups
        :param date_selector: date_selector
        :param commit: commit on the patch stack
        :return:
        """
        upstream = cluster.get_upstream(commit)
        if not upstream:
            return None

        commits_in_class = cluster.get_downstream(commit)

# Path: pypasta/Util.py
# def get_first_upstream(repo, cluster, commit):
#     upstream = cluster.get_upstream(commit)
#     if not upstream:
#         return None
#     return min(upstream, key=lambda x: repo[x].committer.date)


# Path: pypasta/PatchDynamics.py
from functools import partial
from .Util import get_first_upstream



class PatchComposition:
    def __init__(self, backports, forwardports, none):
        """
        :param backports: Patches, that are classified as backports
        :param forwardports: Patches, that are classified as forwardports
        :param none: Remaining patches
        """
        self.backports = backports
        self.forwardports = forwardports
        self.none = none

    @staticmethod
    def is_forwardport(repo, cluster, date_selector, commit):
        """
        Given a commit hash on the patch stack, is_forwardport returns True,
        if the commit is a forward port, False, if it is a backport and None if
        it has no upstream candidate
        :param repo: Repository
        :param cluster: patch groups
        :param date_selector: date_selector
        :param commit: commit on the patch stack
        :return:
        """
        upstream = cluster.get_upstream(commit)
        if not upstream:
            return None

        commits_in_class = cluster.get_downstream(commit)

        upstream = get_first_upstream(repo, cluster, commit)