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) >= 0:
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) >=0:
59 authorList = re.split(': ', line, 1)
60 author = re.split('<', authorList[1], 1)[0]
61 author = "[" + author[0:len(author)-1]+"]"
64 elif re.match('^Date:', line) >= 0:
65 dateList = re.split(': ', line, 1)
67 date = date[0:len(date)-1]
69 # The svn-id lines are ignored
70 elif re.match(' git-svn-id:', line) >= 0:
72 # The sign off line is ignored too
73 elif re.search('Signed-off-by', line) >= 0:
75 # Extract the actual commit message for this commit
76 elif authorFound & dateFound & messageFound == False:
77 # Find the commit message if we can
87 message = message + line.strip()
89 message = message + " " + line.strip()
90 # If this line is hit all of the files have been stored for this commit
91 elif re.search('files changed', line) >= 0:
94 # Collect the files for this commit. FIXME: Still need to add +/- to files
95 elif authorFound & dateFound & messageFound:
96 fileList = re.split(' \| ', line, 2)
99 files = files + "\n\t* " + fileList[0].strip()
101 files = "\t* " + fileList[0].strip()
102 # All of the parts of the commit have been found - write out the entry
103 if authorFound & dateFound & messageFound & filesFound:
104 # First the author line, only outputted if it is the first for that
106 authorLine = date + " " + author
107 if len(prevAuthorLine) != 0:
109 fout.write(authorLine + " " + commit + "\n\n")
111 # Assemble the actual commit message line(s) and limit the line length
116 while i < len(commitLine):
117 if len(commitLine) < i + 70:
118 commit = commit + "\n\t\t" + commitLine[i:len(commitLine)]
120 index = commitLine.rfind(' ', i, i+70)
122 commit = commit + "\n\t\t" + commitLine[i:index]
125 commit = commit + "\n\t\t" + commitLine[i:70]
128 # Write out the commit line
129 fout.write(files + "\t\t" + commit + "\n")
131 #Now reset all the variables ready for a new commit block.
139 prevAuthorLine = authorLine
141 # Close the input and output lines now that we are finished.