Created
February 12, 2025 20:34
-
-
Save iTrooz/90166f551dd1dd49400ae2f7a6a1e800 to your computer and use it in GitHub Desktop.
Sort authors in a git repository by total contributed lines (I know it's useless)
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
import os | |
import re | |
output = os.popen('git shortlog -s -n').read() | |
lines = {} | |
for line in output.split("\n"): | |
if not line: | |
continue | |
name = line.split("\t")[1] | |
CMD = r"""git log --author="%REPLACE" --pretty=tformat: --numstat | gawk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s removed lines: %s total lines: %s\n", add, subs, loc }' -""" | |
CMD = CMD.replace("%REPLACE", name) | |
out = os.popen(CMD).read().strip() | |
match = re.search(r'total lines: (\d+)', out) | |
if match: | |
total_lines = int(match.group(1)) | |
lines[(name, out)] = total_lines | |
sorted_lines = dict(sorted(lines.items(), key=lambda item: item[1], reverse=True)) | |
for (name, out), total_lines in sorted_lines.items(): | |
print(f"{name}: {out}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment