Created
February 19, 2020 15:11
-
-
Save zhangyuan/57a6e0004d3412ee3200ffc953df1070 to your computer and use it in GitHub Desktop.
Extract the git commit stats for analysis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from git import Repo | |
import sys | |
import csv | |
def build_changes(repo): | |
changes = [] | |
for commit in repo.iter_commits("master"): | |
for filename, stats in commit.stats.files.items(): | |
changes.append([ | |
commit.hexsha, | |
commit.authored_date, | |
commit.authored_datetime, | |
commit.committed_date, | |
commit.committed_datetime, | |
commit.committer.name, | |
commit.committer.email, | |
filename, | |
stats['insertions'], | |
stats['deletions'], | |
stats['lines'] | |
]) | |
return changes | |
if __name__ == "__main__": | |
repo_path = sys.argv[1] | |
repo = Repo(repo_path) | |
changes = build_changes(repo) | |
with open("data.csv", 'w') as csvfile: | |
spamwriter = csv.writer(csvfile, quoting=csv.QUOTE_MINIMAL) | |
for change in changes: | |
spamwriter.writerow(change) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment