Last active
December 16, 2015 15:38
-
-
Save signed0/5456882 to your computer and use it in GitHub Desktop.
Determine the first and last commit date for each user in a git repo.
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 datetime | |
from collections import defaultdict | |
import subprocess | |
def main(): | |
git_log = subprocess.check_output(['git', 'log', "--pretty=format:%an\t%ct"]) | |
users = defaultdict(list) | |
for line in git_log.split('\n'): | |
name, commit_time = line.strip().split('\t') | |
commit_time = datetime.datetime.fromtimestamp(int(commit_time)) | |
users[name].append(commit_time) | |
print '\t'.join(('User', 'First Commit', 'Last Commit', 'Count')) | |
for name, dates in sorted(users.iteritems(), key=lambda x:x[0]): | |
start, end = min(dates), max(dates) | |
parts = (name, start, end, len(dates)) | |
print '\t'.join(str(s) for s in parts) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment