New upstream version 1.0.0
[fdkaac.git] / git2changelog.py
1 #!/usr/bin/env python
2
3 # Copyright (C) 2013 nu774
4 # For conditions of distribution and use, see copyright notice in COPYING
5
6 import sys
7 import re
8 from subprocess import Popen, PIPE
9 from itertools import groupby
10 from collections import namedtuple
11
12 GITLOG_FMT = 'commit %H%nauthor %cn <%ae>%ndate %ad%nsubject %s%nref %d%n%n'
13 GITLOG_CMD = ['git','log','--date=short','--format={0}'.format(GITLOG_FMT)]
14
15 Commit = namedtuple('Commit', 'commit author date subject ref')
16
17 def parse_gitlog(stream):
18 re_decode_ref = re.compile(r'(?<=\()([^,)]+)')
19 re_strip_tag = re.compile(r'^tag: ')
20 commit = dict()
21 for line in stream:
22 fields = line.decode('utf-8').rstrip('\r\n').split(' ', 1)
23 if len(fields) == 2:
24 key, value = fields
25 if key == 'ref':
26 m = re_decode_ref.search(value)
27 if m:
28 value = ' [{0}]'.format(re_strip_tag.sub('', m.group()))
29 else:
30 value = ''
31 commit[key] = value
32 elif commit:
33 yield Commit(**commit)
34 commit = dict()
35
36 output=sys.stdout.write
37
38 with Popen(GITLOG_CMD, shell=False, stdout=PIPE).stdout as pipe:
39 commits = parse_gitlog(pipe)
40 commits_by_date_author = groupby(commits, key=lambda x: (x.date, x.author))
41 for (date, author), commits in commits_by_date_author:
42 output(u'{0} {1}\n\n'.format(date, author).encode('utf-8'))
43 for c in commits:
44 output(u' * {0}{1}\n\n'.format(c.subject, c.ref).encode('utf-8'))
This page took 0.022326 seconds and 4 git commands to generate.