anonymous / count-words.py secret
Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View count-words.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#!/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.