def convert_commitcves_to_cvecommits(commit_db):
    """
    Convert commit => cveinfo mapping to cve => commit mapping
    :param commit_db: the dict with commit_id => cveinfo mapping
    returns a new dict with cve => commit mapping
    """
    src_files_key = "src_files"
    cvedb = {}
    for commit in commit_db:
        cveinfo = commit_db[commit]
        for cvetype in cveinfo:
            cvelist = cveinfo[cvetype]
            for cve_id in cvelist:
                cve = cvelist[cve_id]
                src_files = []
                if cve and src_files_key in cve:
                    src_files = cve[src_files_key]
                commit_entry = {"commit": commit}
                if src_files:
                    commit_entry[src_files_key] = src_files
                if cve_id not in cvedb:
                    cvedb[cve_id] = {cvetype: []}
                # Both added_commits and fixed_commits are now a list of commit_entry
                if cvetype not in cvedb[cve_id]:
                    cvedb[cve_id][cvetype] = [commit_entry,]
                else:
                    cvedb[cve_id][cvetype].append( commit_entry )
    return cvedb