2 # Copyright 2008 Marcus D. Hanwell <marcus@cryos.org>
3 # Distributed under the terms of the GNU General Public License v2 or later
7 # Execute git log with the desired command line options.
8 fin = os.popen('git log --summary --stat --no-merges --date=short', 'r')
9 # Create a ChangeLog file in the current directory.
10 fout = open('ChangeLog', 'w')
12 # Set up the loop variables in order to locate the blocks we want
22 # The main part of the loop
24 # The commit line marks the start of a new commit object.
25 if string.find(line, 'commit') >= 0:
26 # Start all over again...
35 # Match the author line and extract the part we want
36 elif re.match('Author:', line) >=0:
37 authorList = re.split(': ', line, 1)
38 author = authorList[1]
39 author = author[0:len(author)-1]
42 elif re.match('Date:', line) >= 0:
43 dateList = re.split(': ', line, 1)
45 date = date[0:len(date)-1]
47 # The svn-id lines are ignored
48 elif re.match(' git-svn-id:', line) >= 0:
50 # The sign off line is ignored too
51 elif re.search('Signed-off-by', line) >= 0:
53 # Extract the actual commit message for this commit
54 elif authorFound & dateFound & messageFound == False:
55 # Find the commit message if we can
65 message = message + line.strip()
67 message = message + " " + line.strip()
68 # If this line is hit all of the files have been stored for this commit
69 elif re.search('files changed', line) >= 0:
72 # Collect the files for this commit. FIXME: Still need to add +/- to files
73 elif authorFound & dateFound & messageFound:
74 fileList = re.split(' \| ', line, 2)
77 files = files + ", " + fileList[0].strip()
79 files = fileList[0].strip()
80 # All of the parts of the commit have been found - write out the entry
81 if authorFound & dateFound & messageFound & filesFound:
82 # First the author line, only outputted if it is the first for that
84 authorLine = date + " " + author
85 if len(prevAuthorLine) == 0:
86 fout.write(authorLine + "\n")
87 elif authorLine == prevAuthorLine:
90 fout.write("\n" + authorLine + "\n")
92 # Assemble the actual commit message line(s) and limit the line length
94 commitLine = "* " + files + ": " + message
97 while i < len(commitLine):
98 if len(commitLine) < i + 78:
99 commit = commit + "\n " + commitLine[i:len(commitLine)]
101 index = commitLine.rfind(' ', i, i+78)
103 commit = commit + "\n " + commitLine[i:index]
106 commit = commit + "\n " + commitLine[i:78]
109 # Write out the commit line
110 fout.write(commit + "\n")
112 #Now reset all the variables ready for a new commit block.
120 prevAuthorLine = authorLine
122 # Close the input and output lines now that we are finished.