Skip to content

Instantly share code, notes, and snippets.

@zhangyuan
Created February 19, 2020 15:11
Show Gist options
  • Save zhangyuan/57a6e0004d3412ee3200ffc953df1070 to your computer and use it in GitHub Desktop.
Save zhangyuan/57a6e0004d3412ee3200ffc953df1070 to your computer and use it in GitHub Desktop.
Extract the git commit stats for analysis
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