-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathcount_git_changes.py
More file actions
44 lines (39 loc) · 935 Bytes
/
count_git_changes.py
File metadata and controls
44 lines (39 loc) · 935 Bytes
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
36
37
38
39
40
41
42
43
44
import os
import sys
insertions=0
deletions=0
files=0
FROMVER=""
if len(sys.argv)>1:
FROMVER=sys.argv[1]
TOVER=""
if len(sys.argv)>2:
TOVER=sys.argv[2]
TMPNAME=os.tmpnam()
VER=""
if len(FROMVER)>0:
VER=FROMVER+'..'
if len(TOVER)>0:
if len(VER)==0:
VER='..'
VER=VER+TOVER
os.system('git log --oneline --shortstat %s >%s' % (VER,TMPNAME))
for line in file(TMPNAME).readlines():
if line.find('file') == -1:
continue
if line.find('changed') == -1:
continue
if line.find('insertion') == -1 and line.find('deletion') == -1:
continue
entries=line.split(',')
for e in entries:
if e.find('file') != -1:
files+=int(e.strip().split(' ')[0])
elif e.find('insertion') != -1:
insertions+=int(e.strip().split(' ')[0])
elif e.find('deletion') != -1:
deletions+=int(e.strip().split(' ')[0])
print "Files changed: %d" % files
print "Insertions: %d" % insertions
print "Deletions: %d" % deletions
os.unlink(TMPNAME)