5 # version 2.0, by John Wiegley
7 # The purpose of this code is to turn "git log" output into a complete
8 # ChangeLog, for projects who wish to begin using a ChangeLog, but haven't
11 # This version of git-changelog depends on GitPython:
12 # git://gitorious.org/git-python/mainline.git
20 from git
import * # GitPython
21 from subprocess
import *
23 repo
= Repo(os
.getcwd())
24 ref
= 'origin/master..'
27 # Usage: git changelog [COMMITISH] [-- [PATH]]
31 for arg
in sys
.argv
[1:]:
39 for commit
in repo
.iter_commits(ref
, paths
=path
):
41 author
= commit
.author
42 date
= commit
.committed_date
43 log_text
= commit
.message
.split('\n')[0]
45 log_text_remainder
= commit
.message
.split('\n\n')[1:]
46 while len(log_text_remainder
) > 0 and not log_text_remainder
[0]:
47 log_text_remainder
= log_text_remainder
[1:]
48 log_text_remainder
= string
.join(log_text_remainder
, '\n\t')
49 if log_text_remainder
:
50 log_text_remainder
= '\n\t' + log_text_remainder
52 diff
= commit
.diff(commit
.parents
[0])
55 p
= f
.a_blob
.path
or f
.b_blob
.path
56 p2
= re
.sub('^' + path
+ '/', '', p
)
60 fp
= Popen(["fmt", "-72"], shell
= True, stdin
= PIPE
, stdout
= PIPE
)
61 fp
.stdin
.write("\t* %s: %s" % (string
.join(files
, ",\n\t"), log_text
))
63 log_text
= fp
.stdout
.read()
66 print "%s %s <%s>\n\n%s%s" % \
67 (time
.strftime("%Y-%m-%d", time
.gmtime(date
)),
68 author
.name
, author
.email
, log_text
, log_text_remainder
)
70 # git-changelog ends here