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])
62 p2
= re
.sub('^' + path
+ '/', '', p
)
66 fp
= Popen(["fmt", "-72"], shell
= True, stdin
= PIPE
, stdout
= PIPE
)
68 fp
.stdin
.write("\t* %s: %s" % (string
.join(files
, ",\n\t"), log_text
))
70 fp
.stdin
.write("\t* %s" % log_text
)
72 log_text
= fp
.stdout
.read()
75 print "%s %s <%s>\n" % \
76 (time
.strftime("%Y-%m-%d", time
.gmtime(date
)),
77 author
.name
, author
.email
)
80 log_text
= re
.sub(' ' + path
+ '/', ' ', log_text
)
81 log_text_remainder
= re
.sub(' ' + path
+ '/', ' ', log_text_remainder
)
83 # If the log_text_remainder already begins with a *, then use that as the
85 if re
.match('\s+\* ', log_text_remainder
):
86 if log_text_remainder
[0] == '\n':
87 print log_text_remainder
[1:]
89 print log_text_remainder
91 print "%s%s" % (log_text
, log_text_remainder
)
93 # git-changelog ends here