]> iEval git - fdkaac.git/blame - git2changelog.py
fix warning: cast size_t as sprintf() arg to int
[fdkaac.git] / git2changelog.py
CommitLineData
2f960ef8 1#!/usr/bin/env python
2
3# Copyright (C) 2013 nu774
4# For conditions of distribution and use, see copyright notice in COPYING
5
6import sys
7import re
8from subprocess import Popen, PIPE
9from itertools import groupby
10from collections import namedtuple
11
12GITLOG_FMT = 'commit %H%nauthor %cn <%ae>%ndate %ad%nsubject %s%nref %d%n%n'
13GITLOG_CMD = ['git','log','--date=short','--format={0}'.format(GITLOG_FMT)]
14
15Commit = namedtuple('Commit', 'commit author date subject ref')
16
17def parse_gitlog(stream):
0c502d30 18 re_decode_ref = re.compile(r'(?<=\()([^,)]+)')
19 re_strip_tag = re.compile(r'^tag: ')
2f960ef8 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':
0c502d30 26 m = re_decode_ref.search(value)
27 if m:
28 value = ' [{0}]'.format(re_strip_tag.sub('', m.group()))
29 else:
30 value = ''
2f960ef8 31 commit[key] = value
32 elif commit:
33 yield Commit(**commit)
34 commit = dict()
35
36output=sys.stdout.write
37
38with 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('{0} {1}\n\n'.format(date, author))
43 for c in commits:
44 output(' * {0}{1}\n\n'.format(c.subject, c.ref))
This page took 0.024708 seconds and 4 git commands to generate.