Esempio n. 1
0
    def __init__(self, display, pubsub, drawer, repo, branches):
        self.display = display
        self.repo = repo
        self.commits_to_draw = set([])

        self.drawable_commit_collector = DrawableCommitCollector(display, pubsub, drawer, repo, branches)
        self.ids_collector = IdsCollector(repo)
Esempio n. 2
0
class Combiner:

    def __init__(self, display, pubsub, drawer, repo, branches):
        self.display = display
        self.repo = repo
        self.commits_to_draw = set([])

        self.drawable_commit_collector = DrawableCommitCollector(display, pubsub, drawer, repo, branches)
        self.ids_collector = IdsCollector(repo)

    def change_branch(self, current_branch_switched):
        self.reconstruct_graphics(current_branch_switched)

    def reconstruct_graphics(self, current_branch_switched):
        self.commits_to_draw = self.two_branches_combine(current_branch_switched)

    def one_branch_combine(self):
        res = self.drawable_commit_collector.collect_n('master', config['commit_limit'])
        self.arrange_commits_by_time(res)
        return res

    def two_branches_combine(self, current_branch_switched):

        first_branch_name = 'master'
        second_branch_name = current_branch_switched

        def collect_drawables():
            first_common, second_common, first_n, second_n = \
                self.drawable_commit_collector.collect_common_and_n(first_branch_name, second_branch_name)

            res = first_common + second_common + first_n + second_n
            return set(res)

        def collect_ids():
            first_common, second_common, first_n, second_n = \
                self.ids_collector.collect_common_and_n(first_branch_name, second_branch_name)

            original_commits_ids = first_n 
            unmerged_commits_ids = second_common
            merged_commits_ids = second_n - unmerged_commits_ids

            return original_commits_ids, merged_commits_ids, unmerged_commits_ids

        def find_bcs():
            one = self.repo.lookup_branch(first_branch_name).get_object()
            two = self.repo.lookup_branch(second_branch_name).get_object()
            bcs = self.repo.merge_base(one.id, two.id)

            for each_drawable in drawables:
                if each_drawable.raw_commit.id == bcs:
                    return each_drawable
            return None

        original, merged, unmerged = collect_ids()

        def assign_branch_ids(drawables_to_assign):

            for each in drawables_to_assign:

                if each.raw_commit.id in original:
                    each.branch_id = 'original'
                if each.raw_commit.id in merged:
                    each.branch_id = 'merged'
                if each.raw_commit.id in unmerged:
                    each.branch_id = 'unmerged'

        drawables = collect_drawables()
        assign_branch_ids(drawables)

        self.arrange_commits_by_time(drawables)

        bcs = find_bcs()
        new_level = bcs.level
        if not bcs.raw_commit.id in merged:
            new_level += 1
        for each_unmerged in filter(lambda elem: elem.branch_id == 'unmerged', drawables):
            each_unmerged.level += new_level

        return drawables

    @staticmethod
    def arrange_commits_by_time(commits):

        def reposition(commit_list):
            for (index, commit) in enumerate(commit_list):
                commit.position = index

        sorted_by_time = sorted(commits, key=lambda c: -c.raw_commit.commit_time)
        reposition(sorted_by_time)