Script to generate ChangeLog file from commit log.
[mudpy.git] / bin / git2gch
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 u"""Generates potential ChangeLog file contents from commit messages."""
4
5 # Copyright (c) 2010 Jeremy Stanley <fungi@yuggoth.org>. Permission
6 # to use, copy, modify, and distribute this software is granted under
7 # terms provided in the LICENSE file distributed with this software.
8
9 # needs GitPython: http://gitorious.org/git-python
10 import git, time
11
12 copyright = """\
13 Copyright (c) 2004-2010 Jeremy Stanley <fungi@yuggoth.org>. Permission to
14 use, copy, modify, and distribute this software is granted under terms
15 provided in the LICENSE file distributed with this software.
16
17 """
18
19 emacsinfo = "\f" + """
20 Local Variables:
21 mode: change-log
22 coding: utf-8
23 left-margin: 8
24 fill-column: 76
25 version-control: never
26 End:\
27 """
28
29 generated = ""
30 for commit in git.Repo().log():
31    header = "%s  %s  <%s>" % (
32       time.strftime("%Y-%m-%d %H:%M:%S UTC", commit.authored_date),
33       commit.author.name,
34       commit.author.email
35    )
36    comments = ""
37    for line in commit.message.split("\n")[1:]:
38       if line: line = "\t%s" % line
39       if line.startswith("\t*"): line = "\n%s" % line
40       comments += "%s\n" % line
41    generated += "%s\n%s\n" % ( header, comments)
42 print( "%s%s%s" % (generated, copyright, emacsinfo) )