Skip to content

Instantly share code, notes, and snippets.

/count-words.py Secret

Created May 1, 2014 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3e8003c84e7655966bc5 to your computer and use it in GitHub Desktop.
Save anonymous/3e8003c84e7655966bc5 to your computer and use it in GitHub Desktop.
#!/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