Last active
April 6, 2022 08:51
-
-
Save StefanoChiodino/3f749424403c6070dae72dc308724dba to your computer and use it in GitHub Desktop.
get all commits sizes in a file
This file contains hidden or 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
#!/usr/bin/env python3 | |
import csv | |
import subprocess | |
import sys | |
git_rev_list = subprocess.check_output( | |
"git log --no-merges --pretty='%H|%an|%aI|%s' origin/master".split(" ")).decode( | |
sys.stdout.encoding).rstrip().splitlines() | |
with open('commit_stats.csv', 'w', ) as file_handler: | |
csv = csv.writer(file_handler) | |
csv.writerow(["id", "author", "size", "file count", "date", "comment"]) | |
for git_rev in git_rev_list: | |
try: | |
commit_size = 0 | |
commit_id, author, date, comment = git_rev.strip("'").split("|", 3) | |
diff_tree = subprocess.check_output( | |
"git diff-tree -r -c -M -C --no-commit-id {}".format(commit_id).split(" ")).decode(sys.stdout.encoding) | |
for diff in diff_tree.splitlines(): | |
try: | |
blob_id = diff.split(" ")[3] | |
if blob_id != "0000000000000000000000000000000000000000": | |
cat_file = subprocess.check_output("git cat-file -s {}".format(blob_id).split(" ")) | |
commit_size += int(cat_file) | |
except: | |
pass | |
csv.writerow([commit_id, author, commit_size, len(diff_tree), date, comment]) | |
except ValueError: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment