# Path: pypasta/Util.py
# def format_date_ymd(dt):
#     return dt.strftime('%Y-%m-%d')
# 
# 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 multiprocessing import Pool, cpu_count
from .Util import format_date_ymd, get_first_upstream
                base_commit = str(repo[repo.lookup_reference(base_ref).target].target)
                stack_commit = str(repo.lookup_reference(stack_ref).target)

                worklist.append((stack.stack_version, base_commit, stack_commit))

        p = Pool(cpu_count())
        results = p.map(_diffstat_helper, worklist)
        p.close()
        p.join()
        _tmp_repo = None

        with open(f_diffstat, 'w') as f:
            f.write('Version,Deletions,Insertions\n')
            for version_name, deletions, insertions in results:
                    f.write('%s,%d,%d\n' %
                            (version_name, deletions, insertions))

    def release_dates(self, f_mainline_release_dates, f_stack_release_dates):
        stacks = dict()
        base = dict()

        for group_name, stacks_in_group in self.psd.iter_groups():
            for stack in stacks_in_group:
                stacks[stack.stack_version] = group_name, stack.stack_release_date
                base[stack.base_version] = stack.base_release_date

        with open(f_mainline_release_dates, 'w') as f:
            f.write('Version,ReleaseDate\n')
            for version, date in base.items():
                f.write('%s,%s\n' %

# Path: pypasta/Util.py
# def format_date_ymd(dt):
#     return dt.strftime('%Y-%m-%d')
# 
# 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/Export.py
from multiprocessing import Pool, cpu_count
from .Util import format_date_ymd, get_first_upstream

                base_commit = str(repo[repo.lookup_reference(base_ref).target].target)
                stack_commit = str(repo.lookup_reference(stack_ref).target)

                worklist.append((stack.stack_version, base_commit, stack_commit))

        p = Pool(cpu_count())
        results = p.map(_diffstat_helper, worklist)
        p.close()
        p.join()
        _tmp_repo = None

        with open(f_diffstat, 'w') as f:
            f.write('Version,Deletions,Insertions\n')
            for version_name, deletions, insertions in results:
                    f.write('%s,%d,%d\n' %
                            (version_name, deletions, insertions))

    def release_dates(self, f_mainline_release_dates, f_stack_release_dates):
        stacks = dict()
        base = dict()

        for group_name, stacks_in_group in self.psd.iter_groups():
            for stack in stacks_in_group:
                stacks[stack.stack_version] = group_name, stack.stack_release_date
                base[stack.base_version] = stack.base_release_date

        with open(f_mainline_release_dates, 'w') as f:
            f.write('Version,ReleaseDate\n')
            for version, date in base.items():
                f.write('%s,%s\n' %

                        (version, format_date_ymd(date)))