2 # Copyright 2008 Marcus D. Hanwell <marcus@cryos.org>
3 # Adapted for Claws Mail - Copyright 2013 Colin Leroy <colin@colino.net>
4 # Distributed under the terms of the GNU General Public License v2 or later
6 import string
, re
, os
, sys
11 if len(sys
.argv
) == 3:
15 curRevCmd
= os
.popen("git describe")
16 curRev
= curRevCmd
.read()
17 curRev
= curRev
[0:len(curRev
)-1]
19 if len(sys
.argv
) == 2:
22 prevVer
= re
.split('-', curRev
, 1)[0]
24 # Execute git log with the desired command line options.
25 fin
= os
.popen('git log ' + prevVer
+ '..' + curRev
+' --summary --stat --no-merges --date=short', 'r')
26 # Create a ChangeLog file in the current directory.
29 # Set up the loop variables in order to locate the blocks we want
40 # The main part of the loop
42 # The commit line marks the start of a new commit object.
43 if re
.match('^commit', line
):
44 # Start all over again...
52 commitCmd
= os
.popen("git describe "+re
.split(' ', line
, 1)[1])
53 commit
= commitCmd
.read()
55 commit
= commit
[0:len(commit
)-1]
57 # Match the author line and extract the part we want
58 elif re
.match('^Author:', line
):
59 authorList
= re
.split(': ', line
, 1)
60 author
= re
.split('<', authorList
[1], 1)[0]
61 author
= "[" + author
[0:len(author
)-1]+"]"
65 elif re
.match('^Date:', line
):
66 dateList
= re
.split(': ', line
, 1)
68 date
= date
[0:len(date
)-1]
71 # The svn-id lines are ignored
72 elif re
.match(' git-svn-id:', line
):
74 # The sign off line is ignored too
75 elif re
.search('Signed-off-by', line
) != None:
77 # Extract the actual commit message for this commit
78 elif authorFound
& dateFound
& messageFound
== False:
79 # Find the commit message if we can
89 message
= message
+ line
.strip()
91 message
= message
+ " " + line
.strip()
92 # If this line is hit all of the files have been stored for this commit
93 elif re
.search('file(s)? changed', line
) != None:
96 # Collect the files for this commit. FIXME: Still need to add +/- to files
97 elif authorFound
& dateFound
& messageFound
:
98 fileList
= re
.split(' \| ', line
, 2)
101 files
= files
+ "\n\t* " + fileList
[0].strip()
103 files
= "\t* " + fileList
[0].strip()
104 # All of the parts of the commit have been found - write out the entry
105 if authorFound
& dateFound
& messageFound
& filesFound
:
106 # First the author line, only outputted if it is the first for that
108 authorLine
= date
+ " " + author
109 if len(prevAuthorLine
) != 0:
111 fout
.write(authorLine
+ " " + commit
+ "\n\n")
113 # Assemble the actual commit message line(s) and limit the line length
118 while i
< len(commitLine
):
119 if len(commitLine
) < i
+ 70:
120 commit
= commit
+ "\n\t\t" + commitLine
[i
:len(commitLine
)]
122 index
= commitLine
.rfind(' ', i
, i
+70)
124 commit
= commit
+ "\n\t\t" + commitLine
[i
:index
]
127 commit
= commit
+ "\n\t\t" + commitLine
[i
:70]
130 # Write out the commit line
131 fout
.write(files
+ "\t\t" + commit
+ "\n")
133 #Now reset all the variables ready for a new commit block.
141 prevAuthorLine
= authorLine
143 # Close the input and output lines now that we are finished.