Skip to content

anonymous /count-words.py secret
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#!/usr/bin/env python
import sys
from subprocess import Popen, PIPE
from os import path
filename = 'gitoutput.txt'
commit_old = raw_input("Enter the original commit ID: ")
commit_new = raw_input("Enter the new commit ID: ")
git_command = "/usr/bin/git diff " + commit_old + ".." + commit_new + " --word-diff=porcelain > " + filename
git_query = Popen(git_command, shell=True, stdout=PIPE, stderr=PIPE)
output = git_query.communicate()[0]
f=open(filename,'r')
newwords=0
delwords=0
for lines in f:
f1=lines.split()
try:
f2=f1[0]
f3=f2[0]
if f3=='+':
newwords=newwords+len(f1)
elif f3=='-':
delwords=delwords+len(f1)
except:
print "Line not counted (either empty or contains unchanged words)"
f.close()
networds=newwords-delwords
print 'new words:', str(newwords)
print 'deleted words:', str(delwords)
print 'net additions:', str(networds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.