Skip to content

Instantly share code, notes, and snippets.

@tomviner
Created January 10, 2014 14:39
Show Gist options
  • Save tomviner/8355234 to your computer and use it in GitHub Desktop.
Save tomviner/8355234 to your computer and use it in GitHub Desktop.
Git when last changed dict
#!/usr/bin/env python
import subprocess
from collections import defaultdict
def latest():
filesdict = {}
changecount = defaultdict(int)
stringlist = subprocess.check_output(["git","ls-files"]).split("\n")
statlist = subprocess.check_output(["git","whatchanged"]).split("\n")
for line in statlist:
if line.startswith("Date"):
temp = line[8:]
if line.startswith(':'):
_ , file_name = line.split('\t',1)
changecount[file_name] += 1
if file_name not in filesdict:
filesdict[file_name] = temp
return filesdict, changecount
def pretty(filesdict, changecount):
for k, v in sorted(filesdict.items(), key=lambda x: changecount[x[0]]):
print "Filename: {}".format(k)
print "Date: {}".format(v)
print "Changes: {}".format(changecount[k])
print
if __name__ == '__main__':
filesdict, changecount = latest()
pretty(filesdict, changecount)
from subprocess import Popen, PIPE
from collections import defaultdict
mycmd = ['git', 'log', '--pretty="%at"', "--name-only"]
data_stream = Popen(mycmd, stdout=PIPE)
for line in data_stream.stdout:
line = line.strip()
print line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment