-
Notifications
You must be signed in to change notification settings - Fork 0
/
gn
executable file
·30 lines (25 loc) · 993 Bytes
/
gn
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
#!/usr/bin/python
#
# Print a diff summary like:
#
# $ git diff 'master~10..master' | gn
# 293 lines of diff
# 185 lines added
# 19 lines removed
# +166 lines net change
import sys, os, re, fileinput
def get_lines(diff_lines):
# Added lines start with '+' (but not '+++', because that marks a new
# file). The same goes for removed lines, except '-' instead of '+'.
added_lines = [line for line in diff_lines
if line.startswith('+') and not line.startswith('+++')]
removed_lines = [line for line in diff_lines
if line.startswith('-') and not line.startswith('---')]
return added_lines, removed_lines
if __name__ == '__main__':
diff_lines = list(fileinput.input())
added_lines, removed_lines = get_lines(diff_lines)
print '%i lines of diff' % len(diff_lines)
print '%i lines added' % len(added_lines)
print '%i lines removed' % len(removed_lines)
print '%+i lines net change' % (len(added_lines) - len(removed_lines))