def _get_commits_files(repo): data = repo.git.log('--numstat','--pretty=format:"sha: %H"').split("sha: ") comms = {} for d in data[1:]: d = d.replace('"', '').replace('\n\n', '\n').split('\n') commit_sha = d[0] comms[commit_sha] = [] for x in d[1:-1]: insertions, deletions, name = x.split('\t') names = Commit.fix_renamed_files([name]) comms[commit_sha].extend(list(map(lambda n: CommittedFile(commit_sha, n, insertions, deletions), names))) return dict(map(lambda x: (repo.commit(x), comms[x]), filter(lambda x: comms[x], comms)))
def extract_files_commits(obj_git): data = obj_git.connect.git.log( '--numstat', '--name-status', '--pretty=format:"sha: %H parents: %P"').split("sha: ") comms = {} files = {} for d in data[1:]: d = d.replace('"', '').replace('\n\n', '\n').split('\n') sha, parent = d[0].split(" parents: ") commit_sha = sha comms[commit_sha] = [parent.split(" "), []] for x in d[1:-1]: try: split = x.split('\t') status, name = split[0], split[1:] if len(name) == 1: name = name[0] if status.startswith("R"): if name[0].endswith( ".java") and not name[0].endswith("Test.java"): if len(parent.split(" ")) > 1: print(f"{name[0]}") name = Commit.fix_renamed_files(name) comms[commit_sha][1].extend([name]) # files.setdefault(name, []).append(commit_sha) elif name.endswith(".java") and not name.endswith("Test.java"): if status != 'A' and status != "D": if len(parent.split(" ")) > 1: print(f"{name}") name = Commit.fix_renamed_files([name])[0] comms[commit_sha][1].extend([name]) # files.setdefault(name, []).append(commit_sha) except Exception as e: print(e) print(x) pass return dict( map(lambda x: (x, comms[x]), filter(lambda x: comms[x][1], comms))), files