-
Notifications
You must be signed in to change notification settings - Fork 5
/
git-changelog
executable file
·53 lines (48 loc) · 1.37 KB
/
git-changelog
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
#!/usr/bin/env python3
#
# Generate changelog from git history, uses tags.
from __future__ import print_function
import sys
import os
import subprocess
import re
def run(*args):
p = subprocess.Popen(args, stdout=subprocess.PIPE, encoding='utf-8')
return p.communicate()[0]
PAT = re.compile(r'(.*)([ab]\d+)$')
def rev_sort_key(rev):
m = PAT.match(rev)
if m:
return m.group(1), m.group(2)
else:
return rev, 'c1'
def main():
revs = run("git", "tag")
revs = [r for r in revs.split() if r.startswith('v')]
#print 'revs', sorted(revs, key=rev_sort_key)
revs.sort(key=rev_sort_key)
revs.reverse()
if run("git", "--no-pager", "log", "%s..HEAD" % revs[0]).strip():
revs.insert(0, 'HEAD')
revs.append('')
print('Summary of changes')
print('==================')
for i, rev in enumerate(revs[:-1]):
print()
print(rev)
print('-' * len(rev))
print()
sys.stdout.flush()
prevref = revs[i+1]
if prevref:
revspec = "%s..%s" % (prevref, rev)
else:
revspec = rev
#print 'revspec', revspec
output = run("git", "--no-pager", "log", revspec)
for line in output.split('\n'):
if line.startswith('commit '):
continue
sys.stdout.write(line + '\n')
if __name__ == '__main__':
main()