-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgitloc
executable file
·63 lines (57 loc) · 1.93 KB
/
gitloc
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/python
"""
Display lines of code modified grouped into days. Pass path in if desired.
"""
import subprocess
import re
import sys
from datetime import datetime
total_files, inserted_t, deleted_t = 0, 0, 0
def outputline(date, changes):
global total_files, inserted_t, deleted_t
if not date: return
print "%s |% 7d lines | (%d)" % (date.strftime("%a, %b %d %Y"), changes, inserted_t + deleted_t)
sys.stdout.flush()
def main(argv):
global total_files, inserted_t, deleted_t
command = ["git", "log",
"--shortstat",
"--reverse",
"--ignore-space-change",
"--ignore-all-space",
"--patience",
"--no-color",
"--pretty=%at",
"--diff-filter=AMD",
"--find-copies-harder" , "-l10"]
if len(argv) > 1:
command.append("--")
command.extend(argv[1:])
#print ' '.join(command) # DEBUG
git = subprocess.Popen(command, stdout=subprocess.PIPE)
out, err = git.communicate()
curr_day = None
days_changes = 0
for line in out.split('\n'):
if not line: continue
if line[0] != ' ':
# This is a description line
timestamp = datetime.fromtimestamp(float(line.strip()))
day = datetime.date(timestamp)
else:
# This is a stat line
data = re.findall(
' (\d+) files changed, (\d+) insertions\(\+\), (\d+) deletions\(-\)',
line)
files, insertions, deletions = ( int(x) for x in data[0] )
if day != curr_day:
outputline(curr_day, days_changes)
days_changes = 0
curr_day = day
total_files += files
inserted_t += insertions
deleted_t += deletions
days_changes += insertions + deletions
outputline(curr_day, days_changes)
if __name__ == '__main__':
sys.exit(main(sys.argv))