/
gitlog2changelog.py
85 lines (64 loc) · 1.87 KB
/
gitlog2changelog.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
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
##
## Cherokee SVNlog2Changelog script
##
## Copyright: Alvaro Lopez Ortega <alvaro@alobbs.com>
## Licensed: GPL v2
##
import re
import sys
import time
from sys import stdin
from developers import DEVELOPERS
def get_commits():
chunk = ''
commits = []
while True:
line = stdin.readline()
if not line:
break
elif line.startswith("commit"):
if not chunk:
chunk += "%s" %(line)
else:
commits.append (chunk)
chunk = "%s" %(line)
else:
chunk += "%s" %(line)
if chunk:
commits.append(chunk)
return commits
def format_body (body):
result = ""
prev_blank = False
for line in body.splitlines():
if "git-svn-id: svn://" in line:
continue
if not line.strip():
if prev_blank:
continue
else:
result += "%s\n"%(line)
prev_blank = True
else:
result += "%s\n"%(line)
prev_blank = False
return result
def do_parse():
for entry in get_commits():
commit = re.findall(r"commit (\w+)", entry)[0]
author = re.findall(r"Author: +(.+) \<", entry)[0]
date = re.findall(r"Date: +(.+)", entry)[0]
if not "git-svn-id:" in entry:
print >> sys.stderr, "Unpushed commit: %s, %s - %s" % (author, date, commit)
continue
svn_id = re.findall(r"git-svn-id: svn://cherokee-project.com/.+@(.+) ", entry)[0]
header_end = entry.index('\n\n')
if header_end == -1:
continue
print ("%s %s" %(date, DEVELOPERS[author]))
print (" svn=%s git=%s" %(svn_id, commit))
print ("")
print (format_body(entry[header_end + 2:]))
if __name__ == "__main__":
do_parse()